use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method testIsAnonymousRelaySupported.
@Test(timeout = 20000)
public void testIsAnonymousRelaySupported(TestContext context) {
Async async = context.async();
connect(context, connection -> {
context.assertFalse(connection.isAnonymousRelaySupported(), "Connection not yet open, so result should be false");
connection.openHandler(x -> {
context.assertTrue(connection.isAnonymousRelaySupported(), "Connection now open, server supports relay, should be true");
connection.disconnect();
async.complete();
}).open();
});
}
use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method remoteCloseDefaultSessionTestImpl.
private void remoteCloseDefaultSessionTestImpl(TestContext context, boolean sessionError) throws InterruptedException, ExecutionException {
server.close();
Async async = context.async();
ProtonServer protonServer = null;
try {
protonServer = createServer(serverConnection -> {
Future<ProtonSession> sessionFuture = Future.<ProtonSession>future();
// Expect a session to open, when the sender is created by the client
serverConnection.sessionOpenHandler(serverSession -> {
LOG.trace("Server session open");
serverSession.open();
sessionFuture.complete(serverSession);
});
// Expect a receiver link, then close the session after opening it.
serverConnection.receiverOpenHandler(serverReceiver -> {
LOG.trace("Server receiver open");
serverReceiver.open();
context.assertTrue(sessionFuture.succeeded(), "Session future not [yet] succeeded");
LOG.trace("Server session close");
ProtonSession s = sessionFuture.result();
if (sessionError) {
ErrorCondition error = new ErrorCondition();
error.setCondition(AmqpError.INTERNAL_ERROR);
error.setDescription("error description");
s.setCondition(error);
}
s.close();
});
serverConnection.openHandler(result -> {
LOG.trace("Server connection open");
serverConnection.open();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.openHandler(x -> {
context.assertTrue(x.succeeded(), "Connection open failed");
LOG.trace("Client connection opened");
// Create a sender to provoke creation (and subsequent
// closure of by the server) the connections default session
connection.createSender(null).open();
});
connection.closeHandler(x -> {
LOG.trace("Connection close handler called (as espected): " + x.cause());
async.complete();
});
connection.open();
});
async.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method doDetachHandlingTestImpl.
public void doDetachHandlingTestImpl(TestContext context, boolean clientSender) throws Exception {
server.close();
final Async clientLinkOpenAsync = context.async();
final Async serverLinkOpenAsync = context.async();
final Async serverLinkDetachAsync = context.async();
final Async clientLinkDetachAsync = context.async();
final AtomicBoolean serverLinkCloseHandlerFired = new AtomicBoolean();
final AtomicBoolean clientLinkCloseHandlerFired = new AtomicBoolean();
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> session.open());
if (clientSender) {
serverConnection.receiverOpenHandler(serverReceiver -> {
LOG.trace("Server receiver opened");
serverReceiver.open();
serverLinkOpenAsync.complete();
serverReceiver.closeHandler(res -> {
serverLinkCloseHandlerFired.set(true);
});
serverReceiver.detachHandler(res -> {
context.assertTrue(res.succeeded(), "expected non-errored async result");
serverReceiver.detach();
serverLinkDetachAsync.complete();
});
});
} else {
serverConnection.senderOpenHandler(serverSender -> {
LOG.trace("Server sender opened");
serverSender.open();
serverLinkOpenAsync.complete();
serverSender.closeHandler(res -> {
serverLinkCloseHandlerFired.set(true);
});
serverSender.detachHandler(res -> {
context.assertTrue(res.succeeded(), "expected non-errored async result");
serverSender.detach();
serverLinkDetachAsync.complete();
});
});
}
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.openHandler(x -> {
LOG.trace("Client connection opened");
final ProtonLink<?> link;
if (clientSender) {
link = connection.createSender(null);
} else {
link = connection.createReceiver("some-address");
}
link.closeHandler(clientLink -> {
clientLinkCloseHandlerFired.set(true);
});
link.detachHandler(clientLink -> {
LOG.trace("Client link detached");
clientLinkDetachAsync.complete();
});
link.openHandler(y -> {
LOG.trace("Client link opened");
clientLinkOpenAsync.complete();
link.detach();
});
link.open();
}).open();
});
serverLinkOpenAsync.awaitSuccess();
clientLinkOpenAsync.awaitSuccess();
serverLinkDetachAsync.awaitSuccess();
clientLinkDetachAsync.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
context.assertFalse(serverLinkCloseHandlerFired.get(), "server link close handler should not have fired");
context.assertFalse(clientLinkCloseHandlerFired.get(), "client link close handler should not have fired");
}
use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method testDefaultAnonymousSenderSpecifiesLinkTarget.
@Test(timeout = 20000)
public void testDefaultAnonymousSenderSpecifiesLinkTarget(TestContext context) throws Exception {
server.close();
Async async = context.async();
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> processConnectionAnonymousSenderSpecifiesLinkTarget(context, async, serverConnection));
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.openHandler(x -> {
LOG.trace("Client connection opened");
ProtonSender sender = connection.createSender(null);
// Can optionally add an openHandler or sendQueueDrainHandler
// to await remote sender open completing or credit to send being
// granted. But here we will just buffer the send immediately.
sender.open();
sender.send(message("ignored", "content"));
}).open();
});
async.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonServerImplTest method testAuthenticatorCreatedPerConnection.
@Test(timeout = 20000)
public void testAuthenticatorCreatedPerConnection(TestContext context) {
Async connectedAsync = context.async();
Async connectedAsync2 = context.async();
AtomicInteger port = new AtomicInteger(-1);
final TestPlainAuthenticatorFactory authenticatorFactory = new TestPlainAuthenticatorFactory();
ProtonServer.create(vertx).saslAuthenticatorFactory(authenticatorFactory).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);
}).listen(server -> {
port.set(server.result().actualPort());
ProtonClient.create(vertx).connect("localhost", port.intValue(), GOOD_USER, PASSWD, protonConnectionAsyncResult -> {
context.assertTrue(protonConnectionAsyncResult.succeeded());
protonConnectionAsyncResult.result().disconnect();
connectedAsync.complete();
});
});
connectedAsync.awaitSuccess();
context.assertEquals(1, authenticatorFactory.getCreateCount(), "unexpected authenticator count");
ProtonClient.create(vertx).connect("localhost", port.intValue(), GOOD_USER, PASSWD, protonConnectionAsyncResult -> {
context.assertTrue(protonConnectionAsyncResult.succeeded());
protonConnectionAsyncResult.result().disconnect();
connectedAsync2.complete();
});
connectedAsync2.awaitSuccess();
context.assertEquals(2, authenticatorFactory.getCreateCount(), "unexpected authenticator count");
}
Aggregations