Search in sources :

Example 11 with IgniteAtomicSequence

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

Example 12 with IgniteAtomicSequence

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

Example 13 with IgniteAtomicSequence

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

Example 14 with IgniteAtomicSequence

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

Example 15 with IgniteAtomicSequence

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());
}
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