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);
}
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);
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
Aggregations