Search in sources :

Example 6 with IgniteAtomicLong

use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.

the class IgniteAtomicLongChangingTopologySelfTest method testIncrementConsistency.

/**
     * @throws Exception If failed.
     */
public void testIncrementConsistency() throws Exception {
    startGrids(GRID_CNT);
    final AtomicBoolean run = new AtomicBoolean(true);
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        /** {@inheritDoc} */
        @Override
        public Void call() throws Exception {
            IgniteAtomicLong cntr = ignite(0).atomicLong(ATOMIC_LONG_NAME, 0, true);
            while (run.get()) queue.add(cntr.getAndIncrement());
            return null;
        }
    }, 4, "increment-runner");
    for (int i = 0; i < RESTART_CNT; i++) {
        int restartIdx = ThreadLocalRandom.current().nextInt(GRID_CNT - 1) + 1;
        stopGrid(restartIdx);
        U.sleep(500);
        startGrid(restartIdx);
    }
    run.set(false);
    fut.get();
    info("Increments: " + queue.size());
    checkQueue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException)

Example 7 with IgniteAtomicLong

use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.

the class IgniteAtomicLongApiAbstractSelfTest method testCreateRemove.

/**
     * @throws Exception If failed.
     */
public void testCreateRemove() throws Exception {
    info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
    Ignite ignite = grid(0);
    String atomicName1 = "FIRST";
    String atomicName2 = "SECOND";
    IgniteAtomicLong atomic1 = ignite.atomicLong(atomicName1, 0, true);
    IgniteAtomicLong atomic2 = ignite.atomicLong(atomicName2, 0, true);
    IgniteAtomicLong atomic3 = ignite.atomicLong(atomicName1, 0, true);
    assertNotNull(atomic1);
    assertNotNull(atomic2);
    assertNotNull(atomic3);
    assert atomic1.equals(atomic3);
    assert atomic3.equals(atomic1);
    assert !atomic3.equals(atomic2);
    atomic1.close();
    atomic2.close();
    atomic3.close();
    assertNull(ignite.atomicLong(atomicName1, 0, false));
    assertNull(ignite.atomicLong(atomicName2, 0, false));
    try {
        atomic1.get();
        fail();
    } catch (IllegalStateException | IgniteException e) {
        info("Caught expected exception: " + e.getMessage());
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) Ignite(org.apache.ignite.Ignite)

Example 8 with IgniteAtomicLong

use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.

the class IgniteAtomicLongApiAbstractSelfTest method testGetAndSet.

/**
     * @throws Exception If failed.
     */
public void testGetAndSet() throws Exception {
    info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
    Ignite ignite = grid(0);
    IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
    long newVal = RND.nextLong();
    long curAtomicVal = atomic.get();
    assert curAtomicVal == atomic.getAndSet(newVal);
    assert newVal == atomic.get();
}
Also used : IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) Ignite(org.apache.ignite.Ignite)

Example 9 with IgniteAtomicLong

use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.

the class IgniteAtomicLongApiAbstractSelfTest method testIsolation.

/**
     * Implementation of ignite data structures internally uses special system caches, need make sure that
     * transaction on these system caches do not intersect with transactions started by user.
     *
     * @throws Exception If failed.
     */
public void testIsolation() throws Exception {
    Ignite ignite = grid(0);
    IgniteCache<Object, Object> cache = ignite.cache(TRANSACTIONAL_CACHE_NAME);
    IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
    long curAtomicVal = atomic.get();
    try (Transaction tx = ignite.transactions().txStart()) {
        atomic.getAndIncrement();
        cache.put(1, 1);
        tx.rollback();
    }
    assertEquals(0, cache.size());
    assertEquals(curAtomicVal + 1, atomic.get());
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) Ignite(org.apache.ignite.Ignite)

Example 10 with IgniteAtomicLong

use of org.apache.ignite.IgniteAtomicLong in project ignite by apache.

the class IgniteAtomicLongApiAbstractSelfTest method testGetAndAdd.

/**
     * @throws Exception If failed.
     */
public void testGetAndAdd() throws Exception {
    info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
    Ignite ignite = grid(0);
    IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
    long delta = RND.nextLong();
    long curAtomicVal = atomic.get();
    assert curAtomicVal == atomic.getAndAdd(delta);
    assert curAtomicVal + delta == atomic.get();
}
Also used : IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) Ignite(org.apache.ignite.Ignite)

Aggregations

IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)31 Ignite (org.apache.ignite.Ignite)23 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)6 IgniteException (org.apache.ignite.IgniteException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 IgniteAtomicSequence (org.apache.ignite.IgniteAtomicSequence)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 EntryProcessorException (javax.cache.processor.EntryProcessorException)2 IgniteCountDownLatch (org.apache.ignite.IgniteCountDownLatch)2 IgniteQueue (org.apache.ignite.IgniteQueue)2 IgniteSet (org.apache.ignite.IgniteSet)2 Transaction (org.apache.ignite.transactions.Transaction)2 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 Callable (java.util.concurrent.Callable)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1