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] Big refactor of Test Storage usage in ST #9569

Merged
merged 5 commits into from
Feb 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

import static io.strimzi.systemtest.TestConstants.BRIDGE;
Expand All @@ -67,19 +66,14 @@ class HttpBridgeST extends AbstractST {

private final String httpBridgeClusterName = "http-bridge-cluster-name";

private String kafkaClientsPodName;

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

final BridgeClients kafkaBridgeClientJob = new BridgeClientsBuilder()
.withProducerName(producerName)
.withProducerName(testStorage.getProducerName())
.withBootstrapAddress(KafkaBridgeResources.serviceName(httpBridgeClusterName))
.withTopicName(topicName)
.withTopicName(testStorage.getTopicName())
.withMessageCount(testStorage.getMessageCount())
.withPort(TestConstants.HTTP_BRIDGE_DEFAULT_PORT)
.withDelayMs(1000)
Expand All @@ -88,23 +82,23 @@ void testSendSimpleMessage(ExtensionContext extensionContext) {
.build();

// Create topic
resourceManager.createResourceWithWait(extensionContext, KafkaTopicTemplates.topic(httpBridgeClusterName, topicName, Environment.TEST_SUITE_NAMESPACE).build());
resourceManager.createResourceWithWait(extensionContext, KafkaTopicTemplates.topic(httpBridgeClusterName, testStorage.getTopicName(), Environment.TEST_SUITE_NAMESPACE).build());

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

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

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

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

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

// Checking labels for KafkaBridge
verifyLabelsOnPods(Environment.TEST_SUITE_NAMESPACE, httpBridgeClusterName, "my-bridge", "KafkaBridge");
Expand All @@ -113,17 +107,14 @@ void testSendSimpleMessage(ExtensionContext extensionContext) {

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

resourceManager.createResourceWithWait(extensionContext, KafkaTopicTemplates.topic(httpBridgeClusterName, topicName, Environment.TEST_SUITE_NAMESPACE).build());
resourceManager.createResourceWithWait(extensionContext, KafkaTopicTemplates.topic(httpBridgeClusterName, testStorage.getTopicName(), Environment.TEST_SUITE_NAMESPACE).build());

final BridgeClients kafkaBridgeClientJob = new BridgeClientsBuilder()
.withConsumerName(consumerName)
.withConsumerName(testStorage.getConsumerName())
.withBootstrapAddress(KafkaBridgeResources.serviceName(httpBridgeClusterName))
.withTopicName(topicName)
.withTopicName(testStorage.getTopicName())
.withMessageCount(testStorage.getMessageCount())
.withPort(TestConstants.HTTP_BRIDGE_DEFAULT_PORT)
.withDelayMs(1000)
Expand All @@ -135,16 +126,16 @@ void testReceiveSimpleMessage(ExtensionContext extensionContext) {

// Send messages to Kafka
KafkaClients kafkaClients = new KafkaClientsBuilder()
.withTopicName(topicName)
.withTopicName(testStorage.getTopicName())
.withMessageCount(testStorage.getMessageCount())
.withBootstrapAddress(KafkaResources.plainBootstrapAddress(httpBridgeClusterName))
.withProducerName(producerName)
.withProducerName(testStorage.getProducerName())
.withNamespaceName(Environment.TEST_SUITE_NAMESPACE)
.build();

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

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

@ParallelTest
Expand Down Expand Up @@ -377,7 +368,7 @@ void testConfigureDeploymentStrategy(ExtensionContext extensionContext) {

@ParallelTest
void testCustomBridgeLabelsAreProperlySet(ExtensionContext extensionContext) {
final TestStorage testStorage = storageMap.get(extensionContext);
final TestStorage testStorage = new TestStorage(extensionContext);
final String bridgeName = "bridge-" + testStorage.getClusterName();

resourceManager.createResourceWithWait(extensionContext, KafkaBridgeTemplates.kafkaBridge(bridgeName, KafkaResources.plainBootstrapAddress(httpBridgeClusterName), 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HttpBridgeScramShaST extends AbstractST {

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

Expand Down Expand Up @@ -82,7 +82,7 @@ void testSendSimpleMessageTlsScramSha(ExtensionContext extensionContext) {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class HttpBridgeTlsST extends AbstractST {
@ParallelTest
void testSendSimpleMessageTls(ExtensionContext extensionContext) {

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

Expand Down Expand Up @@ -83,7 +83,7 @@ void testSendSimpleMessageTls(ExtensionContext extensionContext) {
@ParallelTest
void testReceiveSimpleMessageTls(ExtensionContext extensionContext) {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package io.strimzi.systemtest.connect;

import io.fabric8.kubernetes.api.model.LabelSelector;
import io.fabric8.openshift.api.model.ImageStream;
import io.fabric8.openshift.api.model.ImageStreamBuilder;
import io.fabric8.openshift.client.OpenShiftClient;
Expand Down Expand Up @@ -372,8 +371,7 @@ void testUpdateConnectWithAnotherPlugin(ExtensionContext extensionContext) {
.endSpec()
.build());

LabelSelector labelSelector = KafkaConnectResource.getLabelSelector(testStorage.getClusterName(), KafkaConnectResources.componentName(testStorage.getClusterName()));
Map<String, String> connectSnapshot = PodUtils.podSnapshot(testStorage.getNamespaceName(), labelSelector);
Map<String, String> connectSnapshot = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getKafkaConnectSelector());
String scraperPodName = kubeClient().listPodsByPrefixInName(testStorage.getNamespaceName(), testStorage.getScraperName()).get(0).getMetadata().getName();

LOGGER.info("Checking that KafkaConnect API contains EchoSink KafkaConnector and not Camel-Telegram Connector class name");
Expand All @@ -387,7 +385,7 @@ void testUpdateConnectWithAnotherPlugin(ExtensionContext extensionContext) {
kafkaConnect.getSpec().getBuild().getPlugins().add(secondPlugin);
}, testStorage.getNamespaceName());

RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), labelSelector, 1, connectSnapshot);
RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), testStorage.getKafkaConnectSelector(), 1, connectSnapshot);

Map<String, Object> camelHttpConfig = new HashMap<>();
camelHttpConfig.put("camel.sink.path.httpUri", "http://" + KafkaConnectResources.serviceName(testStorage.getClusterName()) + ":8083");
Expand Down Expand Up @@ -439,8 +437,7 @@ void testBuildOtherPluginTypeWithAndWithoutFileName(ExtensionContext extensionCo
.endSpec()
.build());

LabelSelector labelSelector = KafkaConnectResource.getLabelSelector(testStorage.getClusterName(), KafkaConnectResources.componentName(testStorage.getClusterName()));
Map<String, String> connectSnapshot = PodUtils.podSnapshot(testStorage.getNamespaceName(), labelSelector);
Map<String, String> connectSnapshot = PodUtils.podSnapshot(testStorage.getNamespaceName(), testStorage.getKafkaConnectSelector());
String connectPodName = kubeClient().listPods(testStorage.getNamespaceName(), testStorage.getClusterName(), Labels.STRIMZI_KIND_LABEL, KafkaConnect.RESOURCE_KIND).get(0).getMetadata().getName();

LOGGER.info("Checking that plugin has correct file name: {}", TestConstants.ECHO_SINK_FILE_NAME);
Expand All @@ -461,7 +458,7 @@ void testBuildOtherPluginTypeWithAndWithoutFileName(ExtensionContext extensionCo
connect.getSpec().getBuild().setPlugins(Collections.singletonList(pluginWithoutFileName));
}, testStorage.getNamespaceName());

RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), labelSelector, 1, connectSnapshot);
RollingUpdateUtils.waitTillComponentHasRolledAndPodsReady(testStorage.getNamespaceName(), testStorage.getKafkaConnectSelector(), 1, connectSnapshot);

LOGGER.info("Checking that plugin has different name than before");
connectPodName = kubeClient().listPods(testStorage.getNamespaceName(), testStorage.getClusterName(), Labels.STRIMZI_KIND_LABEL, KafkaConnect.RESOURCE_KIND).get(0).getMetadata().getName();
Expand Down
Loading
Loading