Search in sources :

Example 16 with BridgeClients

use of io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients in project strimzi-kafka-operator by strimzi.

the class HttpBridgeIsolatedST method testReceiveSimpleMessage.

@ParallelTest
void testReceiveSimpleMessage(ExtensionContext extensionContext) {
    final String topicName = mapWithTestTopics.get(extensionContext.getDisplayName());
    final String consumerName = "consumer-" + new Random().nextInt(Integer.MAX_VALUE);
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(httpBridgeClusterName, topicName).editMetadata().withNamespace(INFRA_NAMESPACE).endMetadata().build());
    final BridgeClients kafkaBridgeClientJob = new BridgeClientsBuilder().withConsumerName(consumerName).withBootstrapAddress(KafkaBridgeResources.serviceName(httpBridgeClusterName)).withTopicName(topicName).withMessageCount(MESSAGE_COUNT).withPort(Constants.HTTP_BRIDGE_DEFAULT_PORT).withDelayMs(1000).withPollInterval(1000).withNamespaceName(INFRA_NAMESPACE).build();
    resourceManager.createResource(extensionContext, kafkaBridgeClientJob.consumerStrimziBridge());
    // Send messages to Kafka
    InternalKafkaClient internalKafkaClient = new InternalKafkaClient.Builder().withTopicName(topicName).withNamespaceName(INFRA_NAMESPACE).withClusterName(httpBridgeClusterName).withMessageCount(MESSAGE_COUNT).withKafkaUsername(USER_NAME).withUsingPodName(kafkaClientsPodName).withListenerName(Constants.PLAIN_LISTENER_DEFAULT_NAME).build();
    assertThat(internalKafkaClient.sendMessagesPlain(), is(MESSAGE_COUNT));
    ClientUtils.waitForClientSuccess(consumerName, INFRA_NAMESPACE, MESSAGE_COUNT);
}
Also used : Random(java.util.Random) BridgeClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClientsBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) BridgeClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClientsBuilder) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) Matchers.containsString(org.hamcrest.Matchers.containsString) BridgeClients(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 17 with BridgeClients

use of io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients in project strimzi-kafka-operator by strimzi.

the class HttpBridgeScramShaST method testSendSimpleMessageTlsScramSha.

@ParallelTest
void testSendSimpleMessageTlsScramSha(ExtensionContext extensionContext) {
    final String topicName = KafkaTopicUtils.generateRandomNameOfTopic();
    final BridgeClients kafkaBridgeClientJb = new BridgeClientsBuilder(kafkaBridgeClientJob).withTopicName(topicName).build();
    // Create topic
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(httpBridgeScramShaClusterName, topicName).editMetadata().withNamespace(namespace).endMetadata().build());
    resourceManager.createResource(extensionContext, kafkaBridgeClientJb.producerStrimziBridge());
    ClientUtils.waitForClientSuccess(producerName, namespace, MESSAGE_COUNT);
    InternalKafkaClient internalKafkaClient = new InternalKafkaClient.Builder().withTopicName(topicName).withNamespaceName(namespace).withClusterName(httpBridgeScramShaClusterName).withMessageCount(MESSAGE_COUNT).withKafkaUsername(USER_NAME).withUsingPodName(kafkaClientsPodName).withSecurityProtocol(SecurityProtocol.SASL_SSL).withListenerName(Constants.TLS_LISTENER_DEFAULT_NAME).build();
    assertThat(internalKafkaClient.receiveMessagesTls(), is(MESSAGE_COUNT));
}
Also used : BridgeClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClientsBuilder) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) BridgeClients(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 18 with BridgeClients

use of io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients in project strimzi-kafka-operator by strimzi.

the class HttpBridgeScramShaST method testReceiveSimpleMessageTlsScramSha.

@ParallelTest
void testReceiveSimpleMessageTlsScramSha(ExtensionContext extensionContext) {
    final String topicName = KafkaTopicUtils.generateRandomNameOfTopic();
    final BridgeClients kafkaBridgeClientJb = new BridgeClientsBuilder(kafkaBridgeClientJob).withTopicName(topicName).build();
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(httpBridgeScramShaClusterName, TOPIC_NAME).editMetadata().withNamespace(namespace).endMetadata().build());
    resourceManager.createResource(extensionContext, kafkaBridgeClientJb.consumerStrimziBridge());
    // Send messages to Kafka
    InternalKafkaClient internalKafkaClient = new InternalKafkaClient.Builder().withTopicName(topicName).withNamespaceName(namespace).withClusterName(httpBridgeScramShaClusterName).withMessageCount(MESSAGE_COUNT).withKafkaUsername(USER_NAME).withUsingPodName(kafkaClientsPodName).withSecurityProtocol(SecurityProtocol.SASL_SSL).withListenerName(Constants.TLS_LISTENER_DEFAULT_NAME).build();
    assertThat(internalKafkaClient.sendMessagesTls(), is(MESSAGE_COUNT));
    ClientUtils.waitForClientSuccess(consumerName, namespace, MESSAGE_COUNT);
}
Also used : BridgeClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClientsBuilder) InternalKafkaClient(io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient) BridgeClients(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 19 with BridgeClients

use of io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients in project strimzi-kafka-operator by strimzi.

the class MetricsIsolatedST method testKafkaBridgeMetrics.

@ParallelTest
@Tag(BRIDGE)
@Tag(ACCEPTANCE)
void testKafkaBridgeMetrics(ExtensionContext extensionContext) {
    String producerName = "bridge-producer";
    String consumerName = "bridge-consumer";
    MetricsCollector bridgeCollector = collector.toBuilder().withComponentName(BRIDGE_CLUSTER).withComponentType(ComponentType.KafkaBridge).build();
    // Attach consumer before producer
    BridgeClients kafkaBridgeClientJob = new BridgeClientsBuilder().withNamespaceName(INFRA_NAMESPACE).withProducerName(producerName).withConsumerName(consumerName).withBootstrapAddress(KafkaBridgeResources.serviceName(BRIDGE_CLUSTER)).withTopicName(bridgeTopic).withMessageCount(MESSAGE_COUNT).withPort(Constants.HTTP_BRIDGE_DEFAULT_PORT).withDelayMs(200).withPollInterval(200).build();
    resourceManager.createResource(extensionContext, kafkaBridgeClientJob.producerStrimziBridge());
    resourceManager.createResource(extensionContext, kafkaBridgeClientJob.consumerStrimziBridge());
    TestUtils.waitFor("KafkaProducer metrics will be available", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> {
        LOGGER.info("Looking for 'strimzi_bridge_kafka_producer_count' in bridge metrics");
        kafkaBridgeMetricsData = bridgeCollector.collectMetricsFromPods();
        Pattern producerCountPattern = Pattern.compile("strimzi_bridge_kafka_producer_count\\{.*,} ([\\d.][^\\n]+)", Pattern.CASE_INSENSITIVE);
        ArrayList<Double> producerCountValues = MetricsCollector.collectSpecificMetric(producerCountPattern, kafkaBridgeMetricsData);
        return producerCountValues.stream().mapToDouble(i -> i).count() == (double) 1;
    });
    TestUtils.waitFor("KafkaConsumer metrics will be available", Constants.GLOBAL_POLL_INTERVAL, Constants.GLOBAL_TIMEOUT, () -> {
        LOGGER.info("Looking for 'strimzi_bridge_kafka_consumer_connection_count' in bridge metrics");
        kafkaBridgeMetricsData = bridgeCollector.collectMetricsFromPods();
        Pattern consumerConnectionsPattern = Pattern.compile("strimzi_bridge_kafka_consumer_connection_count\\{.*,} ([\\d.][^\\n]+)", Pattern.CASE_INSENSITIVE);
        ArrayList<Double> consumerConnectionsValues = MetricsCollector.collectSpecificMetric(consumerConnectionsPattern, kafkaBridgeMetricsData);
        return consumerConnectionsValues.stream().mapToDouble(i -> i).count() > 0;
    });
    assertThat("Collected KafkaBridge metrics doesn't contains jvm metrics", kafkaBridgeMetricsData.values().toString().contains("jvm"));
    assertThat("Collected KafkaBridge metrics doesn't contains HTTP metrics", kafkaBridgeMetricsData.values().toString().contains("strimzi_bridge_http_server"));
    Pattern bridgeResponse = Pattern.compile("system_cpu_count ([\\d.][^\\n]+)", Pattern.CASE_INSENSITIVE);
    ArrayList<Double> values = MetricsCollector.collectSpecificMetric(bridgeResponse, kafkaBridgeMetricsData);
    assertThat(values.stream().mapToDouble(i -> i).sum(), is((double) 1));
}
Also used : Pattern(java.util.regex.Pattern) BridgeClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClientsBuilder) Matchers.emptyString(org.hamcrest.Matchers.emptyString) BridgeClients(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients) OptionalDouble(java.util.OptionalDouble) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest) Tag(org.junit.jupiter.api.Tag)

