use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.
the class IgniteCountDownLatchAbstractSelfTest method checkCountDown.
/**
* @throws Exception Exception.
*/
private void checkCountDown() throws Exception {
IgniteCountDownLatch latch = createLatch("cnt", 10, true);
assert latch.countDown() == 9;
assert latch.countDown(2) == 7;
latch.countDownAll();
assert latch.count() == 0;
checkRemovedLatch(latch);
IgniteCountDownLatch latch1 = createLatch("cnt1", 10, true);
assert latch1.countDown() == 9;
assert latch1.countDown(2) == 7;
latch1.countDownAll();
assert latch1.count() == 0;
checkRemovedLatch(latch1);
}
use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.
the class GridCacheAbstractDataStructuresFailoverSelfTest method doTestCountDownLatch.
/**
* Tests distributed count down latch.
*
* @param topWorker Topology change worker.
* @throws Exception If failed.
*/
private void doTestCountDownLatch(ConstantTopologyChangeWorker topWorker) throws Exception {
try (IgniteCountDownLatch s = grid(0).countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, true)) {
try {
IgniteInternalFuture<?> fut = topWorker.startChangingTopology(new IgniteClosure<Ignite, Object>() {
@Override
public Object apply(Ignite ignite) {
assert ignite.countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, false).count() > 0;
return null;
}
});
int val = s.count();
while (!fut.isDone()) {
assertEquals(val, s.count());
assertEquals(--val, s.countDown());
}
fut.get();
for (Ignite g : G.allGrids()) assertEquals(val, g.countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, true).count());
} finally {
grid(0).countDownLatch(STRUCTURE_NAME, Integer.MAX_VALUE, false, false).countDownAll();
}
}
}
use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.
the class GridCacheAbstractDataStructuresFailoverSelfTest method testCountDownLatchTopologyChange.
/**
* @throws Exception If failed.
*/
public void testCountDownLatchTopologyChange() throws Exception {
try (IgniteCountDownLatch latch = grid(0).countDownLatch(STRUCTURE_NAME, 20, true, true)) {
try {
Ignite g = startGrid(NEW_IGNITE_INSTANCE_NAME);
assertEquals(20, g.countDownLatch(STRUCTURE_NAME, 20, true, false).count());
g.countDownLatch(STRUCTURE_NAME, 20, true, false).countDown(10);
stopGrid(NEW_IGNITE_INSTANCE_NAME);
assertEquals(10, grid(0).countDownLatch(STRUCTURE_NAME, 20, true, false).count());
} finally {
grid(0).countDownLatch(STRUCTURE_NAME, 20, true, false).countDownAll();
}
}
}
use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.
the class IgniteClientReconnectAtomicsTest method testAtomicsReconnectClusterRestart.
/**
* @throws Exception If failed.
*/
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);
}
use of org.apache.ignite.IgniteCountDownLatch in project ignite by apache.
the class IgniteClientReconnectAtomicsTest method testLatchReconnect.
/**
* @throws Exception If failed.
*/
public void testLatchReconnect() throws Exception {
Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = clientRouter(client);
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));
}
Aggregations