use of io.smallrye.reactive.messaging.kafka.impl.KafkaSource in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceTest method testSource.
@SuppressWarnings("unchecked")
@Test
public void testSource() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName());
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<Message<?>> messages = new ArrayList<>();
source.getStream().subscribe().with(messages::add);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, "hello", i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 10);
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
use of io.smallrye.reactive.messaging.kafka.impl.KafkaSource in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithLegacyMetadataTest method testInvalidIncomingType.
@SuppressWarnings("unchecked")
@Test
public void testInvalidIncomingType() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName());
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<Message<?>> messages = new ArrayList<>();
source.getStream().subscribe().with(messages::add);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 2);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 2);
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactly(0, 1);
companion.produceStrings().fromRecords(new ProducerRecord<>(topic, "hello"));
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 2);
// no other message received
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactly(0, 1);
}
use of io.smallrye.reactive.messaging.kafka.impl.KafkaSource in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithLegacyMetadataTest method testSourceWithPartitions.
@SuppressWarnings("unchecked")
@Test
public void testSourceWithPartitions() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName()).with("partitions", 4);
companion.topics().createAndWait(topic, 3);
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<Message<?>> messages = new ArrayList<>();
source.getStream().subscribe().with(messages::add);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 1000);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 1000);
List<Integer> expected = IntStream.range(0, 1000).boxed().collect(Collectors.toList());
// Because of partitions we cannot enforce the order.
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactlyInAnyOrderElementsOf(expected);
}
use of io.smallrye.reactive.messaging.kafka.impl.KafkaSource in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithLegacyMetadataTest method testSource.
@SuppressWarnings("unchecked")
@Test
public void testSource() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName());
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<Message<?>> messages = new ArrayList<>();
source.getStream().subscribe().with(messages::add);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, "hello", i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 10);
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
use of io.smallrye.reactive.messaging.kafka.impl.KafkaSource in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceTest method testSourceWithPartitions.
@SuppressWarnings("unchecked")
@Test
public void testSourceWithPartitions() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName()).with("partitions", 4);
companion.topics().createAndWait(topic, 3, Duration.ofMinutes(1));
KafkaConnectorIncomingConfiguration ic = new KafkaConnectorIncomingConfiguration(config);
source = new KafkaSource<>(vertx, UUID.randomUUID().toString(), ic, UnsatisfiedInstance.instance(), CountKafkaCdiEvents.noCdiEvents, UnsatisfiedInstance.instance(), -1);
List<Message<?>> messages = new ArrayList<>();
source.getStream().subscribe().with(messages::add);
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 1000);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages.size() >= 1000);
List<Integer> expected = IntStream.range(0, 1000).boxed().collect(Collectors.toList());
// Because of partitions we cannot enforce the order.
assertThat(messages.stream().map(m -> ((KafkaRecord<String, Integer>) m).getPayload()).collect(Collectors.toList())).containsExactlyInAnyOrderElementsOf(expected);
}
Aggregations