Java Code Examples for org.apache.ignite.Ignite#countDownLatch()
The following examples show how to use
org.apache.ignite.Ignite#countDownLatch() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridCacheDataStructuresLoadTest.java From ignite with Apache License 2.0 | 5 votes |
@Override public void applyx(Ignite ignite) { IgniteCountDownLatch l = ignite.countDownLatch(TEST_LATCH_NAME, LATCH_INIT_CNT, true, true); for (int i = 0; i < operationsPerTx; i++) { l.countDown(); long cnt = writes.incrementAndGet(); if (cnt % WRITE_LOG_MOD == 0) info("Performed " + cnt + " writes."); } }
Example 2
Source File: GridCacheDataStructuresLoadTest.java From ignite with Apache License 2.0 | 5 votes |
@Override public void applyx(Ignite ignite) { IgniteCountDownLatch l = ignite.countDownLatch(TEST_LATCH_NAME, LATCH_INIT_CNT, true, true); for (int i = 0; i < operationsPerTx; i++) { l.count(); long cnt = reads.incrementAndGet(); if (cnt % READ_LOG_MOD == 0) info("Performed " + cnt + " reads."); } }
Example 3
Source File: IgniteCountDownLatchAbstractSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Implementation of ignite data structures internally uses special system caches, need make sure * that transaction on these system caches do not intersect with transactions started by user. * * @throws Exception If failed. */ @Test public void testIsolation() throws Exception { Ignite ignite = grid(0); CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME); cfg.setName("myCache"); cfg.setAtomicityMode(TRANSACTIONAL); cfg.setWriteSynchronizationMode(FULL_SYNC); IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(cfg); try { IgniteCountDownLatch latch = ignite.countDownLatch("latch1", 10, false, true); assertNotNull(latch); try (Transaction tx = ignite.transactions().txStart()) { cache.put(1, 1); assertEquals(8, latch.countDown(2)); tx.rollback(); } assertEquals(0, cache.size()); assertEquals(7, latch.countDown(1)); } finally { ignite.destroyCache(cfg.getName()); } }
Example 4
Source File: IgniteCountDownLatchAbstractSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param client Ignite client. * @param numOfSrvs Number of server nodes. * @return Ignite latch. */ private IgniteCountDownLatch createLatch1(Ignite client, int numOfSrvs) { return client.countDownLatch( "testName1", // Latch name. numOfSrvs, // Initial count. true, // Auto remove, when counter has reached zero. true // Create if it does not exist. ); }
Example 5
Source File: IgniteCountDownLatchAbstractSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param client Ignite client. * @param numOfSrvs Number of server nodes. * @return Ignite latch. */ private IgniteCountDownLatch createLatch2(Ignite client, int numOfSrvs) { return client.countDownLatch( "testName2", // Latch name. numOfSrvs, // Initial count. true, // Auto remove, when counter has reached zero. true // Create if it does not exist. ); }
Example 6
Source File: IgniteChangeGlobalStateDataStructureTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testDeActivateAndActivateCountDownLatch() throws Exception { final AtomicInteger cnt = new AtomicInteger(); String latchName = "myLatch"; Ignite ig1 = primary(0); Ignite ig2 = primary(1); Ignite ig3 = primary(2); IgniteCountDownLatch latchExp1 = ig1.countDownLatch(latchName, 5, false, true); latchExp1.countDown(); assertEquals(4, latchExp1.count()); assertTrue(ig1.active()); assertTrue(ig2.active()); assertTrue(ig3.active()); ig2.active(false); IgniteEx ex1 = (IgniteEx)ig1; IgniteEx ex2 = (IgniteEx)ig2; IgniteEx ex3 = (IgniteEx)ig3; GridCacheProcessor cache1 = ex1.context().cache(); GridCacheProcessor cache2 = ex2.context().cache(); GridCacheProcessor cache3 = ex3.context().cache(); assertTrue(F.isEmpty(cache1.jcaches())); assertTrue(F.isEmpty(cache2.jcaches())); assertTrue(F.isEmpty(cache3.jcaches())); assertTrue(!ig1.active()); assertTrue(!ig2.active()); assertTrue(!ig3.active()); ig3.active(true); assertTrue(ig1.active()); assertTrue(ig2.active()); assertTrue(ig3.active()); final IgniteCountDownLatch latchAct1 = ig1.countDownLatch(latchName, 0, false, false); final IgniteCountDownLatch latchAct2 = ig2.countDownLatch(latchName, 0, false, false); final IgniteCountDownLatch latchAct3 = ig3.countDownLatch(latchName, 0, false, false); runAsync(new Callable<Void>() { @Override public Void call() throws Exception { latchAct1.await(); cnt.incrementAndGet(); return null; } }); runAsync(new Callable<Void>() { @Override public Void call() throws Exception { latchAct2.await(); cnt.incrementAndGet(); return null; } }); runAsync(new Callable<Void>() { @Override public Void call() throws Exception { latchAct3.await(); cnt.incrementAndGet(); return null; } }); assertEquals(4, latchAct1.count()); assertEquals(4, latchAct2.count()); assertEquals(4, latchAct3.count()); latchAct1.countDown(); latchAct2.countDown(); latchAct3.countDown(); assertEquals(1, latchAct1.count()); assertEquals(1, latchAct2.count()); assertEquals(1, latchAct3.count()); latchAct1.countDown(); U.sleep(3000); assertEquals(3, cnt.get()); }
Example 7
Source File: IgniteClientReconnectAtomicsTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testAtomicsReconnectClusterRestart() throws Exception { Ignite client = grid(serverCount()); assertTrue(client.cluster().localNode().isClient()); final IgniteAtomicLong atomicLong = client.atomicLong("atomicLong", 1L, true); final IgniteAtomicReference<Integer> atomicRef = client.atomicReference("atomicRef", 1, true); final IgniteAtomicStamped<Integer, Integer> atomicStamped = client.atomicStamped("atomicStamped", 1, 1, true); final IgniteCountDownLatch latch = client.countDownLatch("latch", 1, true, true); final IgniteAtomicSequence seq = client.atomicSequence("seq", 1L, true); Ignite srv = grid(0); reconnectServersRestart(log, client, Collections.singleton(srv), new Callable<Collection<Ignite>>() { @Override public Collection<Ignite> call() throws Exception { return Collections.singleton((Ignite)startGrid(0)); } }); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { atomicStamped.compareAndSet(1, 1, 2, 2); return null; } }, IllegalStateException.class, null); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { atomicRef.compareAndSet(1, 2); return null; } }, IllegalStateException.class, null); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { atomicLong.incrementAndGet(); return null; } }, IllegalStateException.class, null); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { seq.getAndAdd(1L); return null; } }, IllegalStateException.class, null); }
Example 8
Source File: IgniteClientReconnectAtomicsTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @throws Exception If failed. */ @Test public void testLatchReconnect() throws Exception { Ignite client = grid(serverCount()); assertTrue(client.cluster().localNode().isClient()); Ignite srv = ignite(0); IgniteCountDownLatch clientLatch = client.countDownLatch("latch1", 3, false, true); assertEquals(3, clientLatch.count()); final IgniteCountDownLatch srvLatch = srv.countDownLatch("latch1", 3, false, false); assertEquals(3, srvLatch.count()); reconnectClientNode(client, srv, new Runnable() { @Override public void run() { srvLatch.countDown(); } }); assertEquals(2, srvLatch.count()); assertEquals(2, clientLatch.count()); srvLatch.countDown(); assertEquals(1, srvLatch.count()); assertEquals(1, clientLatch.count()); clientLatch.countDown(); assertEquals(0, srvLatch.count()); assertEquals(0, clientLatch.count()); assertTrue(srvLatch.await(1000)); assertTrue(clientLatch.await(1000)); }