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.
*/
@SuppressWarnings("IfMayBeConditional")
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 GridCachePartitionedAtomicSequenceMultiThreadedTest method testGetAndIncrementAsync.
/** @throws Exception If failed. */
public void testGetAndIncrementAsync() 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.getAndIncrement();
}
}, 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 testGetAndIncrement.
/** @throws Exception If failed. */
public void testGetAndIncrement() 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.getAndIncrement();
}
}, seq, ITERATION_NUM, THREAD_NUM);
assertEquals(ITERATION_NUM * THREAD_NUM, seq.get());
}
Aggregations