Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ST] Innitial cleanup of AbstractST #9525

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions systemtest/src/test/java/io/strimzi/systemtest/AbstractST.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import io.strimzi.systemtest.resources.operator.SetupClusterOperator;
import io.strimzi.systemtest.storage.TestStorage;
import io.strimzi.systemtest.utils.StUtils;
import io.strimzi.systemtest.utils.kafkaUtils.KafkaTopicUtils;
import io.strimzi.systemtest.utils.kafkaUtils.KafkaUserUtils;
import io.strimzi.systemtest.utils.kubeUtils.objects.PodUtils;
import io.strimzi.test.TestUtils;
import io.strimzi.test.interfaces.TestSeparator;
Expand All @@ -48,7 +46,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -83,7 +80,6 @@ public abstract class AbstractST implements TestSeparator {
private static final Object LOCK = new Object();

protected static ConcurrentHashMap<ExtensionContext, TestStorage> storageMap = new ConcurrentHashMap<>();
protected static final String CLUSTER_NAME_PREFIX = "my-cluster-";
protected static final String KAFKA_IMAGE_MAP = "STRIMZI_KAFKA_IMAGES";
protected static final String KAFKA_CONNECT_IMAGE_MAP = "STRIMZI_KAFKA_CONNECT_IMAGES";
protected static final String KAFKA_MIRROR_MAKER_2_IMAGE_MAP = "STRIMZI_KAFKA_MIRROR_MAKER_2_IMAGES";
Expand All @@ -92,12 +88,6 @@ public abstract class AbstractST implements TestSeparator {
protected static final String KAFKA_INIT_IMAGE = "STRIMZI_DEFAULT_KAFKA_INIT_IMAGE";
protected static final String TLS_SIDECAR_EO_IMAGE = "STRIMZI_DEFAULT_TLS_SIDECAR_ENTITY_OPERATOR_IMAGE";

public static Random rng = new Random();

public static final int MESSAGE_COUNT = TestConstants.MESSAGE_COUNT;
public static final String USER_NAME = KafkaUserUtils.generateRandomNameOfKafkaUser();
public static final String TOPIC_NAME = KafkaTopicUtils.generateRandomNameOfTopic();

protected void assertResources(String namespace, String podName, String containerName, String memoryLimit, String cpuLimit, String memoryRequest, String cpuRequest) {
Pod po = kubeClient(namespace).getPod(namespace, podName);
assertThat("Not found an expected Pod " + namespace + "/" + podName + " but found " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private void testWeirdUsername(ExtensionContext extensionContext, String weirdUs
.withConsumerName(ts.getClusterName() + "-" + consumerName)
.withBootstrapAddress(KafkaBridgeResources.serviceName(ts.getClusterName()))
.withTopicName(ts.getTopicName())
.withMessageCount(MESSAGE_COUNT)
.withMessageCount(ts.getMessageCount())
.withPort(TestConstants.HTTP_BRIDGE_DEFAULT_PORT)
.withNamespaceName(ts.getNamespaceName())
.build();
Expand Down Expand Up @@ -198,7 +198,7 @@ private void testWeirdUsername(ExtensionContext extensionContext, String weirdUs
.withBootstrapAddress(externalBootstrapServers)
.withNamespaceName(ts.getNamespaceName())
.withTopicName(ts.getTopicName())
.withMessageCount(MESSAGE_COUNT)
.withMessageCount(ts.getMessageCount())
.withUsername(weirdUserName)
// we disable ssl.endpoint.identification.algorithm for external listener (i.e., NodePort),
// because TLS hostname verification is not supported on such listener type.
Expand All @@ -213,9 +213,9 @@ private void testWeirdUsername(ExtensionContext extensionContext, String weirdUs
resourceManager.createResourceWithWait(extensionContext, externalKafkaProducer.producerScramShaTlsStrimzi(ts.getClusterName()));
}

ClientUtils.waitForClientSuccess(kafkaProducerExternalName, ts.getNamespaceName(), MESSAGE_COUNT);
ClientUtils.waitForClientSuccess(kafkaProducerExternalName, ts.getNamespaceName(), ts.getMessageCount());

ClientUtils.waitForClientSuccess(ts.getClusterName() + "-" + consumerName, ts.getNamespaceName(), MESSAGE_COUNT);
ClientUtils.waitForClientSuccess(ts.getClusterName() + "-" + consumerName, ts.getNamespaceName(), ts.getMessageCount());
}

@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void testSendSimpleMessage(ExtensionContext extensionContext) {
.withProducerName(producerName)
.withBootstrapAddress(KafkaBridgeResources.serviceName(httpBridgeClusterName))
.withTopicName(topicName)
.withMessageCount(MESSAGE_COUNT)
.withMessageCount(testStorage.getMessageCount())
.withPort(TestConstants.HTTP_BRIDGE_DEFAULT_PORT)
.withDelayMs(1000)
.withPollInterval(1000)
Expand All @@ -92,19 +92,19 @@ void testSendSimpleMessage(ExtensionContext extensionContext) {

resourceManager.createResourceWithWait(extensionContext, kafkaBridgeClientJob.producerStrimziBridge());

ClientUtils.waitForClientSuccess(producerName, Environment.TEST_SUITE_NAMESPACE, MESSAGE_COUNT);
ClientUtils.waitForClientSuccess(producerName, Environment.TEST_SUITE_NAMESPACE, testStorage.getMessageCount());

KafkaClients kafkaClients = new KafkaClientsBuilder()
.withTopicName(topicName)
.withMessageCount(MESSAGE_COUNT)
.withMessageCount(testStorage.getMessageCount())
.withBootstrapAddress(KafkaResources.plainBootstrapAddress(httpBridgeClusterName))
.withConsumerName(consumerName)
.withNamespaceName(Environment.TEST_SUITE_NAMESPACE)
.build();

resourceManager.createResourceWithWait(extensionContext, kafkaClients.consumerStrimzi());

ClientUtils.waitForClientSuccess(consumerName, Environment.TEST_SUITE_NAMESPACE, MESSAGE_COUNT);
ClientUtils.waitForClientSuccess(consumerName, Environment.TEST_SUITE_NAMESPACE, testStorage.getMessageCount());

// Checking labels for KafkaBridge
verifyLabelsOnPods(Environment.TEST_SUITE_NAMESPACE, httpBridgeClusterName, "my-bridge", "KafkaBridge");
Expand All @@ -124,7 +124,7 @@ void testReceiveSimpleMessage(ExtensionContext extensionContext) {
.withConsumerName(consumerName)
.withBootstrapAddress(KafkaBridgeResources.serviceName(httpBridgeClusterName))
.withTopicName(topicName)
.withMessageCount(MESSAGE_COUNT)
.withMessageCount(testStorage.getMessageCount())
.withPort(TestConstants.HTTP_BRIDGE_DEFAULT_PORT)
.withDelayMs(1000)
.withPollInterval(1000)
Expand All @@ -136,15 +136,15 @@ void testReceiveSimpleMessage(ExtensionContext extensionContext) {
// Send messages to Kafka
KafkaClients kafkaClients = new KafkaClientsBuilder()
.withTopicName(topicName)
.withMessageCount(MESSAGE_COUNT)
.withMessageCount(testStorage.getMessageCount())
.withBootstrapAddress(KafkaResources.plainBootstrapAddress(httpBridgeClusterName))
.withProducerName(producerName)
.withNamespaceName(Environment.TEST_SUITE_NAMESPACE)
.build();

resourceManager.createResourceWithWait(extensionContext, kafkaClients.producerStrimzi());

ClientUtils.waitForClientsSuccess(producerName, consumerName, Environment.TEST_SUITE_NAMESPACE, MESSAGE_COUNT);
ClientUtils.waitForClientsSuccess(producerName, consumerName, Environment.TEST_SUITE_NAMESPACE, testStorage.getMessageCount());
}

@ParallelTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import io.strimzi.systemtest.kafkaclients.internalClients.BridgeClientsBuilder;
import io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients;
import io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder;
import io.strimzi.systemtest.storage.TestStorage;
import io.strimzi.systemtest.templates.crd.KafkaBridgeTemplates;
import io.strimzi.systemtest.templates.crd.KafkaTemplates;
import io.strimzi.systemtest.templates.crd.KafkaTopicTemplates;
import io.strimzi.systemtest.templates.crd.KafkaUserTemplates;
import io.strimzi.systemtest.utils.ClientUtils;
import io.strimzi.systemtest.utils.kafkaUtils.KafkaTopicUtils;
import io.strimzi.systemtest.utils.kafkaUtils.KafkaUserUtils;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -45,9 +47,11 @@ class HttpBridgeScramShaST extends AbstractST {
private static final Logger LOGGER = LogManager.getLogger(HttpBridgeScramShaST.class);
private final String httpBridgeScramShaClusterName = "http-bridge-scram-sha-cluster-name";
private BridgeClients kafkaBridgeClientJob;
private final String kafkaUserName = KafkaUserUtils.generateRandomNameOfKafkaUser();

@ParallelTest
void testSendSimpleMessageTlsScramSha(ExtensionContext extensionContext) {
final TestStorage testStorage = storageMap.get(extensionContext);
final String producerName = "producer-" + new Random().nextInt(Integer.MAX_VALUE);
final String consumerName = "consumer-" + new Random().nextInt(Integer.MAX_VALUE);

Expand All @@ -61,23 +65,24 @@ void testSendSimpleMessageTlsScramSha(ExtensionContext extensionContext) {
resourceManager.createResourceWithWait(extensionContext, KafkaTopicTemplates.topic(httpBridgeScramShaClusterName, topicName, Environment.TEST_SUITE_NAMESPACE).build());

resourceManager.createResourceWithWait(extensionContext, kafkaBridgeClientJb.producerStrimziBridge());
ClientUtils.waitForClientSuccess(producerName, Environment.TEST_SUITE_NAMESPACE, MESSAGE_COUNT);
ClientUtils.waitForClientSuccess(producerName, Environment.TEST_SUITE_NAMESPACE, testStorage.getMessageCount());

KafkaClients kafkaClients = new KafkaClientsBuilder()
.withTopicName(topicName)
.withMessageCount(MESSAGE_COUNT)
.withMessageCount(testStorage.getMessageCount())
.withBootstrapAddress(KafkaResources.tlsBootstrapAddress(httpBridgeScramShaClusterName))
.withConsumerName(consumerName)
.withNamespaceName(Environment.TEST_SUITE_NAMESPACE)
.withUsername(USER_NAME)
.withUsername(kafkaUserName)
.build();

resourceManager.createResourceWithWait(extensionContext, kafkaClients.consumerScramShaTlsStrimzi(httpBridgeScramShaClusterName));
ClientUtils.waitForClientSuccess(consumerName, Environment.TEST_SUITE_NAMESPACE, MESSAGE_COUNT);
ClientUtils.waitForClientSuccess(consumerName, Environment.TEST_SUITE_NAMESPACE, testStorage.getMessageCount());
}

@ParallelTest
void testReceiveSimpleMessageTlsScramSha(ExtensionContext extensionContext) {
final TestStorage testStorage = storageMap.get(extensionContext);
final String producerName = "producer-" + new Random().nextInt(Integer.MAX_VALUE);
final String consumerName = "consumer-" + new Random().nextInt(Integer.MAX_VALUE);

Expand All @@ -87,25 +92,27 @@ void testReceiveSimpleMessageTlsScramSha(ExtensionContext extensionContext) {
.withConsumerName(consumerName)
.build();

resourceManager.createResourceWithWait(extensionContext, KafkaTopicTemplates.topic(httpBridgeScramShaClusterName, TOPIC_NAME, Environment.TEST_SUITE_NAMESPACE).build());
resourceManager.createResourceWithWait(extensionContext, KafkaTopicTemplates.topic(httpBridgeScramShaClusterName, testStorage.getTopicName(), Environment.TEST_SUITE_NAMESPACE).build());
resourceManager.createResourceWithWait(extensionContext, kafkaBridgeClientJb.consumerStrimziBridge());

// Send messages to Kafka
KafkaClients kafkaClients = new KafkaClientsBuilder()
.withTopicName(topicName)
.withMessageCount(MESSAGE_COUNT)
.withMessageCount(testStorage.getMessageCount())
.withBootstrapAddress(KafkaResources.tlsBootstrapAddress(httpBridgeScramShaClusterName))
.withProducerName(producerName)
.withNamespaceName(Environment.TEST_SUITE_NAMESPACE)
.withUsername(USER_NAME)
.withUsername(kafkaUserName)
.build();

resourceManager.createResourceWithWait(extensionContext, kafkaClients.producerScramShaTlsStrimzi(httpBridgeScramShaClusterName));
ClientUtils.waitForClientsSuccess(producerName, consumerName, Environment.TEST_SUITE_NAMESPACE, MESSAGE_COUNT);
ClientUtils.waitForClientsSuccess(producerName, consumerName, Environment.TEST_SUITE_NAMESPACE, testStorage.getMessageCount());
}

@BeforeAll
void setUp(ExtensionContext extensionContext) {
final TestStorage testStorage = new TestStorage(extensionContext);

clusterOperator = clusterOperator.defaultInstallation(extensionContext)
.createInstallation()
.runInstallation();
Expand All @@ -131,7 +138,7 @@ void setUp(ExtensionContext extensionContext) {
.endSpec().build());

// Create Kafka user
KafkaUser scramShaUser = KafkaUserTemplates.scramShaUser(Environment.TEST_SUITE_NAMESPACE, httpBridgeScramShaClusterName, USER_NAME)
KafkaUser scramShaUser = KafkaUserTemplates.scramShaUser(Environment.TEST_SUITE_NAMESPACE, httpBridgeScramShaClusterName, kafkaUserName)
.editMetadata()
.withNamespace(Environment.TEST_SUITE_NAMESPACE)
.endMetadata()
Expand All @@ -141,7 +148,7 @@ void setUp(ExtensionContext extensionContext) {

// Initialize PasswordSecret to set this as PasswordSecret in MirrorMaker spec
PasswordSecretSource passwordSecret = new PasswordSecretSource();
passwordSecret.setSecretName(USER_NAME);
passwordSecret.setSecretName(kafkaUserName);
passwordSecret.setPassword("password");

// Initialize CertSecretSource with certificate and Secret names for consumer
Expand All @@ -160,7 +167,7 @@ void setUp(ExtensionContext extensionContext) {
.addToConfig(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest")
.endConsumer()
.withNewKafkaClientAuthenticationScramSha512()
.withUsername(USER_NAME)
.withUsername(kafkaUserName)
.withPasswordSecret(passwordSecret)
.endKafkaClientAuthenticationScramSha512()
.withNewTls()
Expand All @@ -170,8 +177,8 @@ void setUp(ExtensionContext extensionContext) {

kafkaBridgeClientJob = new BridgeClientsBuilder()
.withBootstrapAddress(KafkaBridgeResources.serviceName(httpBridgeScramShaClusterName))
.withTopicName(TOPIC_NAME)
.withMessageCount(MESSAGE_COUNT)
.withTopicName(testStorage.getTopicName())
.withMessageCount(testStorage.getMessageCount())
.withPort(TestConstants.HTTP_BRIDGE_DEFAULT_PORT)
.withNamespaceName(Environment.TEST_SUITE_NAMESPACE)
.build();
Expand Down
Loading
Loading