Skip to content

Commit 9f34c99

Browse files
authored
System Tests: Named Kafka clusters (kroxylicious#3074)
1 parent d9d2ec4 commit 9f34c99

9 files changed

Lines changed: 34 additions & 16 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ dependency-reduced-pom.xml
4242
.idea/**/dynamic.xml
4343
.idea/**/uiDesigner.xml
4444
.idea/**/dbnavigator.xml
45+
.idea/remote-targets.xml
4546

4647
# Gradle
4748
.idea/**/gradle.xml

kroxylicious-systemtests/src/main/java/io/kroxylicious/systemtests/installation/strimzi/Strimzi.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ public Strimzi(String deploymentNamespace) {
4343
* Deploy strimzi.
4444
*/
4545
public void deploy() {
46-
LOGGER.info("Deploy Strimzi in {} namespace", deploymentNamespace);
4746
if (kubeClient().getDeployment(deploymentNamespace, Constants.STRIMZI_DEPLOYMENT_NAME) != null
4847
|| Environment.SKIP_STRIMZI_INSTALL) {
4948
LOGGER.warn("Skipping strimzi deployment. It is already deployed!");
5049
return;
5150
}
52-
51+
LOGGER.info("Deploy Strimzi in {} namespace", deploymentNamespace);
5352
ResourceManager.helmClient().namespace(deploymentNamespace).installByContainerImage(STRIMZI_HELM_REPOSITORY, STRIMZI_SERVICE_NAME,
5453
Optional.of(Environment.STRIMZI_VERSION),
5554
Optional.of(Path.of(TestUtils.getResourcesURI("helm_strimzi_overrides.yaml"))),

kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/KroxyliciousST.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
class KroxyliciousST extends AbstractST {
4141
private static final Logger LOGGER = LoggerFactory.getLogger(KroxyliciousST.class);
4242
private static Kroxylicious kroxylicious;
43-
private final String clusterName = "my-cluster";
43+
private final String clusterName = "kroxylicious-st-cluster";
4444
protected static final String BROKER_NODE_NAME = "kafka";
4545
private static final String MESSAGE = "Hello-world";
4646
private KroxyliciousOperator kroxyliciousOperator;

kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/MetricsST.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*/
4646
class MetricsST extends AbstractST {
4747
private static final Logger LOGGER = LoggerFactory.getLogger(MetricsST.class);
48-
private final String clusterName = "my-cluster";
48+
private final String clusterName = "metrics-st-cluster";
4949
protected static final String BROKER_NODE_NAME = "kafka";
5050
private static final String RECORD_VALUE = "Hello-world";
5151
private MetricsCollector kroxyliciousCollector;

kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/NonJVMClientsST.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@Tag(EXTERNAL_KAFKA_CLIENTS)
4040
class NonJVMClientsST extends AbstractST {
4141
private static final Logger LOGGER = LoggerFactory.getLogger(NonJVMClientsST.class);
42-
private final String clusterName = "my-cluster";
42+
private final String clusterName = "non-jvm-clients-cluster";
4343
protected static final String BROKER_NODE_NAME = "kafka";
4444
private static final String MESSAGE = "Hello-world";
4545
private String bootstrap;

kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/OperatorChangeDetectionST.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@
7171
class OperatorChangeDetectionST extends AbstractST {
7272

7373
private static final Logger LOGGER = LoggerFactory.getLogger(OperatorChangeDetectionST.class);
74+
private static final String PREFIX = "optr-cd";
7475
private static Kroxylicious kroxylicious;
7576
private static CertManager certManager;
76-
private final String kafkaClusterName = "my-cluster";
77+
private final String kafkaClusterName = PREFIX + "-cluster";
7778
private KroxyliciousOperator kroxyliciousOperator;
7879

7980
@Test
@@ -133,7 +134,7 @@ void shouldUpdateDeploymentWhenVirtualKafkaClusterChanges(String namespace) {
133134
void shouldUpdateDeploymentWhenDownstreamTlsCertUpdated(String namespace) {
134135
// Given
135136
var issuer = certManager.issuer(namespace);
136-
var cert = certManager.certFor(namespace, "my-cluster-cluster-ip." + namespace + ".svc.cluster.local");
137+
var cert = certManager.certFor(namespace, PREFIX + "-cluster-ip." + namespace + ".svc.cluster.local");
137138

138139
resourceManager.createOrUpdateResourceWithWait(issuer, cert);
139140

@@ -159,7 +160,7 @@ void shouldUpdateDeploymentWhenDownstreamTlsCertUpdated(String namespace) {
159160
void shouldUpdateDeploymentWhenDownstreamTrustUpdated(String namespace) {
160161
// Given
161162
var issuer = certManager.issuer(namespace);
162-
var cert = certManager.certFor(namespace, "my-cluster-cluster-ip." + namespace + ".svc.cluster.local");
163+
var cert = certManager.certFor(namespace, PREFIX + "-cluster-ip." + namespace + ".svc.cluster.local");
163164

164165
resourceManager.createOrUpdateResourceWithWait(issuer, cert);
165166

kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/extensions/KroxyliciousExtension.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package io.kroxylicious.systemtests.extensions;
88

99
import java.lang.reflect.Parameter;
10+
import java.util.Locale;
1011
import java.util.Optional;
1112
import java.util.UUID;
1213

@@ -23,19 +24,21 @@
2324

2425
import io.skodjob.testframe.resources.KubeResourceManager;
2526

26-
import io.kroxylicious.systemtests.Constants;
2727
import io.kroxylicious.systemtests.Environment;
2828
import io.kroxylicious.systemtests.logs.TestLogCollector;
2929
import io.kroxylicious.systemtests.resources.manager.ResourceManager;
3030
import io.kroxylicious.systemtests.utils.NamespaceUtils;
3131

32+
import edu.umd.cs.findbugs.annotations.NonNull;
33+
3234
/**
3335
* The type Kroxylicious extension.
3436
*/
3537
public class KroxyliciousExtension implements ParameterResolver, BeforeAllCallback, BeforeEachCallback, AfterEachCallback, AfterAllCallback {
3638
private static final Logger LOGGER = LoggerFactory.getLogger(KroxyliciousExtension.class);
3739
private static final String K8S_NAMESPACE_KEY = "namespace";
3840
private static final String EXTENSION_STORE_NAME = "io.kroxylicious.systemtests";
41+
private static final int MAX_NAMESPACE_PREFIX_LENGTH = 12;
3942
private final ExtensionContext.Namespace junitNamespace;
4043
private final TestLogCollector logCollector = TestLogCollector.getInstance();
4144

@@ -89,9 +92,8 @@ public void afterEach(ExtensionContext extensionContext) {
8992
String testMethodName = extensionContext.getRequiredTestMethod().getName();
9093
try {
9194
Optional<Throwable> exception = extensionContext.getExecutionException();
92-
exception.filter(t -> !t.getClass().getSimpleName().equals("AssumptionViolatedException")).ifPresent(e -> {
93-
logCollector.collectLogs(testClassName, testMethodName);
94-
});
95+
exception.filter(t -> !t.getClass().getSimpleName().equals("AssumptionViolatedException"))
96+
.ifPresent(e -> logCollector.collectLogs(testClassName, testMethodName));
9597
}
9698
finally {
9799
if (Environment.SYNC_RESOURCES_DELETION) {
@@ -106,11 +108,24 @@ public void afterEach(ExtensionContext extensionContext) {
106108
@Override
107109
public void beforeEach(ExtensionContext extensionContext) {
108110
ResourceManager.setTestContext(extensionContext);
109-
final String k8sNamespace = Constants.KAFKA_DEFAULT_NAMESPACE + "-" + UUID.randomUUID().toString().replace("-", "").substring(0, 6);
111+
final String k8sNamespace = generateNamespaceName(extensionContext);
110112
extensionContext.getStore(junitNamespace).put(K8S_NAMESPACE_KEY, k8sNamespace);
111113
NamespaceUtils.createNamespaceAndPrepare(k8sNamespace);
112114
}
113115

116+
@NonNull
117+
private static String generateNamespaceName(ExtensionContext extensionContext) {
118+
String namespacePrefix = getPrefix(extensionContext);
119+
return namespacePrefix + "-" + UUID.randomUUID().toString().replace("-", "").substring(0, 6);
120+
}
121+
122+
@NonNull
123+
private static String getPrefix(ExtensionContext extensionContext) {
124+
String simpleName = extensionContext.getRequiredTestClass().getSimpleName().replace("ST", "");
125+
String limitedTestName = simpleName.substring(0, Math.min(simpleName.length(), MAX_NAMESPACE_PREFIX_LENGTH));
126+
return String.join("-", limitedTestName.split("(?=\\p{Upper})")).toLowerCase(Locale.ROOT) + "-st";
127+
}
128+
114129
private String extractK8sNamespace(ExtensionContext extensionContext) {
115130
return extensionContext.getStore(junitNamespace).get(K8S_NAMESPACE_KEY, String.class);
116131
}

kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/filters/AuthorizationST.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class AuthorizationST extends AbstractST {
4747
protected static final String BROKER_NODE_NAME = "kafka";
4848
private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizationST.class);
4949
private static final String MESSAGE = "Hello-world";
50-
private final String clusterName = "my-cluster";
50+
private final String clusterName = "authorization-st-cluster";
5151
private String bootstrap;
5252
private KroxyliciousOperator kroxyliciousOperator;
5353
private static Kroxylicious kroxylicious;
@@ -86,7 +86,9 @@ void beforeEach() {
8686

8787
@AfterAll
8888
void cleanUp() {
89-
kroxyliciousOperator.delete();
89+
if (kroxyliciousOperator != null) {
90+
kroxyliciousOperator.delete();
91+
}
9092
}
9193

9294
@Test

kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/filters/RecordEncryptionST.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class RecordEncryptionST extends AbstractST {
4949
private static final Logger LOGGER = LoggerFactory.getLogger(RecordEncryptionST.class);
5050
private static final String MESSAGE = "Hello-world";
5151
private static final String KEK_PREFIX = "KEK-";
52-
private final String clusterName = "my-cluster";
52+
private final String clusterName = "record-encryption-cluster";
5353
private String bootstrap;
5454
private TestKekManager testKekManager;
5555
private KroxyliciousOperator kroxyliciousOperator;

0 commit comments

Comments
 (0)