@Test public void testRacingRegistrations() throws InterruptedException { for (int i = 0; i < ITERATIONS; i++) { startLatch = new CountDownLatch(THREAD_COUNT); registeredLatch = new CountDownLatch(THREAD_COUNT); canUnregisterLatch = new CountDownLatch(1); unregisteredLatch = new CountDownLatch(THREAD_COUNT); List<SubscriberThread> threads = startThreads(); registeredLatch.await(); eventBus.post("42"); canUnregisterLatch.countDown(); for (int t = 0; t < THREAD_COUNT; t++) { int eventCount = threads.get(t).eventCount; if (eventCount != 1) { fail("Failed in iteration " + i + ": thread #" + t + " has event count of " + eventCount); } } // Wait for threads to be done unregisteredLatch.await(); } }
@Override public void accept(String v) { assertEquals("one", v); System.out.println("v: " + v); latch.countDown(); } });
@Override public ListenableFuture<String> call() throws Exception { inFunction.countDown(); try { new CountDownLatch(1).await(); // wait for interrupt } catch (InterruptedException expected) { gotException.countDown(); throw expected; } return immediateFuture("a"); } };
@Test public void testSharedServersRoundRobinWithOtherServerRunningOnDifferentPort() throws Exception { // Have a server running on a different port to make sure it doesn't interact CountDownLatch latch = new CountDownLatch(1); HttpServer theServer = vertx.createHttpServer(new HttpServerOptions().setPort(8081)); theServer.requestHandler(req -> { fail("Should not process request"); }).listen(onSuccess(s -> latch.countDown())); awaitLatch(latch); testSharedServersRoundRobin(); }
final AtomicInteger count = new AtomicInteger(2); final CountDownLatch cdl = new CountDownLatch(2); cdl.countDown(); if (!cdl.await(5, TimeUnit.SECONDS)) { throw new AssertionError("The wait timed out!");
public void testExecute_idempotentConcurrently() throws InterruptedException { final CountDownLatch okayToRun = new CountDownLatch(1); final AtomicInteger runCalled = new AtomicInteger(); list.add( new Runnable() { thread2.start(); assertEquals(0, runCalled.get()); okayToRun.countDown(); thread1.join(); thread2.join();
public void testStopWhileStarting_runNotCalled() throws Exception { final CountDownLatch started = new CountDownLatch(1); FakeService service = new FakeService() { @Override protected void startUp() throws Exception { super.startUp(); started.await(); } }; service.startAsync(); service.stopAsync(); started.countDown(); service.awaitTerminated(); assertEquals(Service.State.TERMINATED, service.state()); assertEquals(1, service.startupCalled); assertEquals(0, service.runCalled); assertEquals(1, service.shutdownCalled); }
@Test(timeout = 1000) public void settingUnderlyingWhenUnsubscribedCausesImmediateUnsubscriptionConcurrently() throws InterruptedException { serialDisposable.update(firstSet); final CountDownLatch start = new CountDownLatch(1); final CountDownLatch end = new CountDownLatch(count); start.countDown(); serialDisposable.update(underlying); end.await(); verify(firstSet).dispose(); verify(underlying).dispose();
@Override public void accept(String v) { assertEquals("one", v); System.out.println("v: " + v); latch.countDown(); } });
@Override public Void call() throws Exception { enterLatch.countDown(); new CountDownLatch(1).await(); // wait forever return null; } });
@Test public void testReplyFailureNoHandlers() throws Exception { CountDownLatch latch = new CountDownLatch(1); EventBus eb = vertx.eventBus(); eb.send(ADDRESS1, "bar", new DeliveryOptions().setSendTimeout(10), ar -> { assertTrue(ar.failed()); latch.countDown(); }); awaitLatch(latch); FakeEventBusMetrics metrics = FakeMetricsBase.getMetrics(eb); assertEquals(Collections.singletonList(ADDRESS1), metrics.getReplyFailureAddresses()); assertEquals(Collections.singletonList(ReplyFailure.NO_HANDLERS), metrics.getReplyFailures()); }