Search in sources :

Example 1 with StrimziKafkaContainer

use of io.strimzi.test.container.StrimziKafkaContainer in project strimzi by strimzi.

the class AbstractAdminApiOperatorIT method beforeAll.

@BeforeAll
public static void beforeAll() {
    vertx = Vertx.vertx();
    Map<String, String> additionalConfiguration = Map.of("authorizer.class.name", "kafka.security.authorizer.AclAuthorizer", "super.users", "User:ANONYMOUS");
    kafkaContainer = new StrimziKafkaContainer().withBrokerId(1).withKafkaConfigurationMap(additionalConfiguration);
    kafkaContainer.start();
    Properties p = new Properties();
    p.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaContainer.getBootstrapServers());
    adminClient = Admin.create(p);
}
Also used : StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) Properties(java.util.Properties) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with StrimziKafkaContainer

use of io.strimzi.test.container.StrimziKafkaContainer in project strimzi-kafka-operator by strimzi.

the class AbstractAdminApiOperatorIT method beforeAll.

@BeforeAll
public static void beforeAll() {
    vertx = Vertx.vertx();
    Map<String, String> additionalConfiguration = Map.of("authorizer.class.name", "kafka.security.authorizer.AclAuthorizer", "super.users", "User:ANONYMOUS");
    kafkaContainer = new StrimziKafkaContainer().withBrokerId(1).withKafkaConfigurationMap(additionalConfiguration);
    kafkaContainer.start();
    Properties p = new Properties();
    p.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaContainer.getBootstrapServers());
    adminClient = Admin.create(p);
}
Also used : StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) Properties(java.util.Properties) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with StrimziKafkaContainer

use of io.strimzi.test.container.StrimziKafkaContainer in project smallrye-reactive-messaging by smallrye.

the class KafkaSourceTest method testRetry.

@SuppressWarnings({ "rawtypes" })
@Test
@Tag(TestTags.SLOW)
public void testRetry() {
    // This test need an individual Kafka container
    try (StrimziKafkaContainer kafka = KafkaBrokerExtension.createKafkaContainer()) {
        kafka.start();
        await().until(kafka::isRunning);
        MapBasedConfig config = newCommonConfigForSource().with("bootstrap.servers", kafka.getBootstrapServers()).with("value.deserializer", IntegerDeserializer.class.getName()).with("retry", true).with("retry-attempts", 100).with("retry-max-wait", 30);
        KafkaCompanion kafkaCompanion = new KafkaCompanion(kafka.getBootstrapServers());
        KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
        source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
        List<KafkaRecord> messages1 = new ArrayList<>();
        source.getStream().subscribe().with(messages1::add);
        AtomicInteger counter = new AtomicInteger();
        kafkaCompanion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
        await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
        try (@SuppressWarnings("unused") StrimziKafkaContainer container = KafkaBrokerExtension.restart(kafka, 2)) {
            kafkaCompanion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
            await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 20);
            assertThat(messages1.size()).isGreaterThanOrEqualTo(20);
        }
    }
}
Also used : StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) KafkaCompanion(io.smallrye.reactive.messaging.kafka.companion.KafkaCompanion) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 4 with StrimziKafkaContainer

use of io.strimzi.test.container.StrimziKafkaContainer in project smallrye-reactive-messaging by smallrye.

the class KafkaSourceWithLegacyMetadataTest method testRetry.

