use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class TracingAmqpToAppWithParentTest method testFromAmqpToAppWithParentSpan.
@Test
public void testFromAmqpToAppWithParentSpan() {
weld.addBeanClass(MyAppReceivingData.class);
new MapBasedConfig().put("mp.messaging.incoming.stuff.connector", AmqpConnector.CONNECTOR_NAME).put("mp.messaging.incoming.stuff.host", host).put("mp.messaging.incoming.stuff.port", port).put("amqp-username", username).put("amqp-password", password).write();
container = weld.initialize();
MyAppReceivingData bean = container.getBeanManager().createInstance().select(MyAppReceivingData.class).get();
await().until(() -> isAmqpConnectorReady(container));
AtomicInteger count = new AtomicInteger();
List<SpanContext> producedSpanContexts = new CopyOnWriteArrayList<>();
usage.produce("stuff", 10, () -> AmqpMessage.create().durable(false).ttl(10000).withIntegerAsBody(count.getAndIncrement()).applicationProperties(createTracingSpan(producedSpanContexts, "stuff")).build());
await().until(() -> bean.list().size() >= 10);
assertThat(bean.list()).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
List<String> producedTraceIds = producedSpanContexts.stream().map(SpanContext::getTraceId).collect(Collectors.toList());
assertThat(producedTraceIds).hasSize(10);
assertThat(bean.tracing()).hasSizeGreaterThanOrEqualTo(10);
assertThat(bean.tracing()).doesNotContainNull().doesNotHaveDuplicates();
List<String> receivedTraceIds = bean.tracing().stream().map(tracingMetadata -> Span.fromContext(tracingMetadata.getCurrentContext()).getSpanContext().getTraceId()).collect(Collectors.toList());
assertThat(receivedTraceIds).doesNotContainNull().doesNotHaveDuplicates().hasSize(10);
assertThat(receivedTraceIds).containsExactlyInAnyOrderElementsOf(producedTraceIds);
List<String> spanIds = new ArrayList<>();
for (TracingMetadata tracing : bean.tracing()) {
spanIds.add(Span.fromContext(tracing.getCurrentContext()).getSpanContext().getSpanId());
assertThat(tracing.getPreviousContext()).isNotNull();
Span previousSpan = Span.fromContextOrNull(tracing.getPreviousContext());
assertThat(previousSpan).isNotNull();
assertThat(previousSpan.getSpanContext().getTraceId()).isEqualTo(Span.fromContext(tracing.getCurrentContext()).getSpanContext().getTraceId());
assertThat(previousSpan.getSpanContext().getSpanId()).isNotEqualTo(Span.fromContext(tracing.getCurrentContext()).getSpanContext().getSpanId());
}
assertThat(spanIds).doesNotContainNull().doesNotHaveDuplicates().hasSizeGreaterThanOrEqualTo(10);
List<String> parentIds = bean.tracing().stream().map(tracingMetadata -> Span.fromContextOrNull(tracingMetadata.getPreviousContext()).getSpanContext().getSpanId()).collect(Collectors.toList());
assertThat(producedSpanContexts.stream().map(SpanContext::getSpanId)).containsExactlyElementsOf(parentIds);
for (SpanData data : testExporter.getFinishedSpanItems()) {
assertThat(data.getSpanId()).isIn(spanIds);
assertThat(data.getSpanId()).isNotEqualTo(data.getParentSpanId());
assertThat(data.getKind()).isEqualByComparingTo(SpanKind.CONSUMER);
assertThat(data.getParentSpanId()).isNotNull();
assertThat(data.getParentSpanId()).isIn(parentIds);
}
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class CloudEventConsumptionTest method testReceivingStructuredCloudEventsWithStringPayload.
@SuppressWarnings("unchecked")
@Test
public void testReceivingStructuredCloudEventsWithStringPayload() {
String address = UUID.randomUUID().toString();
new MapBasedConfig().with("mp.messaging.incoming.source.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.source.address", address).with("mp.messaging.incoming.source.host", host).with("mp.messaging.incoming.source.port", port).with("mp.messaging.incoming.source.tracing-enabled", false).with("amqp-username", username).with("amqp-password", password).write();
weld.addBeanClass(MyConsumptionBean.class);
container = weld.initialize();
await().until(() -> isAmqpConnectorReady(container));
MyConsumptionBean bean = container.getBeanManager().createInstance().select(MyConsumptionBean.class).get();
usage.produce(address, 1, () -> {
JsonObject json = new JsonObject().put("specversion", CloudEventMetadata.CE_VERSION_1_0).put("type", "type").put("id", "id").put("source", "test://test").put("subject", "foo").put("datacontenttype", "application/json").put("dataschema", "http://schema.io").put("time", "2020-07-23T09:12:34Z").put("data", new JsonObject().put("name", "neo"));
return AmqpMessage.create().withBody(json.encode()).contentType(AmqpCloudEventHelper.STRUCTURED_CONTENT_TYPE).build();
});
await().atMost(2, TimeUnit.MINUTES).until(() -> bean.getList().size() >= 1);
Message<JsonObject> message = bean.getList().get(0);
IncomingCloudEventMetadata<JsonObject> metadata = message.getMetadata(IncomingCloudEventMetadata.class).orElse(null);
assertThat(metadata).isNotNull();
assertThat(metadata.getSpecVersion()).isEqualTo(CloudEventMetadata.CE_VERSION_1_0);
assertThat(metadata.getType()).isEqualTo("type");
assertThat(metadata.getId()).isEqualTo("id");
assertThat(metadata.getSource()).isEqualTo(URI.create("test://test"));
assertThat(metadata.getSubject()).hasValue("foo");
assertThat(metadata.getDataContentType()).hasValue("application/json");
assertThat(metadata.getDataSchema()).hasValue(URI.create("http://schema.io"));
assertThat(metadata.getTimeStamp()).isNotEmpty();
assertThat(metadata.getData().getString("name")).isEqualTo("neo");
assertThat(message.getPayload()).isInstanceOf(JsonObject.class);
assertThat(message.getPayload().getString("name")).isEqualTo("neo");
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class CloudEventConsumptionTest method testReceivingStructuredCloudEventsWithBinaryPayload.
@SuppressWarnings("unchecked")
@Test
public void testReceivingStructuredCloudEventsWithBinaryPayload() {
String address = UUID.randomUUID().toString();
new MapBasedConfig().with("mp.messaging.incoming.source.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.source.address", address).with("mp.messaging.incoming.source.host", host).with("mp.messaging.incoming.source.port", port).with("mp.messaging.incoming.source.tracing-enabled", false).with("amqp-username", username).with("amqp-password", password).write();
weld.addBeanClass(MyConsumptionBean.class);
container = weld.initialize();
await().until(() -> isAmqpConnectorReady(container));
MyConsumptionBean bean = container.getBeanManager().createInstance().select(MyConsumptionBean.class).get();
usage.produce(address, 1, () -> {
JsonObject json = new JsonObject().put("specversion", CloudEventMetadata.CE_VERSION_1_0).put("type", "type").put("id", "id").put("source", "test://test").put("subject", "foo").put("datacontenttype", "application/json").put("dataschema", "http://schema.io").put("time", "2020-07-23T09:12:34Z").put("data", new JsonObject().put("name", "neo"));
return AmqpMessage.create().withBufferAsBody(Buffer.buffer(json.toBuffer().getBytes())).contentType(AmqpCloudEventHelper.STRUCTURED_CONTENT_TYPE).build();
});
await().atMost(2, TimeUnit.MINUTES).until(() -> bean.getList().size() >= 1);
Message<JsonObject> message = bean.getList().get(0);
IncomingCloudEventMetadata<JsonObject> metadata = message.getMetadata(IncomingCloudEventMetadata.class).orElse(null);
assertThat(metadata).isNotNull();
assertThat(metadata.getSpecVersion()).isEqualTo(CloudEventMetadata.CE_VERSION_1_0);
assertThat(metadata.getType()).isEqualTo("type");
assertThat(metadata.getId()).isEqualTo("id");
assertThat(metadata.getSource()).isEqualTo(URI.create("test://test"));
assertThat(metadata.getSubject()).hasValue("foo");
assertThat(metadata.getDataContentType()).hasValue("application/json");
assertThat(metadata.getDataSchema()).hasValue(URI.create("http://schema.io"));
assertThat(metadata.getTimeStamp()).isNotEmpty();
assertThat(metadata.getData().getString("name")).isEqualTo("neo");
assertThat(message.getPayload()).isInstanceOf(JsonObject.class);
assertThat(message.getPayload().getString("name")).isEqualTo("neo");
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class CloudEventConsumptionTest method testReceivingStructuredCloudEventsWithoutMatchingContentTypeIsNotReadACloudEvent.
@SuppressWarnings("unchecked")
@Test
public void testReceivingStructuredCloudEventsWithoutMatchingContentTypeIsNotReadACloudEvent() {
String address = UUID.randomUUID().toString();
new MapBasedConfig().with("mp.messaging.incoming.source.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.source.address", address).with("mp.messaging.incoming.source.host", host).with("mp.messaging.incoming.source.port", port).with("mp.messaging.incoming.source.tracing-enabled", false).with("amqp-username", username).with("amqp-password", password).write();
weld.addBeanClass(MyConsumptionBean.class);
container = weld.initialize();
await().until(() -> isAmqpConnectorReady(container));
MyConsumptionBean bean = container.getBeanManager().createInstance().select(MyConsumptionBean.class).get();
usage.produce(address, 1, () -> {
JsonObject json = new JsonObject().put("specversion", CloudEventMetadata.CE_VERSION_1_0).put("type", "type").put("id", "id").put("source", "test://test").put("data", new JsonObject().put("name", "neo"));
return AmqpMessage.create().withJsonObjectAsBody(// Set the content type to application/json
json).build();
});
await().atMost(2, TimeUnit.MINUTES).until(() -> bean.getList().size() >= 1);
Message<JsonObject> message = bean.getList().get(0);
IncomingCloudEventMetadata<JsonObject> metadata = message.getMetadata(IncomingCloudEventMetadata.class).orElse(null);
assertThat(metadata).isNull();
assertThat(message.getPayload().getString("id")).isEqualTo("id");
}
use of io.smallrye.reactive.messaging.test.common.config.MapBasedConfig in project smallrye-reactive-messaging by smallrye.
the class CloudEventConsumptionTest method testReceivingStructuredCloudEventsWithoutSource.
@Test
public void testReceivingStructuredCloudEventsWithoutSource() {
String address = UUID.randomUUID().toString();
new MapBasedConfig().with("mp.messaging.incoming.source.connector", AmqpConnector.CONNECTOR_NAME).with("mp.messaging.incoming.source.address", address).with("mp.messaging.incoming.source.host", host).with("mp.messaging.incoming.source.port", port).with("mp.messaging.incoming.source.tracing-enabled", false).with("amqp-username", username).with("amqp-password", password).write();
weld.addBeanClass(MyConsumptionBean.class);
container = weld.initialize();
await().until(() -> isAmqpConnectorReady(container));
MyConsumptionBean bean = container.getBeanManager().createInstance().select(MyConsumptionBean.class).get();
usage.produce(address, 1, () -> {
JsonObject json = new JsonObject().put("specversion", CloudEventMetadata.CE_VERSION_1_0).put("type", "type").put("id", "id").put("subject", "foo").put("data", new JsonObject().put("name", "neo"));
return AmqpMessage.create().withJsonObjectAsBody(json).contentType(AmqpCloudEventHelper.STRUCTURED_CONTENT_TYPE).build();
});
await().pollDelay(Duration.ofSeconds(1)).atMost(2, TimeUnit.MINUTES).until(() -> bean.getList().size() == 0);
// Nothing has been received because the deserializer is not supported.
}
Aggregations