use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method sendReceiveEcho.
private void sendReceiveEcho(TestContext context, String data) {
Async async = context.async();
connect(context, connection -> {
connection.open();
connection.createReceiver(MockServer.Addresses.echo.toString()).handler((d, m) -> {
String actual = (String) (getMessageBody(context, m));
context.assertEquals(data, actual);
connection.disconnect();
async.complete();
}).open();
connection.createSender(MockServer.Addresses.echo.toString()).open().send(message("echo", data));
});
}
use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method testConnectionOpenResultReturnsConnection.
@Test(timeout = 20000)
public void testConnectionOpenResultReturnsConnection(TestContext context) {
Async async = context.async();
connect(context, connectedConn -> {
connectedConn.openHandler(result -> {
context.assertTrue(result.succeeded());
ProtonConnection openedConn = result.result();
context.assertNotNull(openedConn, "opened connection result should not be null");
openedConn.disconnect();
async.complete();
}).open();
});
}
use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method testAnonymousRelayIsNotSupported.
@Test(timeout = 20000)
public void testAnonymousRelayIsNotSupported(TestContext context) {
((ProtonServerImpl) server.getProtonServer()).setAdvertiseAnonymousRelayCapability(false);
Async async = context.async();
connect(context, connection -> {
context.assertFalse(connection.isAnonymousRelaySupported(), "Connection not yet open, so result should be false");
connection.openHandler(x -> {
context.assertFalse(connection.isAnonymousRelaySupported(), "Connection now open, server does not support relay, should be false");
connection.disconnect();
async.complete();
}).open();
});
}
use of io.vertx.ext.unit.TestContext in project vertx-proton by vert-x3.
the class ProtonClientTest method doOpenLinkWithQosTestImpl.
public void doOpenLinkWithQosTestImpl(TestContext context, boolean clientSender, ProtonQoS qos) throws Exception {
server.close();
Async serverAsync = context.async();
Async clientAsync = context.async();
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> session.open());
if (clientSender) {
serverConnection.receiverOpenHandler(receiver -> {
context.assertEquals(qos, receiver.getRemoteQoS(), "unexpected remote qos value");
LOG.trace("Server receiver opened");
receiver.open();
serverAsync.complete();
});
} else {
serverConnection.senderOpenHandler(sender -> {
context.assertEquals(qos, sender.getRemoteQoS(), "unexpected remote qos value");
LOG.trace("Server sender opened");
sender.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<?> link;
if (clientSender) {
link = connection.createSender(null);
} else {
link = connection.createReceiver("some-address");
}
link.setQoS(qos);
link.openHandler(y -> {
LOG.trace("Client link opened");
context.assertEquals(qos, link.getRemoteQoS(), "unexpected remote qos value");
clientAsync.complete();
});
link.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 ProtonClientTest method testLinkPropertiesAndCapabilities.
@Test(timeout = 20000)
public void testLinkPropertiesAndCapabilities(TestContext context) throws Exception {
server.close();
Async serverAsync = context.async();
Async clientAsync = context.async();
Map<Symbol, Object> clientProperties = Collections.singletonMap(Symbol.valueOf("client"), true);
Map<Symbol, Object> serverProperties = Collections.singletonMap(Symbol.valueOf("server"), true);
Symbol cap1 = Symbol.valueOf("1");
Symbol cap2 = Symbol.valueOf("1");
Symbol cap3 = Symbol.valueOf("1");
Symbol cap4 = Symbol.valueOf("1");
Symbol[] clientDesired = { cap1, cap2 };
Symbol[] clientOffered = { cap3 };
Symbol[] serverDesried = { cap3, cap4 };
Symbol[] serverOffered = { cap2 };
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> {
session.open();
});
serverConnection.senderOpenHandler(serverSender -> {
context.assertEquals(clientProperties, serverSender.getRemoteProperties());
context.assertTrue(Arrays.equals(clientDesired, serverSender.getRemoteDesiredCapabilities()));
context.assertTrue(Arrays.equals(clientOffered, serverSender.getRemoteOfferedCapabilities()));
LOG.trace("Server sender opened");
serverSender.setProperties(serverProperties);
serverSender.setDesiredCapabilities(serverDesried);
serverSender.setOfferedCapabilities(serverOffered);
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");
receiver.setProperties(clientProperties);
receiver.setDesiredCapabilities(clientDesired);
receiver.setOfferedCapabilities(clientOffered);
receiver.openHandler(y -> {
LOG.trace("Client link opened");
context.assertEquals(serverProperties, receiver.getRemoteProperties(), "Unexpected value for link properties");
context.assertTrue(Arrays.equals(serverDesried, receiver.getRemoteDesiredCapabilities()));
context.assertTrue(Arrays.equals(serverOffered, receiver.getRemoteOfferedCapabilities()));
clientAsync.complete();
});
receiver.open();
}).open();
});
serverAsync.awaitSuccess();
clientAsync.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
Aggregations