@SuppressWarnings({ "rawtypes" })
@Test
@Tag(TestTags.SLOW)
public void testRetry() {
    // This test need an individual Kafka container
    try (StrimziKafkaContainer kafka = KafkaBrokerExtension.createKafkaContainer()) {
        kafka.start();
        await().until(kafka::isRunning);
        MapBasedConfig config = newCommonConfigForSource().with("bootstrap.servers", kafka.getBootstrapServers()).with("value.deserializer", IntegerDeserializer.class.getName()).with("retry", true).with("retry-attempts", 100).with("retry-max-wait", 30);
        KafkaCompanion kafkaCompanion = new KafkaCompanion(kafka.getBootstrapServers());
        KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
        source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
        List<KafkaRecord> messages1 = new ArrayList<>();
        source.getStream().subscribe().with(messages1::add);
        kafkaCompanion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
        await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
        try (@SuppressWarnings("unused") StrimziKafkaContainer container = restart(kafka, 2)) {
            kafkaCompanion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, 10), 10);
            await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 20);
            assertThat(messages1.size()).isGreaterThanOrEqualTo(20);
        }
    }
}
Also used : StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) KafkaCompanion(io.smallrye.reactive.messaging.kafka.companion.KafkaCompanion) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 5 with StrimziKafkaContainer

use of io.strimzi.test.container.StrimziKafkaContainer in project smallrye-reactive-messaging by smallrye.

the class BrokerRestartTest method testPausingWhileBrokerIsDown.

@Test
public void testPausingWhileBrokerIsDown() throws Exception {
    try (StrimziKafkaContainer kafka = KafkaBrokerExtension.createKafkaContainer()) {
        kafka.start();
        await().until(kafka::isRunning);
        Integer port = kafka.getMappedPort(KAFKA_PORT);
        sendMessages(0, 10, kafka.getBootstrapServers());
        String groupId = UUID.randomUUID().toString();
        MapBasedConfig config = createConsumerConfig(groupId).with("topic", topic).with(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers()).with(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, 6000);
        createSource(config, groupId);
        Multi<IncomingKafkaRecord<Integer, String>> stream = source.getStream();
        AssertSubscriber<IncomingKafkaRecord<Integer, String>> subscriber = stream.onItem().invoke(item -> CompletableFuture.runAsync(item::ack)).subscribe().withSubscriber(AssertSubscriber.create(0));
        waitForPartitionAssignment();
        await().untilAsserted(() -> subscriber.assertSubscribed().assertHasNotReceivedAnyItem());
        subscriber.request(1);
        await().until(() -> subscriber.getItems().size() == 1);
        await().until(() -> !source.getConsumer().paused().await().indefinitely().isEmpty());
        sendMessages(0, 10, kafka.getBootstrapServers());
        kafka.stop();
        await().until(() -> !kafka.isRunning());
        await().until(() -> !source.getConsumer().paused().await().indefinitely().isEmpty());
        subscriber.request(3);
        await().until(() -> subscriber.getItems().size() == 4);
        subscriber.request(10);
        AtomicInteger last = new AtomicInteger(subscriber.getItems().size());
        // Make sure we can't poll anymore.
        await().pollDelay(Duration.ofMillis(1000)).until(() -> {
            return last.get() == last.getAndSet(subscriber.getItems().size());
        });
        try (StrimziKafkaContainer restarted = KafkaBrokerExtension.startKafkaBroker(port)) {
            await().until(restarted::isRunning);
            subscriber.request(100);
            await().until(() -> source.getConsumer().paused().await().indefinitely().isEmpty());
            sendMessages(10, 45, restarted.getBootstrapServers());
            await().until(() -> subscriber.getItems().size() == 55);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) IncomingKafkaRecord(io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord) Test(org.junit.jupiter.api.Test)

Aggregations

StrimziKafkaContainer (io.strimzi.test.container.StrimziKafkaContainer)10 MapBasedConfig (io.smallrye.reactive.messaging.test.common.config.MapBasedConfig)6 Test (org.junit.jupiter.api.Test)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IncomingKafkaRecord (io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord)2 KafkaMapBasedConfig (io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig)2 KafkaCompanion (io.smallrye.reactive.messaging.kafka.companion.KafkaCompanion)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Tag (org.junit.jupiter.api.Tag)2 Slf4jLogConsumer (org.testcontainers.containers.output.Slf4jLogConsumer)1