Search in sources :

Example 1 with KafkaAdminClientsBuilder

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

the class ThrottlingQuotaST method testThrottlingQuotasCreateTopic.

/**
 * Test checks for throttling quotas set for user
 * on creation & deletion of topics and create partition operations.
 */
@ParallelTest
void testThrottlingQuotasCreateTopic(ExtensionContext extensionContext) {
    final String kafkaUsername = mapWithTestUsers.get(extensionContext.getDisplayName());
    final String createAdminName = "create-admin-" + mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String topicNamePrefix = classTopicPrefix + "-create";
    int topicsCountOverQuota = 500;
    setupKafkaUserInNamespace(extensionContext, kafkaUsername);
    KafkaAdminClients adminClientJob = new KafkaAdminClientsBuilder().withAdminName(createAdminName).withBootstrapAddress(KafkaResources.plainBootstrapAddress(CLUSTER_NAME)).withTopicName(topicNamePrefix).withTopicCount(topicsCountOverQuota).withNamespaceName(namespace).withTopicOperation(AdminClientOperations.CREATE_TOPICS.toString()).withAdditionalConfig(KafkaAdminClients.getAdminClientScramConfig(namespace, kafkaUsername, 240000)).build();
    resourceManager.createResource(extensionContext, adminClientJob.defaultAdmin());
    String createPodName = kubeClient(namespace).listPodNamesInSpecificNamespace(namespace, "job-name", createAdminName).get(0);
    PodUtils.waitUntilMessageIsInPodLogs(namespace, createPodName, "org.apache.kafka.common.errors.ThrottlingQuotaExceededException: The throttling quota has been exceeded.", GLOBAL_TIMEOUT);
    JobUtils.deleteJobWithWait(namespace, createAdminName);
    // Teardown delete created topics
    KafkaTopicUtils.deleteAllKafkaTopicsWithPrefix(namespace, topicNamePrefix);
}
Also used : KafkaAdminClients(io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClients) KafkaAdminClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClientsBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 2 with KafkaAdminClientsBuilder

use of io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClientsBuilder in project strimzi by strimzi.

the class ThrottlingQuotaST method testKafkaAdminTopicOperations.

