use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCacheSequenceApiSelfAbstractTest method testSequenceIntegrity0.
/**
* @throws Exception If failed.
*/
public void testSequenceIntegrity0() throws Exception {
// Random sequence names.
String locSeqName1 = UUID.randomUUID().toString();
String locSeqName2 = UUID.randomUUID().toString();
// Sequence.
IgniteAtomicSequence locSeq1 = grid().atomicSequence(locSeqName1, 0, true);
locSeq1.batchSize(1);
// Sequence.
long initVal = -1500;
IgniteAtomicSequence locSeq2 = grid().atomicSequence(locSeqName2, initVal, true);
locSeq2.batchSize(7);
// Compute sequence value manually and compare with sequence value.
for (int i = 0; i < MAX_LOOPS_NUM; i++) {
integrity(locSeq1, i * 4);
integrity(locSeq2, (i * 4) + initVal);
if (i % 100 == 0)
info("Finished iteration: " + i);
}
removeSequence(locSeqName1);
removeSequence(locSeqName2);
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class IgniteClientDataStructuresAbstractTest method testSequence.
/**
* @param creator Creator node.
* @param other Other node.
* @throws Exception If failed.
*/
private void testSequence(Ignite creator, Ignite other) throws Exception {
assertNull(creator.atomicSequence("seq1", 1L, false));
assertNull(other.atomicSequence("seq1", 1L, false));
try (IgniteAtomicSequence seq = creator.atomicSequence("seq1", 1L, true)) {
assertNotNull(seq);
assertEquals(1L, seq.get());
assertEquals(1L, seq.getAndAdd(1));
assertEquals(2L, seq.get());
IgniteAtomicSequence seq0 = other.atomicSequence("seq1", 1L, false);
assertNotNull(seq0);
}
assertNull(creator.atomicSequence("seq1", 1L, false));
assertNull(other.atomicSequence("seq1", 1L, false));
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCachePartitionedAtomicSequenceMultiThreadedTest method testIncrementAndGetAsync.
/** @throws Exception If failed. */
public void testIncrementAndGetAsync() 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.incrementAndGet();
}
}, seq, ITERATION_NUM, THREAD_NUM);
assertEquals(ITERATION_NUM * THREAD_NUM, seq.get());
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCachePartitionedAtomicSequenceMultiThreadedTest method testMixed2.
/** @throws Exception If failed. */
public void testMixed2() 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.getAndAdd(2);
t.addAndGet(3);
t.addAndGet(5);
t.getAndAdd(7);
}
}, seq, ITERATION_NUM, THREAD_NUM);
assertEquals(17 * ITERATION_NUM * THREAD_NUM, seq.get());
}
use of org.apache.ignite.IgniteAtomicSequence in project ignite by apache.
the class GridCachePartitionedAtomicSequenceMultiThreadedTest method testIncrementAndGet.
/** @throws Exception If failed. */
public void testIncrementAndGet() 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.incrementAndGet();
}
}, seq, ITERATION_NUM, THREAD_NUM);
assertEquals(ITERATION_NUM * THREAD_NUM, seq.get());
}
Aggregations