Search in sources :

Example 31 with IgniteAtomicSequence

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;
    }
}
Also used : Random(java.util.Random) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence)

Example 32 with IgniteAtomicSequence

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());
}
Also used : IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence)

Example 33 with IgniteAtomicSequence

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());
}
Also used : IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence)

Aggregations

IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)33 Ignite (org.apache.ignite.Ignite)8 IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)3 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 IgniteCountDownLatch (org.apache.ignite.IgniteCountDownLatch)2 IgniteException (org.apache.ignite.IgniteException)2 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 Callable (java.util.concurrent.Callable)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteAtomicReference (org.apache.ignite.IgniteAtomicReference)1 IgniteAtomicStamped (org.apache.ignite.IgniteAtomicStamped)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 IgniteLock (org.apache.ignite.IgniteLock)1