use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method testClientIdentification.
@Test(timeout = 20000)
public void testClientIdentification(TestContext context) {
Async async = context.async();
connect(context, connection -> {
connection.setContainer("foo").openHandler(x -> {
context.assertEquals("foo", connection.getContainer());
// Our mock server responds with a pong container id
context.assertEquals("pong: foo", connection.getRemoteContainer());
connection.disconnect();
async.complete();
}).open();
});
}
use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method testReceiveMultipleMessagesWithLowerPrefetch.
@Test(timeout = 20000)
public void testReceiveMultipleMessagesWithLowerPrefetch(TestContext context) {
Async async = context.async();
connect(context, connection -> {
connection.open();
AtomicInteger counter = new AtomicInteger(0);
ProtonReceiver receiver = connection.createReceiver(MockServer.Addresses.five_messages.toString());
// Set prefetch to 2 credit. Test verifies receiver gets multiple messages, i.e credit is being replenished.
receiver.setPrefetch(2).handler((d, m) -> {
int count = counter.incrementAndGet();
validateMessage(context, count, String.valueOf(count), m);
if (count == 5) {
// Got the last message, lets finish the test.
LOG.trace("Got msg 5, completing async");
async.complete();
connection.disconnect();
}
}).open();
});
}
use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method testMaxMessageSize.
@Test(timeout = 20000)
public void testMaxMessageSize(TestContext context) throws Exception {
server.close();
Async serverAsync = context.async();
Async clientAsync = context.async();
final UnsignedLong clientMaxMsgSize = UnsignedLong.valueOf(54321);
final UnsignedLong serverMaxMsgSize = UnsignedLong.valueOf(12345);
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> {
session.open();
});
serverConnection.senderOpenHandler(serverSender -> {
context.assertEquals(clientMaxMsgSize, serverSender.getRemoteMaxMessageSize(), "unexpected remote max message size at server");
context.assertNull(serverSender.getMaxMessageSize(), "Expected no value to be set");
serverSender.setMaxMessageSize(serverMaxMsgSize);
context.assertEquals(serverMaxMsgSize, serverSender.getMaxMessageSize(), "Expected value to now be set");
LOG.trace("Server sender opened");
serverSender.open();
serverAsync.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<?> receiver = connection.createReceiver("some-address");
context.assertNull(receiver.getMaxMessageSize(), "Expected no value to be set");
receiver.setMaxMessageSize(clientMaxMsgSize);
context.assertEquals(clientMaxMsgSize, receiver.getMaxMessageSize(), "Expected value to now be set");
receiver.openHandler(y -> {
LOG.trace("Client link opened");
context.assertEquals(serverMaxMsgSize, receiver.getRemoteMaxMessageSize(), "unexpected remote max message size at client");
clientAsync.complete();
});
receiver.open();
}).open();
});
serverAsync.awaitSuccess();
clientAsync.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 testCustomAuthenticatorHasInitCalled.
@Test(timeout = 20000)
public void testCustomAuthenticatorHasInitCalled(TestContext context) {
Async initCalledAsync = context.async();
ProtonServer.create(vertx).saslAuthenticatorFactory(new ProtonSaslAuthenticatorFactory() {
@Override
public ProtonSaslAuthenticator create() {
return new ProtonSaslAuthenticator() {
@Override
public void init(NetSocket socket, ProtonConnection protonConnection, Transport transport) {
initCalledAsync.complete();
}
@Override
public void process(Handler<Boolean> completionHandler) {
completionHandler.handle(false);
}
@Override
public boolean succeeded() {
return false;
}
};
}
}).connectHandler(protonConnection -> {
}).listen(server -> ProtonClient.create(vertx).connect("localhost", server.result().actualPort(), protonConnectionAsyncResult -> {
}));
}
use of io.vertx.ext.unit.TestContext 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();
}
Aggregations