use of io.vertx.core.eventbus.Message in project vert.x by eclipse.
the class JsonEventBusTest method testChangesNotVisibleArray3.
@Test
public void testChangesNotVisibleArray3() {
List<Object> list = new ArrayList<>();
final JsonArray obj = new JsonArray(list);
eb.<JsonArray>consumer("foo").handler((Message<JsonArray> msg) -> {
vertx.setTimer(1000, id -> {
assertEquals(0, msg.body().size());
testComplete();
});
});
eb.send("foo", obj);
list.add("uhwqdiuh");
await();
}
use of io.vertx.core.eventbus.Message in project vert.x by eclipse.
the class JsonEventBusTest method testChangesNotVisibleArray2.
@Test
public void testChangesNotVisibleArray2() {
final JsonArray obj = new JsonArray();
eb.<JsonArray>consumer("foo").handler((Message<JsonArray> msg) -> msg.body().add("blah"));
eb.send("foo", obj);
vertx.setTimer(1000, id -> {
assertEquals(0, obj.size());
testComplete();
});
await();
}
use of io.vertx.core.eventbus.Message in project vert.x by eclipse.
the class DeploymentTest method testIsolationGroup.
private void testIsolationGroup(String group1, String group2, int count1, int count2, List<String> isolatedClasses, String verticleID) throws Exception {
Map<String, Integer> countMap = new ConcurrentHashMap<>();
vertx.eventBus().<JsonObject>consumer("testcounts").handler((Message<JsonObject> msg) -> {
countMap.put(msg.body().getString("deploymentID"), msg.body().getInteger("count"));
});
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<String> deploymentID1 = new AtomicReference<>();
AtomicReference<String> deploymentID2 = new AtomicReference<>();
boolean expectedSuccess = Thread.currentThread().getContextClassLoader() instanceof URLClassLoader;
try {
vertx.deployVerticle(verticleID, new DeploymentOptions().setIsolationGroup(group1).setIsolatedClasses(isolatedClasses), onSuccess(id1 -> {
deploymentID1.set(id1);
assertEquals(0, TestVerticle.instanceCount.get());
vertx.deployVerticle(verticleID, new DeploymentOptions().setIsolationGroup(group2).setIsolatedClasses(isolatedClasses), onSuccess(id2 -> {
deploymentID2.set(id2);
assertEquals(0, TestVerticle.instanceCount.get());
latch.countDown();
}));
}));
awaitLatch(latch);
// Wait until two entries in the map
assertWaitUntil(() -> countMap.size() == 2);
assertEquals(count1, countMap.get(deploymentID1.get()).intValue());
assertEquals(count2, countMap.get(deploymentID2.get()).intValue());
assertTrue(expectedSuccess);
} catch (IllegalStateException e) {
assertFalse(expectedSuccess);
}
}
use of io.vertx.core.eventbus.Message in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeEventTest method before.
@Before
public void before(TestContext context) {
vertx = Vertx.vertx();
final Async async = context.async();
vertx.eventBus().consumer("hello", (Message<JsonObject> msg) -> msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value"))));
vertx.eventBus().consumer("echo", (Message<JsonObject> msg) -> msg.reply(msg.body()));
vertx.setPeriodic(1000, __ -> vertx.eventBus().send("ping", new JsonObject().put("value", "hi")));
sslKeyPairCerts = new SSLKeyPairCerts().createTwoWaySSL();
TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("hello")).addInboundPermitted(new PermittedOptions().setAddress("echo")).addInboundPermitted(new PermittedOptions().setAddress("test")).addOutboundPermitted(new PermittedOptions().setAddress("echo")).addOutboundPermitted(new PermittedOptions().setAddress("ping")), new NetServerOptions().setClientAuth(ClientAuth.REQUEST).setSsl(true).setTrustStoreOptions(sslKeyPairCerts.getServerTrustStore()).setKeyStoreOptions(sslKeyPairCerts.getServerKeyStore()), be -> {
logger.info("Handled a bridge event " + be.getRawMessage());
if (be.socket().isSsl()) {
try {
for (Certificate c : be.socket().peerCertificates()) {
logger.info(((X509Certificate) c).getSubjectDN().toString());
}
} catch (SSLPeerUnverifiedException e) {
throw new RuntimeException("Failed to get peer certificates chain", e);
}
}
be.complete(true);
});
bridge.listen(7000, res -> {
context.assertTrue(res.succeeded());
async.complete();
});
}
use of io.vertx.core.eventbus.Message in project vertx-tcp-eventbus-bridge by vert-x3.
the class TcpEventBusBridgeEventTest method testSendVoidMessage.
@Test
public void testSendVoidMessage(TestContext context) {
// Send a request and get a response
NetClient client = vertx.createNetClient(new NetClientOptions().setSsl(true).setTrustStoreOptions(sslKeyPairCerts.getClientTrustStore()).setKeyStoreOptions(sslKeyPairCerts.getClientKeyStore()));
final Async async = context.async();
vertx.eventBus().consumer("test", (Message<JsonObject> msg) -> {
client.close();
async.complete();
});
client.connect(7000, "localhost", conn -> {
context.assertFalse(conn.failed());
NetSocket socket = conn.result();
FrameHelper.sendFrame("send", "test", new JsonObject().put("value", "vert.x"), socket);
});
}
Aggregations