@ParallelTest
void testKafkaAdminTopicOperations(ExtensionContext extensionContext) {
    final String kafkaUsername = mapWithTestUsers.get(extensionContext.getDisplayName());
    final String createAdminName = "create-admin-" + mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String deleteAdminName = "delete-admin-" + mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String listAdminName = "list-admin-" + mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String topicNamePrefix = classTopicPrefix + "-simple";
    int topicsCountBelowQuota = 100;
    setupKafkaUserInNamespace(extensionContext, kafkaUsername);
    // Create 'topicsCountBelowQuota' topics
    KafkaAdminClients adminClientJob = new KafkaAdminClientsBuilder().withAdminName(createAdminName).withBootstrapAddress(KafkaResources.plainBootstrapAddress(CLUSTER_NAME)).withTopicName(topicNamePrefix).withTopicCount(topicsCountBelowQuota).withNamespaceName(namespace).withTopicOperation(AdminClientOperations.CREATE_TOPICS.toString()).withAdditionalConfig(KafkaAdminClients.getAdminClientScramConfig(namespace, kafkaUsername, 240000)).build();
    resourceManager.createResource(extensionContext, adminClientJob.defaultAdmin());
    ClientUtils.waitForClientSuccess(createAdminName, namespace, topicsCountBelowQuota);
    String createPodName = kubeClient(namespace).listPodNamesInSpecificNamespace(namespace, "job-name", createAdminName).get(0);
    PodUtils.waitUntilMessageIsInPodLogs(namespace, createPodName, "All topics created");
    // List 'topicsCountBelowQuota' topics
    KafkaAdminClients adminClientListJob = new KafkaAdminClientsBuilder().withAdminName(listAdminName).withBootstrapAddress(KafkaResources.plainBootstrapAddress(CLUSTER_NAME)).withNamespaceName(namespace).withTopicOperation(AdminClientOperations.LIST_TOPICS.toString()).withAdditionalConfig(KafkaAdminClients.getAdminClientScramConfig(namespace, kafkaUsername, 600000)).build();
    resourceManager.createResource(extensionContext, adminClientListJob.defaultAdmin());
    ClientUtils.waitForClientSuccess(listAdminName, namespace, 0);
    String listPodName = kubeClient().listPodNamesInSpecificNamespace(namespace, "job-name", listAdminName).get(0);
    PodUtils.waitUntilMessageIsInPodLogs(namespace, listPodName, topicNamePrefix + "-" + (topicsCountBelowQuota - 1));
    JobUtils.deleteJobWithWait(namespace, listAdminName);
    // Delete 'topicsCountBelowQuota' topics
    adminClientJob = new KafkaAdminClientsBuilder(adminClientJob).withAdminName(deleteAdminName).withTopicOperation(AdminClientOperations.DELETE_TOPICS.toString()).build();
    resourceManager.createResource(extensionContext, adminClientJob.defaultAdmin());
    ClientUtils.waitForClientSuccess(deleteAdminName, namespace, 10);
    String deletePodName = kubeClient(namespace).listPodNamesInSpecificNamespace(namespace, "job-name", deleteAdminName).get(0);
    PodUtils.waitUntilMessageIsInPodLogs(namespace, deletePodName, "Successfully removed all " + topicsCountBelowQuota);
    // List topics after deletion
    resourceManager.createResource(extensionContext, adminClientListJob.defaultAdmin());
    ClientUtils.waitForClientSuccess(listAdminName, namespace, 0);
    listPodName = kubeClient(namespace).listPodNamesInSpecificNamespace(namespace, "job-name", listAdminName).get(0);
    String afterDeletePodLogs = kubeClient(namespace).logsInSpecificNamespace(namespace, listPodName);
    assertThat(afterDeletePodLogs.contains(topicNamePrefix), is(false));
    assertThat(afterDeletePodLogs, not(containsString(topicNamePrefix)));
    JobUtils.deleteJobWithWait(namespace, createAdminName);
    JobUtils.deleteJobWithWait(namespace, listAdminName);
    JobUtils.deleteJobWithWait(namespace, deleteAdminName);
}
Also used : KafkaAdminClients(io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClients) KafkaAdminClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClientsBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 3 with KafkaAdminClientsBuilder

use of io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClientsBuilder in project strimzi by strimzi.

the class ThrottlingQuotaST method testThrottlingQuotasCreateTopic.

/**
 * Test checks for throttling quotas set for user
 * on creation & deletion of topics and create partition operations.
 */
@ParallelTest
void testThrottlingQuotasCreateTopic(ExtensionContext extensionContext) {
    final String kafkaUsername = mapWithTestUsers.get(extensionContext.getDisplayName());
    final String createAdminName = "create-admin-" + mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String topicNamePrefix = classTopicPrefix + "-create";
    int topicsCountOverQuota = 500;
    setupKafkaUserInNamespace(extensionContext, kafkaUsername);
    KafkaAdminClients adminClientJob = new KafkaAdminClientsBuilder().withAdminName(createAdminName).withBootstrapAddress(KafkaResources.plainBootstrapAddress(CLUSTER_NAME)).withTopicName(topicNamePrefix).withTopicCount(topicsCountOverQuota).withNamespaceName(namespace).withTopicOperation(AdminClientOperations.CREATE_TOPICS.toString()).withAdditionalConfig(KafkaAdminClients.getAdminClientScramConfig(namespace, kafkaUsername, 240000)).build();
    resourceManager.createResource(extensionContext, adminClientJob.defaultAdmin());
    String createPodName = kubeClient(namespace).listPodNamesInSpecificNamespace(namespace, "job-name", createAdminName).get(0);
    PodUtils.waitUntilMessageIsInPodLogs(namespace, createPodName, "org.apache.kafka.common.errors.ThrottlingQuotaExceededException: The throttling quota has been exceeded.", GLOBAL_TIMEOUT);
    JobUtils.deleteJobWithWait(namespace, createAdminName);
    // Teardown delete created topics
    KafkaTopicUtils.deleteAllKafkaTopicsWithPrefix(namespace, topicNamePrefix);
}
Also used : KafkaAdminClients(io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClients) KafkaAdminClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClientsBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 4 with KafkaAdminClientsBuilder

