use of io.vertx.ext.unit.Async in project vertx-proton by vert-x3.
the class ProtonServerImplTest method testCustomAuthenticatorSuceedsAuthentication.
@Test(timeout = 20000)
public void testCustomAuthenticatorSuceedsAuthentication(TestContext context) {
Async connectedAsync = context.async();
Async authenticatedAsync = context.async();
ProtonServer.create(vertx).saslAuthenticatorFactory(new TestPlainAuthenticatorFactory()).connectHandler(protonConnection -> {
// Verify the expected auth detail was recorded in the connection attachments, just using a String here.
String authValue = protonConnection.attachments().get(AUTH_KEY, String.class);
context.assertEquals(AUTH_VALUE, authValue);
authenticatedAsync.complete();
}).listen(server -> ProtonClient.create(vertx).connect("localhost", server.result().actualPort(), GOOD_USER, PASSWD, protonConnectionAsyncResult -> {
context.assertTrue(protonConnectionAsyncResult.succeeded());
protonConnectionAsyncResult.result().disconnect();
connectedAsync.complete();
}));
authenticatedAsync.awaitSuccess();
connectedAsync.awaitSuccess();
}
use of io.vertx.ext.unit.Async in project vertx-proton by vert-x3.
the class ProtonBenchmark method benchmarkAtLeastOnceSendThroughput.
@Test
public void benchmarkAtLeastOnceSendThroughput(TestContext context) {
server.setProducerCredits(1000);
Async async = context.async();
connect(context, connection -> {
connection.open();
ProtonSender sender = connection.createSender(MockServer.Addresses.drop.toString()).setQoS(ProtonQoS.AT_LEAST_ONCE).open();
String name = "At Least Once Send Throughput";
Message message = message("drop", "Hello World");
benchmark(BENCHMARK_DURATION, name, counter -> {
sender.sendQueueDrainHandler(s -> {
while (!sender.sendQueueFull()) {
sender.send(message, d -> {
if (d.remotelySettled()) {
counter.incrementAndGet();
}
});
}
});
}, () -> {
connection.disconnect();
async.complete();
});
});
}
use of io.vertx.ext.unit.Async in project vertx-proton by vert-x3.
the class ProtonClientSslTest method testConnectWithSslToServerWhileUsingTrustAll.
@Test(timeout = 20000)
public void testConnectWithSslToServerWhileUsingTrustAll(TestContext context) throws Exception {
Async async = context.async();
// Create a server that accept a connection and expects a client connection+session+receiver
ProtonServerOptions serverOptions = new ProtonServerOptions();
serverOptions.setSsl(true);
PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD);
serverOptions.setPfxKeyCertOptions(serverPfxOptions);
protonServer = createServer(serverOptions, this::handleClientConnectionSessionReceiverOpen);
// Try to connect the client and expect it to succeed due to trusting all certs
ProtonClientOptions clientOptions = new ProtonClientOptions();
clientOptions.setSsl(true);
clientOptions.setTrustAll(true);
ProtonClient client = ProtonClient.create(vertx);
client.connect(clientOptions, "localhost", protonServer.actualPort(), res -> {
// Expect connect to succeed
context.assertTrue(res.succeeded());
async.complete();
});
async.awaitSuccess();
}
use of io.vertx.ext.unit.Async in project vertx-proton by vert-x3.
the class ProtonClientSslTest method testConnectWithSslSucceeds.
@Test(timeout = 20000)
public void testConnectWithSslSucceeds(TestContext context) throws Exception {
Async async = context.async();
// Create a server that accept a connection and expects a client connection+session+receiver
ProtonServerOptions serverOptions = new ProtonServerOptions();
serverOptions.setSsl(true);
PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD);
serverOptions.setPfxKeyCertOptions(serverPfxOptions);
protonServer = createServer(serverOptions, this::handleClientConnectionSessionReceiverOpen);
// Connect the client and open a receiver to verify the connection works
ProtonClientOptions clientOptions = new ProtonClientOptions();
clientOptions.setSsl(true);
PfxOptions clientPfxOptions = new PfxOptions().setPath(TRUSTSTORE).setPassword(PASSWORD);
clientOptions.setPfxTrustOptions(clientPfxOptions);
ProtonClient client = ProtonClient.create(vertx);
client.connect(clientOptions, "localhost", protonServer.actualPort(), res -> {
// Expect connect to succeed
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.open();
ProtonReceiver receiver = connection.createReceiver("some-address");
receiver.openHandler(recvResult -> {
context.assertTrue(recvResult.succeeded());
LOG.trace("Client reciever open");
async.complete();
}).open();
});
async.awaitSuccess();
}
use of io.vertx.ext.unit.Async in project vertx-camel-bridge by vert-x3.
the class InboundEndpointTest method testWithDirectEndpointWithPublishAndCustomTypeNoCodec.
@Test
public void testWithDirectEndpointWithPublishAndCustomTypeNoCodec(TestContext context) throws Exception {
Async async = context.async();
Endpoint endpoint = camel.getEndpoint("direct:foo");
bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel).addInboundMapping(fromCamel(endpoint).toVertx("test").usePublish()));
camel.start();
BridgeHelper.startBlocking(bridge);
ProducerTemplate producer = camel.createProducerTemplate();
producer.asyncSend(endpoint, exchange -> {
Message message = exchange.getIn();
message.setBody(new Person().setName("bob"));
exchange.addOnCompletion(new SynchronizationAdapter() {
@Override
public void onFailure(Exchange exchange) {
context.assertTrue(exchange.getException().getMessage().contains("No message codec"));
async.complete();
}
});
});
}
Aggregations