/** * Awaits until this TestObserver/TestSubscriber receives an onError or onComplete events. * @return this * @throws InterruptedException if the current thread is interrupted while waiting * @see #awaitTerminalEvent() */ @SuppressWarnings("unchecked") public final U await() throws InterruptedException { if (done.getCount() == 0) { return (U)this; } done.await(); return (U)this; }
/** * */ public void onBeforeActivate() { CountDownLatch latch0 = initLatch; if (latch0 == null || latch0.getCount() == 0) initLatch = new CountDownLatch(1); }
CountDownLatch latch = new CountDownLatch(this.smartMemberCount); Set<String> countDownBeanNames = Collections.synchronizedSet(new LinkedHashSet<>()); Set<String> lifecycleBeanNames = new HashSet<>(this.lifecycleBeans.keySet()); latch.countDown(); latch.await(this.timeout, TimeUnit.MILLISECONDS); if (latch.getCount() > 0 && !countDownBeanNames.isEmpty() && logger.isInfoEnabled()) { logger.info("Failed to shut down " + countDownBeanNames.size() + " bean" + (countDownBeanNames.size() > 1 ? "s" : "") + " with phase value " +
/** * @param fut Future. */ private void checkAsyncListener(IgniteFutureImpl<String> fut) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); IgniteInClosure<? super IgniteFuture<String>> lsnr = createAsyncListener(latch, CUSTOM_THREAD_NAME, null); fut.listenAsync(lsnr, customExec); assert latch.await(1, TimeUnit.SECONDS) : latch.getCount(); }
final CountDownLatch countdown = new CountDownLatch(num_thread); for (int i = 0; i < num_thread; ++ i){ Thread t= new Thread() { public void run() { doSomething(); countdown.countDown(); System.out.printf("Waiting on %d other threads.",countdown.getCount()); countdown.await(); //waits until everyone reaches this point finish(); } }; t.start(); }
public void testNoIntercept() throws Exception { final CountDownLatch latch = new CountDownLatch(messageCount); consumer.setMessageListener(new MessageListener() { @Override public void onMessage(javax.jms.Message message) { latch.countDown(); } }); for (int i = 0; i < messageCount; i++){ javax.jms.Message message = producerSession.createTextMessage("test: " + i); producer.send(message); } latch.await(timeOutInSeconds, TimeUnit.SECONDS); assertEquals(0,latch.getCount()); }
/** * Awaits the specified amount of time or until this TestObserver/TestSubscriber * receives an onError or onComplete events, whichever happens first. * @param time the waiting time * @param unit the time unit of the waiting time * @return true if the TestObserver/TestSubscriber terminated, false if timeout happened * @throws InterruptedException if the current thread is interrupted while waiting * @see #awaitTerminalEvent(long, TimeUnit) */ public final boolean await(long time, TimeUnit unit) throws InterruptedException { boolean d = done.getCount() == 0 || (done.await(time, unit)); timeout = !d; return d; }
/** * Test that delayed allocation blocks */ @Test public void testDelayedAllocation() throws Exception { BufferPool pool = new BufferPool(5 * 1024, 1024, metrics, time, metricGroup); ByteBuffer buffer = pool.allocate(1024, maxBlockTimeMs); CountDownLatch doDealloc = asyncDeallocate(pool, buffer); CountDownLatch allocation = asyncAllocate(pool, 5 * 1024); assertEquals("Allocation shouldn't have happened yet, waiting on memory.", 1L, allocation.getCount()); doDealloc.countDown(); // return the memory assertTrue("Allocation should succeed soon after de-allocation", allocation.await(1, TimeUnit.SECONDS)); }
protected synchronized void waitForMore(int count) { latch = new CountDownLatch(count + (int)latch.getCount()); }
CountDownLatch latch = new CountDownLatch(this.smartMemberCount); Set<String> countDownBeanNames = Collections.synchronizedSet(new LinkedHashSet<>()); Set<String> lifecycleBeanNames = new HashSet<>(this.lifecycleBeans.keySet()); latch.countDown(); latch.await(this.timeout, TimeUnit.MILLISECONDS); if (latch.getCount() > 0 && !countDownBeanNames.isEmpty() && logger.isInfoEnabled()) { logger.info("Failed to shut down " + countDownBeanNames.size() + " bean" + (countDownBeanNames.size() > 1 ? "s" : "") + " with phase value " +
public void testRunOnPopulatedList() throws Exception { Executor exec = Executors.newCachedThreadPool(); CountDownLatch countDownLatch = new CountDownLatch(3); list.add(new MockRunnable(countDownLatch), exec); list.add(new MockRunnable(countDownLatch), exec); list.add(new MockRunnable(countDownLatch), exec); assertEquals(3L, countDownLatch.getCount()); list.execute(); // Verify that all of the runnables execute in a reasonable amount of time. assertTrue(countDownLatch.await(1L, TimeUnit.SECONDS)); }
/** * Awaits until this TestObserver/TestSubscriber receives an onError or onComplete events. * @return this * @throws InterruptedException if the current thread is interrupted while waiting * @see #awaitTerminalEvent() */ @SuppressWarnings("unchecked") public final U await() throws InterruptedException { if (done.getCount() == 0) { return (U)this; } done.await(); return (U)this; }
public void testListenerDoesNotRunUntilTaskCompletes() throws Exception { // Test default state of not started. assertEquals(1, listenerLatch.getCount()); assertFalse(task.isDone()); assertFalse(task.isCancelled()); // Start the task to put it in the RUNNING state. Have to use a separate // thread because the task will block on the task latch after unblocking // the run latch. exec.execute(task); runLatch.await(); assertEquals(1, listenerLatch.getCount()); assertFalse(task.isDone()); assertFalse(task.isCancelled()); // Finish the task by unblocking the task latch. Then wait for the // listener to be called by blocking on the listener latch. taskLatch.countDown(); assertEquals(25, task.get().intValue()); assertTrue(listenerLatch.await(5, TimeUnit.SECONDS)); assertTrue(task.isDone()); assertFalse(task.isCancelled()); }
public void testAwait_CountDownLatch() { final CountDownLatch latch = new CountDownLatch(1); Object x = new Object() { @Override protected void finalize() { latch.countDown(); } }; x = null; // Hint to the JIT that x is unreachable GcFinalization.await(latch); assertEquals(0, latch.getCount()); }
@Test public void testNonBlockingOuterWhileBlockingOnNext() throws InterruptedException { final CountDownLatch completedLatch = new CountDownLatch(1); final CountDownLatch nextLatch = new CountDownLatch(1); final AtomicLong completeTime = new AtomicLong(); System.out.println("After subscribe: " + completedLatch.getCount()); assertEquals(1, completedLatch.getCount()); nextLatch.countDown(); completedLatch.await(1000, TimeUnit.MILLISECONDS); assertTrue(completeTime.get() > afterSubscribeTime); System.out.println("onComplete nanos after subscribe: " + (completeTime.get() - afterSubscribeTime));
try { LOG.info("Starting ZK:" + (new Date()).toString()); opsCount = new CountDownLatch(limit); ZooKeeper zk = createClient(); LOG.info("Submitted all operations:" + (new Date()).toString()); if(!opsCount.await(10000, TimeUnit.MILLISECONDS)) Assert.fail("Haven't received all confirmations" + opsCount.getCount());