public ChoosableSet(int initialSize) { ids = new ConcurrentHashSet<>(initialSize); }
protected Set<Deployment> takeDeploymentSnapshot(int pos) { Set<Deployment> snapshot = new ConcurrentHashSet<>(); VertxInternal v = (VertxInternal)vertices[pos]; for (String depID: v.deploymentIDs()) { snapshot.add(v.getDeployment(depID)); } return snapshot; }
Set<HttpServer> connectedServers = new ConcurrentHashSet<>(); Map<HttpServer, Integer> connectCount = new ConcurrentHashMap<>();
Set<Context> contexts = new ConcurrentHashSet<>(); for (int i = 0; i < numServers; i++) { HttpServer theServer = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT));
@Test public void testContextsSend() throws Exception { Set<ContextInternal> contexts = new ConcurrentHashSet<>(); CountDownLatch latch = new CountDownLatch(2); vertx.eventBus().consumer(ADDRESS1).handler(msg -> { msg.reply("bar"); contexts.add(((VertxInternal) vertx).getContext()); latch.countDown(); }); vertx.eventBus().send(ADDRESS1, "foo", onSuccess((Message<Object> reply) -> { assertEquals("bar", reply.body()); contexts.add(((VertxInternal) vertx).getContext()); latch.countDown(); })); awaitLatch(latch); assertEquals(2, contexts.size()); }
@Test public void testContextsPublish() throws Exception { Set<ContextInternal> contexts = new ConcurrentHashSet<>(); AtomicInteger cnt = new AtomicInteger(); int numHandlers = 10; for (int i = 0; i < numHandlers; i++) { vertx.eventBus().consumer(ADDRESS1).handler(msg -> { contexts.add(((VertxInternal) vertx).getContext()); if (cnt.incrementAndGet() == numHandlers) { assertEquals(numHandlers, contexts.size()); testComplete(); } }); } vertx.eventBus().publish(ADDRESS1, "foo"); await(); }
awaitLatch(listenLatch); Set<Context> contexts = new ConcurrentHashSet<>(); AtomicInteger connectCount = new AtomicInteger(); CountDownLatch clientLatch = new CountDownLatch(1);
@Test // This tests using NetSocket.writeHandlerID (on the server side) // Send some data and make sure it is fanned out to all connections public void testFanout() throws Exception { int numConnections = 10; Set<String> connections = new ConcurrentHashSet<>(); server.connectHandler(socket -> { connections.add(socket.writeHandlerID()); if (connections.size() == numConnections) { for (String actorID : connections) { vertx.eventBus().publish(actorID, Buffer.buffer("some data")); } } socket.closeHandler(v -> { connections.remove(socket.writeHandlerID()); }); }); startServer(); CountDownLatch receivedLatch = new CountDownLatch(numConnections); for (int i = 0; i < numConnections; i++) { client.connect(testAddress, onSuccess(socket -> { socket.handler(data -> { receivedLatch.countDown(); }); })); } assertTrue(receivedLatch.await(10, TimeUnit.SECONDS)); testComplete(); }
@Test public void testContexts() throws Exception { Set<ContextInternal> contexts = new ConcurrentHashSet<>(); AtomicInteger cnt = new AtomicInteger(); AtomicReference<ContextInternal> serverRequestContext = new AtomicReference<>();
Set<HttpServer> connectedServers = new ConcurrentHashSet<>(); for (int i = 0; i < numServers; i++) { HttpServer server = vertx.createHttpServer(new HttpServerOptions().setHost(DEFAULT_HTTP_HOST).setPort(DEFAULT_HTTP_PORT));
public ChoosableSet(int initialSize) { ids = new ConcurrentHashSet<>(initialSize); }
protected Set<Deployment> takeDeploymentSnapshot(int pos) { Set<Deployment> snapshot = new ConcurrentHashSet<>(); VertxInternal v = (VertxInternal)vertices[pos]; for (String depID: v.deploymentIDs()) { snapshot.add(v.getDeployment(depID)); } return snapshot; }
Set<HttpServer> connectedServers = new ConcurrentHashSet<>(); Map<HttpServer, Integer> connectCount = new ConcurrentHashMap<>();
Set<Context> contexts = new ConcurrentHashSet<>(); for (int i = 0; i < numServers; i++) { HttpServer theServer = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT));
awaitLatch(listenLatch); Set<Context> contexts = new ConcurrentHashSet<>(); AtomicInteger connectCount = new AtomicInteger(); CountDownLatch clientLatch = new CountDownLatch(1);
@Test public void testContextsPublish() throws Exception { Set<ContextInternal> contexts = new ConcurrentHashSet<>(); AtomicInteger cnt = new AtomicInteger(); int numHandlers = 10; for (int i = 0; i < numHandlers; i++) { vertx.eventBus().consumer(ADDRESS1).handler(msg -> { contexts.add(((VertxInternal) vertx).getContext()); if (cnt.incrementAndGet() == numHandlers) { assertEquals(numHandlers, contexts.size()); testComplete(); } }); } vertx.eventBus().publish(ADDRESS1, "foo"); await(); }
@Test public void testContextsSend() throws Exception { Set<ContextInternal> contexts = new ConcurrentHashSet<>(); CountDownLatch latch = new CountDownLatch(2); vertx.eventBus().consumer(ADDRESS1).handler(msg -> { msg.reply("bar"); contexts.add(((VertxInternal) vertx).getContext()); latch.countDown(); }); vertx.eventBus().send(ADDRESS1, "foo", onSuccess((Message<Object> reply) -> { assertEquals("bar", reply.body()); contexts.add(((VertxInternal) vertx).getContext()); latch.countDown(); })); awaitLatch(latch); assertEquals(2, contexts.size()); }
@Test // This tests using NetSocket.writeHandlerID (on the server side) // Send some data and make sure it is fanned out to all connections public void testFanout() throws Exception { int numConnections = 10; Set<String> connections = new ConcurrentHashSet<>(); server.connectHandler(socket -> { connections.add(socket.writeHandlerID()); if (connections.size() == numConnections) { for (String actorID : connections) { vertx.eventBus().publish(actorID, Buffer.buffer("some data")); } } socket.closeHandler(v -> { connections.remove(socket.writeHandlerID()); }); }); startServer(); CountDownLatch receivedLatch = new CountDownLatch(numConnections); for (int i = 0; i < numConnections; i++) { client.connect(testAddress, onSuccess(socket -> { socket.handler(data -> { receivedLatch.countDown(); }); })); } assertTrue(receivedLatch.await(10, TimeUnit.SECONDS)); testComplete(); }
@Test public void testContexts() throws Exception { Set<ContextInternal> contexts = new ConcurrentHashSet<>(); AtomicInteger cnt = new AtomicInteger(); AtomicReference<ContextInternal> serverRequestContext = new AtomicReference<>();
Set<HttpServer> connectedServers = new ConcurrentHashSet<>(); for (int i = 0; i < numServers; i++) { HttpServer server = vertx.createHttpServer(new HttpServerOptions().setHost(DEFAULT_HTTP_HOST).setPort(DEFAULT_HTTP_PORT));