use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class IgniteClientReconnectAtomicsTest method testAtomicSeqReconnectInProgress.
/**
* @throws Exception If failed.
*/
@Test
public void testAtomicSeqReconnectInProgress() throws Exception {
Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = ignite(0);
BlockTcpCommunicationSpi commSpi = commSpi(srv);
final IgniteAtomicSequence clientAtomicSeq = client.atomicSequence("atomicSeqInProg", 0, true);
clientAtomicSeq.batchSize(1);
final IgniteAtomicSequence srvAtomicSeq = srv.atomicSequence("atomicSeqInProg", 0, false);
srvAtomicSeq.batchSize(1);
commSpi.blockMessage(GridNearLockResponse.class);
final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
for (int i = 0; i < 3000; i++) {
try {
clientAtomicSeq.incrementAndGet();
} catch (IgniteClientDisconnectedException e) {
checkAndWait(e);
return true;
}
}
return false;
}
});
// Check that client waiting operation.
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return fut.get(200);
}
}, IgniteFutureTimeoutCheckedException.class, null);
assertNotDone(fut);
commSpi.unblockMessage();
reconnectClientNode(client, srv, null);
assertTrue((Boolean) fut.get(2, TimeUnit.SECONDS));
// Check that after reconnect working.
assert clientAtomicSeq.incrementAndGet() >= 0;
assert srvAtomicSeq.incrementAndGet() >= 0;
clientAtomicSeq.close();
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class IgniteClientReconnectAtomicsTest method testAtomicsReconnectClusterRestart.
/**
* @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;
}
}, IgniteException.class, null);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
atomicRef.compareAndSet(1, 2);
return null;
}
}, IgniteException.class, null);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
atomicLong.incrementAndGet();
return null;
}
}, IgniteException.class, null);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
seq.getAndAdd(1L);
return null;
}
}, IgniteException.class, null);
}
Aggregations