use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class CloudEventProductionTest method testSendingBinaryCloudEventsWithConfiguredTypeAndSource.
@Test
public void testSendingBinaryCloudEventsWithConfiguredTypeAndSource() {
String address = UUID.randomUUID().toString();
new MapBasedConfig().with("mp.messaging.outgoing.amqp.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.outgoing.amqp.address", address).with("mp.messaging.outgoing.amqp.host", host).with("mp.messaging.outgoing.amqp.port", port).with("mp.messaging.outgoing.amqp.cloud-events-type", "my type").with("mp.messaging.outgoing.amqp.cloud-events-source", "http://acme.org").with("amqp-username", username).with("amqp-password", password).write();
weld.addBeanClass(AmqpSender.class);
container = weld.initialize();
AmqpSender bean = container.getBeanManager().createInstance().select(AmqpSender.class).get();
Emitter<JsonObject> emitter = bean.get();
List<io.vertx.mutiny.amqp.AmqpMessage> list = new ArrayList<>();
usage.consume(address, list::add);
Message<JsonObject> msg = Message.of(new JsonObject().put("message", "hello")).addMetadata(OutgoingCloudEventMetadata.builder().withDataContentType("application/json+neo").withId("some id").build());
emitter.send(msg);
await().until(() -> list.size() == 1);
AmqpMessage message = list.get(0);
assertThat(message.address()).isEqualTo(address);
assertThat(message.contentType()).isEqualTo("application/json+neo");
JsonObject app = message.applicationProperties();
assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_SPEC_VERSION)).isEqualTo("1.0");
assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_TYPE)).isEqualTo("my type");
assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_SOURCE)).isEqualTo("http://acme.org");
assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_ID)).isEqualTo("some id");
assertThat(app.getString(AmqpCloudEventHelper.AMQP_HEADER_FOR_CONTENT_TYPE)).isEqualTo("application/json+neo");
JsonObject body = message.bodyAsJsonObject();
assertThat(body.getString("message")).isEqualTo("hello");
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class AmqpSourceTest method doSourceTestImpl.
private void doSourceTestImpl(boolean useChannelName) throws Exception {
int msgCount = 10;
List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>(msgCount));
server = setupMockServer(msgCount, dispositionsReceived, executionHolder.vertx().getDelegate());
String topic = UUID.randomUUID().toString();
Map<String, Object> config;
if (useChannelName) {
config = getConfigUsingChannelName(topic, server.actualPort());
} else {
config = getConfig(topic, server.actualPort());
}
provider = new AmqpConnector();
provider.setup(executionHolder);
PublisherBuilder<? extends Message<?>> builder = provider.getPublisherBuilder(new MapBasedConfig(config));
List<Message<Integer>> messages = new ArrayList<>();
builder.buildRs().subscribe(createSubscriber(messages, new AtomicBoolean()));
await().atMost(5, TimeUnit.SECONDS).until(() -> messages.size() >= 10);
assertThat(messages.stream().peek(m -> m.ack().toCompletableFuture().join()).map(Message::getPayload).collect(Collectors.toList())).containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
await().atMost(2, TimeUnit.SECONDS).until(() -> dispositionsReceived.size() >= msgCount);
AtomicInteger count = new AtomicInteger();
dispositionsReceived.forEach(record -> {
int messageNum = count.get() + 1;
assertThat(messageNum).isLessThanOrEqualTo(msgCount);
assertThat(record.getMessageNumber()).isEqualTo(messageNum);
assertThat(record.getState()).isInstanceOf(Accepted.class);
assertThat(record.isSettled()).isTrue();
count.incrementAndGet();
});
assertThat(count.get()).isEqualTo(msgCount);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class AmqpSourceTest method doDataContentTestImpl.
private void doDataContentTestImpl(boolean setContentType) throws Exception {
List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>());
final org.apache.qpid.proton.message.Message msg = Proton.message();
msg.setBody(new Data(new Binary("foo".getBytes(StandardCharsets.UTF_8))));
if (setContentType) {
msg.setContentType("application/octet-stream");
}
server = setupMockServerForTypeTest(msg, dispositionsReceived, executionHolder.vertx().getDelegate());
String topic = UUID.randomUUID().toString();
Map<String, Object> config = getConfig(topic, server.actualPort());
provider = new AmqpConnector();
provider.setup(executionHolder);
List<Message<byte[]>> messages = new ArrayList<>();
PublisherBuilder<? extends Message<?>> builder = provider.getPublisherBuilder(new MapBasedConfig(config));
builder.to(createSubscriber(messages, new AtomicBoolean())).run();
await().atMost(6, TimeUnit.SECONDS).until(() -> !messages.isEmpty());
assertThat(messages.stream().peek(m -> m.ack().toCompletableFuture().join()).map(Message::getPayload).collect(Collectors.toList())).containsExactly("foo".getBytes(StandardCharsets.UTF_8));
await().atMost(2, TimeUnit.SECONDS).until(() -> !dispositionsReceived.isEmpty());
AtomicInteger count = new AtomicInteger();
dispositionsReceived.forEach(record -> {
assertThat(record.getMessageNumber()).isEqualTo(1);
assertThat(record.getState()).isInstanceOf(Accepted.class);
assertThat(record.isSettled()).isTrue();
count.incrementAndGet();
});
assertThat(count.get()).isEqualTo(1);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class AmqpSourceTest method testSourceWithBinaryContent.
@Test
@Timeout(30)
public void testSourceWithBinaryContent() throws Exception {
List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>());
final org.apache.qpid.proton.message.Message msg = Proton.message();
msg.setBody(new AmqpValue(new Binary("foo".getBytes(StandardCharsets.UTF_8))));
server = setupMockServerForTypeTest(msg, dispositionsReceived, executionHolder.vertx().getDelegate());
String topic = UUID.randomUUID().toString();
Map<String, Object> config = getConfig(topic, server.actualPort());
provider = new AmqpConnector();
provider.setup(executionHolder);
List<Message<byte[]>> messages = new ArrayList<>();
PublisherBuilder<? extends Message<?>> builder = provider.getPublisherBuilder(new MapBasedConfig(config));
builder.to(createSubscriber(messages, new AtomicBoolean())).run();
await().atMost(6, TimeUnit.SECONDS).until(() -> !messages.isEmpty());
assertThat(messages.stream().peek(m -> m.ack().toCompletableFuture().join()).map(Message::getPayload).collect(Collectors.toList())).containsExactly("foo".getBytes(StandardCharsets.UTF_8));
await().atMost(2, TimeUnit.SECONDS).until(() -> !dispositionsReceived.isEmpty());
AtomicInteger count = new AtomicInteger();
dispositionsReceived.forEach(record -> {
assertThat(record.getMessageNumber()).isEqualTo(1);
assertThat(record.getState()).isInstanceOf(Accepted.class);
assertThat(record.isSettled()).isTrue();
count.incrementAndGet();
});
assertThat(count.get()).isEqualTo(1);
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class AmqpSourceTest method testABeanConsumingTheAMQPMessages.
@Test
@Timeout(30)
public void testABeanConsumingTheAMQPMessages() throws Exception {
int msgCount = 10;
List<DispositionRecord> dispositionsReceived = Collections.synchronizedList(new ArrayList<>(msgCount));
server = setupMockServer(msgCount, dispositionsReceived, executionHolder.vertx().getDelegate());
new MapBasedConfig().put("mp.messaging.incoming.data.address", "data").put("mp.messaging.incoming.data.connector", AmqpConnector.CONNECTOR_NAME).put("mp.messaging.incoming.data.host", "localhost").put("mp.messaging.incoming.data.port", server.actualPort()).put("mp.messaging.incoming.data.tracing-enabled", false).write();
ConsumptionBean bean = deploy();
List<Integer> list = bean.getResults();
await().atMost(5, TimeUnit.SECONDS).until(() -> list.size() >= 10);
// ConsumptionBean adds 1, thus shifting original values by 1
assertThat(list).containsExactly(2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
await().atMost(2, TimeUnit.SECONDS).until(() -> dispositionsReceived.size() >= msgCount);
AtomicInteger count = new AtomicInteger();
dispositionsReceived.forEach(record -> {
int messageNum = count.get() + 1;
assertThat(messageNum).isLessThanOrEqualTo(msgCount);
assertThat(record.getMessageNumber()).isEqualTo(messageNum);
assertThat(record.getState()).isInstanceOf(Accepted.class);
assertThat(record.isSettled()).isTrue();
count.incrementAndGet();
});
assertThat(count.get()).isEqualTo(msgCount);
}
Aggregations