use of io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClientsBuilder in project strimzi by strimzi.

the class ThrottlingQuotaST method testThrottlingQuotasDeleteTopic.

@ParallelTest
void testThrottlingQuotasDeleteTopic(ExtensionContext extensionContext) {
    final String kafkaUsername = mapWithTestUsers.get(extensionContext.getDisplayName());
    final String createAdminName = "create-admin-" + mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String deleteAdminName = "delete-admin-" + mapWithKafkaClientNames.get(extensionContext.getDisplayName());
    final String topicNamePrefix = classTopicPrefix + "-delete";
    int topicsCountOverQuota = 500;
    setupKafkaUserInNamespace(extensionContext, kafkaUsername);
    // Create many topics in multiple rounds using starting offset
    KafkaAdminClients createAdminClientJob = new KafkaAdminClientsBuilder().withAdminName(createAdminName).withBootstrapAddress(KafkaResources.plainBootstrapAddress(CLUSTER_NAME)).withTopicName(topicNamePrefix).withTopicCount(100).withNamespaceName(namespace).withTopicOperation(AdminClientOperations.CREATE_TOPICS.toString()).withAdditionalConfig(KafkaAdminClients.getAdminClientScramConfig(namespace, kafkaUsername, 240000)).build();
    String createPodName;
    int offset = 100;
    int iterations = topicsCountOverQuota / 100;
    for (int i = 0; i < iterations; i++) {
        LOGGER.info("Executing {}/{} iteration.", i + 1, iterations);
        createAdminClientJob = new KafkaAdminClientsBuilder(createAdminClientJob).withTopicOffset(i * offset).build();
        resourceManager.createResource(extensionContext, createAdminClientJob.defaultAdmin());
        ClientUtils.waitForClientSuccess(createAdminName, namespace, 100);
        createPodName = kubeClient(namespace).listPodNamesInSpecificNamespace(namespace, "job-name", createAdminName).get(0);
        PodUtils.waitUntilMessageIsInPodLogs(namespace, createPodName, "All topics created", Constants.GLOBAL_TIMEOUT);
        JobUtils.deleteJobWithWait(namespace, createAdminName);
    }
    // Test delete all topics at once - should fail on Throttling Quota limit
    KafkaAdminClients deleteAdminClientJob = new KafkaAdminClientsBuilder().withAdminName(deleteAdminName).withBootstrapAddress(KafkaResources.plainBootstrapAddress(CLUSTER_NAME)).withTopicName(topicNamePrefix).withTopicCount(topicsCountOverQuota).withNamespaceName(namespace).withTopicOperation(AdminClientOperations.DELETE_TOPICS.toString()).withAdditionalConfig(KafkaAdminClients.getAdminClientScramConfig(namespace, kafkaUsername, 240000)).build();
    resourceManager.createResource(extensionContext, deleteAdminClientJob.defaultAdmin());
    String deletePodName = kubeClient(namespace).listPodNamesInSpecificNamespace(namespace, "job-name", deleteAdminName).get(0);
    PodUtils.waitUntilMessageIsInPodLogs(namespace, deletePodName, "org.apache.kafka.common.errors.ThrottlingQuotaExceededException: The throttling quota has been exceeded.", Constants.GLOBAL_TIMEOUT);
    JobUtils.deleteJobWithWait(namespace, deleteAdminName);
    // Teardown - delete all (remaining) topics (within Quota limits) in multiple rounds using starting offsets
    for (int i = 0; i < iterations; i++) {
        LOGGER.info("Executing {}/{} iteration for {}.", i + 1, iterations, deleteAdminName);
        deleteAdminClientJob = new KafkaAdminClientsBuilder(deleteAdminClientJob).withTopicOffset(i * offset).withTopicCount(100).withAdditionalConfig("").build();
        resourceManager.createResource(extensionContext, deleteAdminClientJob.defaultAdmin());
        ClientUtils.waitForClientSuccess(deleteAdminName, namespace, 10);
        JobUtils.deleteJobWithWait(namespace, deleteAdminName);
    }
}
Also used : KafkaAdminClients(io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClients) KafkaAdminClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClientsBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.systemtest.annotations.ParallelTest)

