Search in sources :

Example 6 with StrimziKafkaContainer

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

the class BrokerRestartTest method testWithBrokerRestart.

@Test
public void testWithBrokerRestart() throws Exception {
    int sendBatchSize = 10;
    try (StrimziKafkaContainer kafka = KafkaBrokerExtension.createKafkaContainer()) {
        kafka.start();
        String groupId = UUID.randomUUID().toString();
        MapBasedConfig config = createConsumerConfig(groupId).put("topic", topic);
        KafkaSource<Integer, String> source = createSource(config, groupId);
        CountDownLatch receiveLatch = new CountDownLatch(sendBatchSize * 2);
        subscribe(source.getStream(), receiveLatch);
        sendMessages(0, sendBatchSize);
        try (StrimziKafkaContainer ignored = restart(kafka, 5)) {
            sendMessages(sendBatchSize, sendBatchSize);
            waitForMessages(receiveLatch);
            checkConsumedMessages();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 7 with StrimziKafkaContainer

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

the class KafkaBrokerExtension method startKafkaBroker.

public static StrimziKafkaContainer startKafkaBroker(int port) {
    StrimziKafkaContainer kafka = createKafkaContainer().withPort(port);
    kafka.start();
    await().until(kafka::isRunning);
    return kafka;
}
Also used : StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer)

Example 8 with StrimziKafkaContainer

use of io.strimzi.test.container.StrimziKafkaContainer in project apicurio-registry by Apicurio.

the class KafkaTestContainerManager method start.

@Override
public Map<String, String> start() {
    log.info("Starting the Kafka Test Container");
    kafka = new StrimziKafkaContainer();
    kafka.addEnv("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "1");
    kafka.addEnv("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR", "1");
    kafka.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("kafka-testcontainer")));
    kafka.start();
    String bootstrapServers = kafka.getBootstrapServers();
    return Map.of("bootstrap.servers", bootstrapServers, "registry.events.kafka.config.bootstrap.servers", bootstrapServers, "registry.kafkasql.bootstrap.servers", bootstrapServers);
}
Also used : StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) Slf4jLogConsumer(org.testcontainers.containers.output.Slf4jLogConsumer)

Example 9 with StrimziKafkaContainer

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

the class BrokerRestartTest method testAcknowledgementUsingThrottledStrategyEvenAfterBrokerRestart.

@Test
public void testAcknowledgementUsingThrottledStrategyEvenAfterBrokerRestart() throws Exception {
    try (StrimziKafkaContainer kafka = KafkaBrokerExtension.createKafkaContainer()) {
        kafka.start();
        await().until(kafka::isRunning);
        String groupId = UUID.randomUUID().toString();
        MapBasedConfig config = createConsumerConfig(groupId).with("topic", topic).with("auto.commit.interval.ms", 10);
        Multi<IncomingKafkaRecord<Integer, String>> stream = createSource(config, groupId).getStream().invoke(IncomingKafkaRecord::ack);
        CountDownLatch latch = new CountDownLatch(100);
        subscribe(stream, latch);
        try (final StrimziKafkaContainer ignored = restart(kafka, 3)) {
            sendMessages(0, 100);
            waitForMessages(latch);
            checkConsumedMessages(0, 100);
            waitForCommits(source, 100);
        }
    }
}
Also used : StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) IncomingKafkaRecord(io.smallrye.reactive.messaging.kafka.IncomingKafkaRecord) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 10 with StrimziKafkaContainer

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

the class BrokerRestartTest method testResumingPausingWhileBrokerIsDown.

@Test
public void testResumingPausingWhileBrokerIsDown() throws Exception {
    try (StrimziKafkaContainer kafka = KafkaBrokerExtension.createKafkaContainer()) {
        kafka.start();
        await().until(kafka::isRunning);
        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);
        source.getStream().subscribe().withSubscriber(AssertSubscriber.create(1));
        waitForPartitionAssignment();
        ReactiveKafkaConsumer<Integer, String> consumer = source.getConsumer();
        await().until(() -> !consumer.getAssignments().await().indefinitely().isEmpty());
        assertThat(consumer.pause().await().indefinitely()).isNotEmpty();
        consumer.resume().await().indefinitely();
        assertThat(consumer.paused().await().indefinitely()).isEmpty();
        kafka.stop();
        await().until(() -> !kafka.isRunning());
        assertThat(consumer.pause().await().indefinitely()).isNotEmpty();
        consumer.resume().await().indefinitely();
        assertThat(consumer.paused().await().indefinitely()).isEmpty();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StrimziKafkaContainer(io.strimzi.test.container.StrimziKafkaContainer) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) 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