Example 20 with BridgeClients

use of io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients in project strimzi-kafka-operator by strimzi.

the class OauthTlsIsolatedST method testProducerConsumerBridge.

@Description("As a oauth bridge, i am able to send messages to bridge endpoint using encrypted communication")
@ParallelTest
@Tag(BRIDGE)
void testProducerConsumerBridge(ExtensionContext extensionContext) {
    String kafkaClientsName = mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    String clusterName = mapWithClusterNames.get(extensionContext.getDisplayName());
    String producerName = OAUTH_PRODUCER_NAME + "-" + clusterName;
    String consumerName = OAUTH_CONSUMER_NAME + "-" + clusterName;
    String topicName = mapWithTestTopics.get(extensionContext.getDisplayName());
    resourceManager.createResource(extensionContext, KafkaTopicTemplates.topic(oauthClusterName, topicName, INFRA_NAMESPACE).build());
    KafkaOauthClients oauthExampleClients = new KafkaOauthClientsBuilder().withNamespaceName(INFRA_NAMESPACE).withProducerName(producerName).withConsumerName(consumerName).withBootstrapAddress(KafkaResources.tlsBootstrapAddress(oauthClusterName)).withTopicName(topicName).withMessageCount(MESSAGE_COUNT).withOauthClientId(OAUTH_CLIENT_NAME).withOauthClientSecret(OAUTH_CLIENT_SECRET).withOauthTokenEndpointUri(keycloakInstance.getOauthTokenEndpointUri()).build();
    resourceManager.createResource(extensionContext, oauthExampleClients.producerStrimziOauthTls(oauthClusterName));
    ClientUtils.waitForClientSuccess(producerName, INFRA_NAMESPACE, MESSAGE_COUNT);
    JobUtils.deleteJobWithWait(INFRA_NAMESPACE, producerName);
    resourceManager.createResource(extensionContext, oauthExampleClients.consumerStrimziOauthTls(oauthClusterName));
    ClientUtils.waitForClientSuccess(consumerName, INFRA_NAMESPACE, MESSAGE_COUNT);
    JobUtils.deleteJobWithWait(INFRA_NAMESPACE, consumerName);
    resourceManager.createResource(extensionContext, KafkaClientsTemplates.kafkaClients(INFRA_NAMESPACE, true, kafkaClientsName).build());
    resourceManager.createResource(extensionContext, KafkaBridgeTemplates.kafkaBridge(oauthClusterName, KafkaResources.tlsBootstrapAddress(oauthClusterName), 1).editMetadata().withNamespace(INFRA_NAMESPACE).endMetadata().editSpec().withNewTls().withTrustedCertificates(new CertSecretSourceBuilder().withCertificate("ca.crt").withSecretName(KafkaResources.clusterCaCertificateSecretName(oauthClusterName)).build()).endTls().withNewKafkaClientAuthenticationOAuth().withTokenEndpointUri(keycloakInstance.getOauthTokenEndpointUri()).withClientId("kafka-bridge").withNewClientSecret().withSecretName(BRIDGE_OAUTH_SECRET).withKey(OAUTH_KEY).endClientSecret().addNewTlsTrustedCertificate().withSecretName(KeycloakInstance.KEYCLOAK_SECRET_NAME).withCertificate(KeycloakInstance.KEYCLOAK_SECRET_CERT).endTlsTrustedCertificate().withDisableTlsHostnameVerification(true).endKafkaClientAuthenticationOAuth().endSpec().build());
    producerName = "bridge-producer-" + clusterName;
    BridgeClients kafkaBridgeClientJob = new BridgeClientsBuilder().withProducerName(producerName).withBootstrapAddress(KafkaBridgeResources.serviceName(oauthClusterName)).withTopicName(topicName).withMessageCount(10).withPort(HTTP_BRIDGE_DEFAULT_PORT).withDelayMs(1000).withPollInterval(1000).withNamespaceName(INFRA_NAMESPACE).build();
    resourceManager.createResource(extensionContext, kafkaBridgeClientJob.producerStrimziBridge());
    ClientUtils.waitForClientSuccess(producerName, INFRA_NAMESPACE, MESSAGE_COUNT);
    JobUtils.deleteJobWithWait(INFRA_NAMESPACE, producerName);
}
Also used : KafkaOauthClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaOauthClientsBuilder) CertSecretSourceBuilder(io.strimzi.api.kafka.model.CertSecretSourceBuilder) BridgeClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClientsBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) BridgeClients(io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients) KafkaOauthClients(io.strimzi.systemtest.kafkaclients.internalClients.KafkaOauthClients) Description(io.vertx.core.cli.annotations.Description) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest) Tag(org.junit.jupiter.api.Tag)

