use of org.eclipse.microprofile.reactive.messaging.Message in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class KafkaTopicInvokerTest method onEvent.
@Test
public void onEvent() {
ArgumentCaptor<Message<String>> captor = ArgumentCaptor.forClass(Message.class);
Emitter<String> emitter = mock(Emitter.class);
String event = "{\"key\": \"value\"}";
String topic = "myTestTopic";
ProcessorDTO processor = createProcessor();
KafkaTopicInvoker invoker = new KafkaTopicInvoker(emitter, processor, topic);
invoker.onEvent(event);
verify(emitter).send(captor.capture());
Message<String> sent = captor.getValue();
assertThat(sent.getPayload()).isEqualTo(event);
Metadata metadata = sent.getMetadata();
OutgoingKafkaRecordMetadata recordMetadata = metadata.get(OutgoingKafkaRecordMetadata.class).get();
assertThat(recordMetadata.getTopic()).isEqualTo(topic);
}
use of org.eclipse.microprofile.reactive.messaging.Message 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 org.eclipse.microprofile.reactive.messaging.Message 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 org.eclipse.microprofile.reactive.messaging.Message 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 org.eclipse.microprofile.reactive.messaging.Message 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);
}
Aggregations