use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCachePartitionedAtomicSequenceMultiThreadedTest method checkUpdate.
/**
* @param updated Whether use updated values.
* @throws Exception If failed.
*/
private void checkUpdate(boolean updated) throws Exception {
String seqName = UUID.randomUUID().toString();
final IgniteAtomicSequence seq = grid(0).atomicSequence(seqName, 0L, true);
long curVal = 0;
Random r = new Random();
for (int i = 0; i < ITERATION_NUM; i++) {
long delta = r.nextInt(10) + 1;
long retVal = updated ? seq.addAndGet(delta) : seq.getAndAdd(delta);
assertEquals(updated ? curVal + delta : curVal, retVal);
curVal += delta;
}
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCachePartitionedAtomicSequenceTxSelfTest method testIsolation.
/**
* Tests isolation of system and user transactions.
*/
@Test
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"));
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class IgniteSequenceInternalCleanupTest method testDeactivate.
/**
*/
@Test
public void testDeactivate() throws Exception {
try {
Ignite ignite = startGridsMultiThreaded(GRIDS_CNT);
ignite.cache("test0").put(0, 0);
int id = 0;
for (Ignite ig : G.allGrids()) {
IgniteAtomicSequence seq = ig.atomicSequence("testSeq", 0, true);
long id0 = seq.getAndIncrement();
assertEquals(id0, id);
id += SEQ_RESERVE;
}
doSleep(1000);
long puts = ignite.cache("test0").metrics().getCachePuts();
assertEquals(1, puts);
grid(GRIDS_CNT - 1).cluster().active(false);
ignite.cluster().active(true);
long putsAfter = ignite.cache("test0").metrics().getCachePuts();
assertEquals(0, putsAfter);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class IgnitePersistentStoreDataStructuresTest method testSequence.
/**
* @throws Exception If failed.
*/
@Test
public void testSequence() throws Exception {
Ignite ignite = startGrids(4);
ignite.active(true);
IgniteAtomicSequence sequence = ignite.atomicSequence("testSequence", 0, true);
int i = 0;
while (i < 1000) {
sequence.incrementAndGet();
i++;
}
stopAllGrids();
ignite = startGrids(4);
ignite.active(true);
sequence = ignite.atomicSequence("testSequence", 0, false);
assertTrue(sequence.incrementAndGet() > i);
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class IgniteClientReconnectAtomicsTest method testAtomicSeqReconnectRemoved.
/**
* @throws Exception If failed.
*/
@Test
public void testAtomicSeqReconnectRemoved() throws Exception {
Ignite client = grid(serverCount());
assertTrue(client.cluster().localNode().isClient());
Ignite srv = ignite(0);
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;
}
}, IgniteException.class, null);
IgniteAtomicSequence newClientAtomicSeq = client.atomicSequence("atomicSeqRmv", 0, true);
assertEquals(0, newClientAtomicSeq.get());
assertEquals(1, newClientAtomicSeq.incrementAndGet());
newClientAtomicSeq.close();
}
Aggregations