use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.
the class IgniteCountDownLatchAbstractSelfTest method testLatchBroadcast.
/**
* @throws Exception If failed.
*/
public void testLatchBroadcast() throws Exception {
Ignite ignite = grid(0);
ClusterGroup srvsGrp = ignite.cluster().forServers();
int numOfSrvs = srvsGrp.nodes().size();
ignite.destroyCache("testCache");
IgniteCache<Object, Object> cache = ignite.createCache("testCache");
for (ClusterNode node : srvsGrp.nodes()) cache.put(String.valueOf(node.id()), 0);
for (int i = 0; i < 500; i++) {
IgniteCountDownLatch latch1 = createLatch1(ignite, numOfSrvs);
IgniteCountDownLatch latch2 = createLatch2(ignite, numOfSrvs);
ignite.compute(srvsGrp).broadcast(new IgniteRunnableJob(latch1, latch2, i));
assertTrue(latch2.await(10000));
}
}
use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.
the class IgniteClientDataStructuresAbstractTest method testLatch.
/**
* @param creator Creator node.
* @param other Other node.
* @throws Exception If failed.
*/
private void testLatch(Ignite creator, final Ignite other) throws Exception {
assertNull(creator.countDownLatch("latch1", 1, true, false));
assertNull(other.countDownLatch("latch1", 1, true, false));
try (IgniteCountDownLatch latch = creator.countDownLatch("latch1", 1, true, true)) {
assertNotNull(latch);
assertEquals(1, latch.count());
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
U.sleep(1000);
IgniteCountDownLatch latch0 = other.countDownLatch("latch1", 1, true, false);
assertEquals(1, latch0.count());
log.info("Count down latch.");
latch0.countDown();
assertEquals(0, latch0.count());
return null;
}
});
log.info("Await latch.");
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
log.info("Finished wait.");
fut.get();
}
assertNull(creator.countDownLatch("latch1", 1, true, false));
assertNull(other.countDownLatch("latch1", 1, true, false));
}
use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.
the class IgniteCountDownLatchAbstractSelfTest method testIsolation.
/**
* 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.
*/
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());
}
}
use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.
the class IgniteCountDownLatchAbstractSelfTest method checkAutoDelete.
/**
* @throws Exception Exception.
*/
private void checkAutoDelete() throws Exception {
IgniteCountDownLatch latch = createLatch("rmv", 5, true);
latch.countDownAll();
// Latch should be removed since autoDelete = true
checkRemovedLatch(latch);
IgniteCountDownLatch latch1 = createLatch("rmv1", 5, false);
latch1.countDownAll();
// Latch should NOT be removed since autoDelete = false
assert !latch1.removed();
removeLatch("rmv1");
}
use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.
the class IgniteCountDownLatchAbstractSelfTest method checkLatch.
/**
* @throws Exception If failed.
*/
private void checkLatch() throws Exception {
// Test API.
checkAutoDelete();
checkAwait();
checkCountDown();
// Test main functionality.
IgniteCountDownLatch latch1 = grid(0).countDownLatch("latch", 2, false, true);
assertEquals(2, latch1.count());
IgniteFuture<Object> fut = grid(0).compute().callAsync(new IgniteCallable<Object>() {
@IgniteInstanceResource
private Ignite ignite;
@LoggerResource
private IgniteLogger log;
@Nullable
@Override
public Object call() throws Exception {
// Test latch in multiple threads on each node.
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
IgniteCountDownLatch latch = ignite.countDownLatch("latch", 2, false, true);
assert latch != null && latch.count() == 2;
log.info("Thread is going to wait on latch: " + Thread.currentThread().getName());
assert latch.await(1, MINUTES);
log.info("Thread is again runnable: " + Thread.currentThread().getName());
return null;
}
}, 5, "test-thread");
fut.get();
return null;
}
});
Thread.sleep(3000);
assert latch1.countDown() == 1;
assert latch1.countDown() == 0;
// Ensure there are no hangs.
fut.get();
// Test operations on removed latch.
latch1.close();
checkRemovedLatch(latch1);
}
Aggregations