Example 5 with KafkaAdminClientsBuilder

use of io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClientsBuilder in project strimzi by strimzi.

the class ThrottlingQuotaST method setup.

@BeforeAll
void setup(ExtensionContext extensionContext) {
    sharedTestStorage = new TestStorage(extensionContext, namespace);
    // Deploy kafka with ScramSHA512
    LOGGER.info("Deploying shared Kafka across all test cases in {} namespace", sharedTestStorage.getNamespaceName());
    resourceManager.createResource(extensionContext, KafkaTemplates.kafkaEphemeral(sharedTestStorage.getClusterName(), 3).editMetadata().withNamespace(sharedTestStorage.getNamespaceName()).endMetadata().editSpec().editKafka().withListeners(new GenericKafkaListenerBuilder().withName(Constants.PLAIN_LISTENER_DEFAULT_NAME).withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).withNewKafkaListenerAuthenticationScramSha512Auth().endKafkaListenerAuthenticationScramSha512Auth().build(), new GenericKafkaListenerBuilder().withName(Constants.TLS_LISTENER_DEFAULT_NAME).withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).withNewKafkaListenerAuthenticationTlsAuth().endKafkaListenerAuthenticationTlsAuth().build()).endKafka().endSpec().build());
    resourceManager.createResource(extensionContext, KafkaUserTemplates.defaultUser(sharedTestStorage.getNamespaceName(), sharedTestStorage.getClusterName(), sharedTestStorage.getUserName()).editOrNewSpec().withNewQuotas().withControllerMutationRate(1.0).endQuotas().withAuthentication(new KafkaUserScramSha512ClientAuthentication()).endSpec().build());
    adminClientsBuilder = new KafkaAdminClientsBuilder().withBootstrapAddress(KafkaResources.plainBootstrapAddress(sharedTestStorage.getClusterName())).withNamespaceName(sharedTestStorage.getNamespaceName()).withAdditionalConfig(KafkaAdminClients.getAdminClientScramConfig(sharedTestStorage.getNamespaceName(), sharedTestStorage.getUserName(), 240000));
}
Also used : GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) KafkaAdminClientsBuilder(io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClientsBuilder) TestStorage(io.strimzi.systemtest.storage.TestStorage) KafkaUserScramSha512ClientAuthentication(io.strimzi.api.kafka.model.KafkaUserScramSha512ClientAuthentication) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

KafkaAdminClientsBuilder (io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClientsBuilder)12 ParallelTest (io.strimzi.systemtest.annotations.ParallelTest)10 KafkaAdminClients (io.strimzi.systemtest.kafkaclients.internalClients.KafkaAdminClients)10 Matchers.containsString (org.hamcrest.Matchers.containsString)8 TestStorage (io.strimzi.systemtest.storage.TestStorage)4 KafkaUserScramSha512ClientAuthentication (io.strimzi.api.kafka.model.KafkaUserScramSha512ClientAuthentication)2 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2