/** * @param top Topology. * @param topVer Version to wait for. * @throws Exception If failed. */ protected final void waitForReadyTopology(final GridDhtPartitionTopology top, final AffinityTopologyVersion topVer) throws Exception { GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return topVer.compareTo(top.readyTopologyVersion()) <= 0; } }, 5000); }
/** * @param cache Cache. * @param exp Expected. */ private static void waitingForCompletion(final IgniteCache<Integer, String> cache, final int exp) throws IgniteInterruptedCheckedException { GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { GridCacheQueryMetricsAdapter m = (GridCacheQueryMetricsAdapter)cache.queryMetrics(); return m.completedExecutions() == exp; } }, 5000); } }
/** * Await future completion. * * @param fut Future. * @return {@code True} if future completed. * @throws Exception If failed. */ private static boolean awaitFuture(final IgniteInternalFuture fut) throws Exception { return GridTestUtils.waitForCondition(new GridAbsPredicateX() { @Override public boolean applyx() throws IgniteCheckedException { return fut.isDone(); } }, 1000); }
/** * @param lock IgniteLock. * @throws Exception If failed. */ protected void checkRemovedReentrantLock(final IgniteLock lock) throws Exception { assert GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return lock.removed(); } }, 5000); assert lock.removed(); }
/** * @param services Ignite services. * @param srvcName Service name to wait. * @throws IgniteInterruptedCheckedException If interrupted. */ private void waitForServiceDeploymentIfNeeded(IgniteServices services, String srvcName) throws IgniteInterruptedCheckedException { if (!isEventDrivenServiceProcessorEnabled) GridTestUtils.waitForCondition(() -> services.service(srvcName) != null, DEPLOYMENT_WAIT_TIMEOUT); }
/** * @param semaphore Semaphore. * @throws Exception If failed. */ protected void checkRemovedSemaphore(final IgniteSemaphore semaphore) throws Exception { assert GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return semaphore.removed(); } }, 5000); assert semaphore.removed(); }
/** * @param enabled1 Statistics enabled for cache 1. * @param enabled2 Statistics enabled for cache 2. */ private void assertCachesStatisticsMode(final boolean enabled1, final boolean enabled2) throws IgniteInterruptedCheckedException { assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return checkStatisticsMode(CACHE1, enabled1) && checkStatisticsMode(CACHE2, enabled2); } }, WAIT_CONDITION_TIMEOUT)); }
/** * @param spi Spi. * * @return {@code true} if sessions count was achieved, {@code false} otherwise. */ private boolean waitForSessionsCount(TcpCommunicationSpi spi, int cnt) throws IgniteInterruptedCheckedException { return GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(spi, "nioSrvr", "sessions"); return sessions.size() == cnt; } }, awaitForSocketWriteTimeout()); }
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); startGridsMultiThreaded(2); assert GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return grid(0).cluster().nodes().size() == 2; } }, 10000L); }
/** */ protected void waitAndCheckExpired( final IgniteCache<Integer, byte[]> cache) throws IgniteInterruptedCheckedException { GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return cache.size() == 0; } }, TimeUnit.SECONDS.toMillis(EXPIRATION_TIMEOUT + 1)); pringStatistics((IgniteCacheProxy)cache, "After timeout"); for (int i = 0; i < ENTRIES; i++) assertNull(cache.get(i)); }
/** * @param node Node. * @param expNodes Expected node in cluster. * @throws Exception If failed. */ private void checkNodesNumber(final Ignite node, final int expNodes) throws Exception { GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return node.cluster().nodes().size() == expNodes; } }, 5000); assertEquals(expNodes, node.cluster().nodes().size()); }
/** * @throws Exception If failed. */ @Test public void testSmall() throws Exception { final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 256), WAIT_BUFFER_TIMEOUT)); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 128), WAIT_BUFFER_TIMEOUT)); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 64), WAIT_BUFFER_TIMEOUT)); assertFalse(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 32), WAIT_BUFFER_TIMEOUT)); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 64), WAIT_BUFFER_TIMEOUT)); }
/** * Assert that on barrier waiting one thread. * * @throws IgniteInterruptedCheckedException In case of failure. */ private void assertWaitingOnBarrier() throws IgniteInterruptedCheckedException { Assert.assertTrue("Still waiting " + barrier.getNumberWaiting() + " parties", GridTestUtils.waitForCondition(() -> barrier.getNumberWaiting() == 1, TIMEOUT_IN_MS)); }
/** * @param ignite Ignite. * @throws Exception If failed. */ private void waitSegmented(final Ignite ignite) throws Exception { GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return IgniteState.STOPPED_ON_SEGMENTATION == Ignition.state(ignite.name()); } }, 5000); assertEquals(IgniteState.STOPPED_ON_SEGMENTATION, Ignition.state(ignite.name())); }
/** * */ private void awaitStop(final IgniteEx grid) throws IgniteInterruptedCheckedException { GridTestUtils.waitForCondition(() -> grid.context().gateway().getState() == GridKernalState.STOPPED, STOP_TIMEOUT_MS); }
/** * @param igniteWork Working ignite instance. * @param igniteFail Failed ignite instance. */ private static void assertFailureState(Ignite igniteWork, Ignite igniteFail) throws IgniteInterruptedCheckedException { assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return dummyFailureHandler(igniteFail).failure(); } }, 5000L)); assertFalse(dummyFailureHandler(igniteWork).failure()); }
/** * Check that streaming state on target node is as expected. * * @param on Expected streaming state. */ protected void assertStreamingState(boolean on) throws Exception { SqlClientContext cliCtx = sqlClientContext(); GridTestUtils.waitForCondition(() -> cliCtx.isStream() == on, 1000); assertEquals(on, cliCtx.isStream()); }
/** * @throws Exception If failed. */ @Test public void testChanged2() throws Exception { final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 256), WAIT_BUFFER_TIMEOUT)); out.write(BIG); out.reset(); assertEquals(4096, out.internalArray().length); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 4096), WAIT_BUFFER_TIMEOUT)); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 2048), 2 * WAIT_BUFFER_TIMEOUT)); }
private void checkEmpty(final GridCacheAdapter internalCache, final Object key) throws Exception { if (internalCache.isNear()) { checkEmpty(((GridNearCacheAdapter)internalCache).dht(), key); return; } GridTestUtils.waitForCondition(new PA() { @Override public boolean apply() { return internalCache.peekEx(key) == null; } }, 5000); assertNull(internalCache.peekEx(key)); } }
/** * @throws Exception If failed. */ @Test public void testStarvationDetected() throws Exception { final int stripeIdx = 0; stripedExecSvc.execute(stripeIdx, new TestRunnable(true)); sleepASec(); assertFalse(GridTestUtils.waitForCondition(() -> stripedExecSvc.activeStripesCount() == 0, 2000)); stripedExecSvc.execute(stripeIdx, new TestRunnable()); assertTrue(GridTestUtils.waitForCondition(() -> stripedExecSvc.activeStripesCount() == 1, 10000)); assertTrue(stripedExecSvc.detectStarvation()); }