use of org.apache.ignite.IgniteAtomicSequence 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.IgniteAtomicSequence in project ignite by apache.
the class IgniteClientReconnectAtomicsTest method testAtomicSeqReconnectRemoved.
/**
* @throws Exception If failed.
*/
public void testAtomicSeqReconnectRemoved() throws Exception {
Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = clientRouter(client);
final IgniteAtomicSequence clientAtomicSeq = client.atomicSequence("atomicSeqRmv", 0, true);
clientAtomicSeq.batchSize(1);
assertEquals(1L, clientAtomicSeq.incrementAndGet());
final IgniteAtomicSequence srvAtomicSeq = srv.atomicSequence("atomicSeqRmv", 0, false);
srvAtomicSeq.batchSize(1);
assertEquals(1001L, srvAtomicSeq.incrementAndGet());
reconnectClientNode(client, srv, new Runnable() {
@Override
public void run() {
srvAtomicSeq.close();
assert srvAtomicSeq.removed();
}
});
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
for (int i = 0; i < 2000; i++) clientAtomicSeq.incrementAndGet();
return null;
}
}, IllegalStateException.class, null);
IgniteAtomicSequence newClientAtomicSeq = client.atomicSequence("atomicSeqRmv", 0, true);
assertEquals(0, newClientAtomicSeq.get());
assertEquals(1, newClientAtomicSeq.incrementAndGet());
newClientAtomicSeq.close();
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class IgniteClientReconnectAtomicsTest method testAtomicSeqReconnectInProgress.
/**
* @throws Exception If failed.
*/
public void testAtomicSeqReconnectInProgress() throws Exception {
Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = clientRouter(client);
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 GridCachePartitionedAtomicSequenceMultiThreadedTest method testAddAndGet.
/** @throws Exception If failed. */
public void testAddAndGet() throws Exception {
// Random sequence names.
String seqName = UUID.randomUUID().toString();
final IgniteAtomicSequence seq = grid(0).atomicSequence(seqName, 0L, true);
runSequenceClosure(new GridInUnsafeClosure<IgniteAtomicSequence>() {
@Override
public void apply(IgniteAtomicSequence t) {
t.addAndGet(5);
}
}, seq, ITERATION_NUM, THREAD_NUM);
assertEquals(5 * ITERATION_NUM * THREAD_NUM, seq.get());
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCachePartitionedAtomicSequenceTxSelfTest method testIsolation.
/**
* Tests isolation of system and user transactions.
*/
public void testIsolation() {
IgniteAtomicSequence seq = ignite(0).atomicSequence(SEQ_NAME, 0, true);
CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setAtomicityMode(TRANSACTIONAL);
IgniteCache<Object, Object> cache = ignite(0).getOrCreateCache(ccfg);
try (Transaction tx = ignite(0).transactions().txStart()) {
seq.getAndIncrement();
cache.put(1, 1);
tx.rollback();
}
assertEquals(0, cache.size());
assertEquals(new Long(1L), U.field(seq, "locVal"));
assertEquals(new Long(SEQ_CACHE_SIZE - 1), U.field(seq, "upBound"));
}
Aggregations