use of io.vertx.ext.unit.Async in project vertx-camel-bridge by vert-x3.
the class InboundEndpointTest method testWithDirectEndpointWithPublish.
@Test
public void testWithDirectEndpointWithPublish(TestContext context) throws Exception {
Async async = context.async();
Async async2 = context.async();
Endpoint endpoint = camel.getEndpoint("direct:foo");
bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel).addInboundMapping(fromCamel(endpoint).toVertx("test").usePublish()));
vertx.eventBus().consumer("test", message -> {
context.assertEquals("hello", message.body());
async.complete();
});
vertx.eventBus().consumer("test", message -> {
context.assertEquals("hello", message.body());
async2.complete();
});
camel.start();
BridgeHelper.startBlocking(bridge);
ProducerTemplate producer = camel.createProducerTemplate();
producer.asyncSendBody(endpoint, "hello");
}
use of io.vertx.ext.unit.Async in project vertx-camel-bridge by vert-x3.
the class InboundEndpointTest method testWithDirectEndpointWithHeaderCopy.
@Test
public void testWithDirectEndpointWithHeaderCopy(TestContext context) throws Exception {
Async async = context.async();
Endpoint endpoint = camel.getEndpoint("direct:foo");
bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel).addInboundMapping(fromCamel("direct:foo").toVertx("test")));
vertx.eventBus().consumer("test", message -> {
context.assertEquals("hello", message.body());
context.assertEquals(message.headers().get("key"), "value");
async.complete();
});
camel.start();
BridgeHelper.startBlocking(bridge);
ProducerTemplate producer = camel.createProducerTemplate();
producer.asyncSend(endpoint, exchange -> {
Message message = exchange.getIn();
message.setBody("hello");
message.setHeader("key", "value");
});
}
use of io.vertx.ext.unit.Async in project hono by eclipse.
the class IntegrationTestSupport method deleteObjects.
/**
* Deletes all temporary objects from the Device Registry which
* have been created during the last test execution.
*
* @param ctx The vert.x context.
*/
public void deleteObjects(final TestContext ctx) {
devicesToDelete.forEach((tenantId, devices) -> {
devices.forEach(deviceId -> {
final Async deletion = ctx.async();
CompositeFuture.join(registry.deregisterDevice(tenantId, deviceId), registry.removeAllCredentials(tenantId, deviceId)).setHandler(ok -> deletion.complete());
deletion.await();
});
});
devicesToDelete.clear();
tenantsToDelete.forEach(tenantId -> {
final Async deletion = ctx.async();
registry.removeTenant(tenantId).setHandler(ok -> deletion.complete());
deletion.await();
});
tenantsToDelete.clear();
}
use of io.vertx.ext.unit.Async in project hono by eclipse.
the class ClientTestBase method testSendingMessages.
/**
* Verifies that a number of messages uploaded to Hono's Telemetry or Event API can be successfully
* consumed via the AMQP Messaging Network.
*
* @param ctx The test context.
* @throws InterruptedException if test execution is interrupted.
*/
@Test
public void testSendingMessages(final TestContext ctx) throws InterruptedException {
final CountDownLatch received = new CountDownLatch(IntegrationTestSupport.MSG_COUNT);
final Async setup = ctx.async();
final AtomicReference<String> registrationAssertion = new AtomicReference<>();
registrationClient.register(DEVICE_ID, null).compose(ok -> registrationClient.assertRegistration(DEVICE_ID)).compose(result -> {
registrationAssertion.set(result.getString(RegistrationConstants.FIELD_ASSERTION));
return createConsumer(TEST_TENANT_ID, msg -> {
LOGGER.trace("received {}", msg);
assertMessageProperties(ctx, msg);
assertAdditionalMessageProperties(ctx, msg);
received.countDown();
if (received.getCount() % 200 == 0) {
LOGGER.info("messages received: {}", IntegrationTestSupport.MSG_COUNT - received.getCount());
}
});
}).map(c -> {
consumer = c;
setup.complete();
return null;
});
setup.await(1000);
long start = System.currentTimeMillis();
final AtomicInteger messagesSent = new AtomicInteger();
while (messagesSent.get() < IntegrationTestSupport.MSG_COUNT) {
final Async sending = ctx.async();
sender.send(DEVICE_ID, "payload_" + messagesSent.getAndIncrement(), CONTENT_TYPE_TEXT_PLAIN, registrationAssertion.get(), creditAvailable -> sending.complete());
if (messagesSent.get() % 200 == 0) {
LOGGER.info("messages sent: " + messagesSent.get());
}
sending.await();
}
long timeToWait = Math.max(DEFAULT_TEST_TIMEOUT, Math.round(IntegrationTestSupport.MSG_COUNT * 1.2));
if (!received.await(timeToWait, TimeUnit.MILLISECONDS)) {
LOGGER.info("sent {} and received {} messages after {} milliseconds", messagesSent.get(), IntegrationTestSupport.MSG_COUNT - received.getCount(), System.currentTimeMillis() - start);
ctx.fail("did not receive all messages sent");
} else {
LOGGER.info("sent {} and received {} messages after {} milliseconds", messagesSent.get(), IntegrationTestSupport.MSG_COUNT - received.getCount(), System.currentTimeMillis() - start);
}
}
use of io.vertx.ext.unit.Async in project hono by eclipse.
the class ClientTestBase method deregister.
/**
* Deregisters the test device (DEVICE_ID) and disconnects from
* the Hono server, Hono device registry and AMQP messaging network.
*
* @param ctx The test context
*/
@After
public void deregister(final TestContext ctx) {
if (registrationClient != null) {
final Async done = ctx.async();
LOGGER.debug("deregistering devices");
registrationClient.deregister(DEVICE_ID).setHandler(r -> done.complete());
done.await(2000);
}
disconnect(ctx);
}
Aggregations