Aggregations

BridgeClients (io.strimzi.systemtest.kafkaclients.internalClients.BridgeClients)22 BridgeClientsBuilder (io.strimzi.systemtest.kafkaclients.internalClients.BridgeClientsBuilder)22 ParallelTest (io.strimzi.systemtest.annotations.ParallelTest)20 InternalKafkaClient (io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient)12 Tag (org.junit.jupiter.api.Tag)10 Random (java.util.Random)6 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)4 KafkaOauthClients (io.strimzi.systemtest.kafkaclients.internalClients.KafkaOauthClients)4 KafkaOauthClientsBuilder (io.strimzi.systemtest.kafkaclients.internalClients.KafkaOauthClientsBuilder)4 Description (io.vertx.core.cli.annotations.Description)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Service (io.fabric8.kubernetes.api.model.Service)2 CertSecretSource (io.strimzi.api.kafka.model.CertSecretSource)2 CertSecretSourceBuilder (io.strimzi.api.kafka.model.CertSecretSourceBuilder)2 KafkaBridgeResources (io.strimzi.api.kafka.model.KafkaBridgeResources)2 KafkaBridgeSpec (io.strimzi.api.kafka.model.KafkaBridgeSpec)2 KafkaBridgeSpecBuilder (io.strimzi.api.kafka.model.KafkaBridgeSpecBuilder)2 KafkaResources (io.strimzi.api.kafka.model.KafkaResources)2 PasswordSecretSource (io.strimzi.api.kafka.model.PasswordSecretSource)2 KafkaListenerAuthentication (io.strimzi.api.kafka.model.listener.KafkaListenerAuthentication)2