Search in sources :

Example 61 with AtomicIntegerArray

use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.

the class Atomic8Test method testIntArrayUpdateAndGet.

/**
 * AtomicIntegerArray updateAndGet updates with supplied function and
 * returns result.
 */
public void testIntArrayUpdateAndGet() {
    AtomicIntegerArray a = new AtomicIntegerArray(1);
    a.set(0, 1);
    assertEquals(18, a.updateAndGet(0, Atomic8Test::addInt17));
    assertEquals(35, a.updateAndGet(0, Atomic8Test::addInt17));
    assertEquals(35, a.get(0));
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 62 with AtomicIntegerArray

use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.

the class Atomic8Test method testIntArrayGetAndUpdate.

/**
 * AtomicIntegerArray getAndUpdate returns previous value and updates
 * result of supplied function
 */
public void testIntArrayGetAndUpdate() {
    AtomicIntegerArray a = new AtomicIntegerArray(1);
    a.set(0, 1);
    assertEquals(1, a.getAndUpdate(0, Atomic8Test::addInt17));
    assertEquals(18, a.getAndUpdate(0, Atomic8Test::addInt17));
    assertEquals(35, a.get(0));
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 63 with AtomicIntegerArray

use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.

the class Atomic8Test method testIntArrayGetAndAccumulate.

/**
 * AtomicIntegerArray getAndAccumulate returns previous value and updates
 * with supplied function.
 */
public void testIntArrayGetAndAccumulate() {
    AtomicIntegerArray a = new AtomicIntegerArray(1);
    a.set(0, 1);
    assertEquals(1, a.getAndAccumulate(0, 2, Integer::sum));
    assertEquals(3, a.getAndAccumulate(0, 3, Integer::sum));
    assertEquals(6, a.get(0));
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 64 with AtomicIntegerArray

use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.

the class AtomicIntegerArrayTest method testGetLazySet.

/**
 * get returns the last value lazySet at index by same thread
 */
public void testGetLazySet() {
    AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.lazySet(i, 1);
        assertEquals(1, aa.get(i));
        aa.lazySet(i, 2);
        assertEquals(2, aa.get(i));
        aa.lazySet(i, -3);
        assertEquals(-3, aa.get(i));
    }
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 65 with AtomicIntegerArray

use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.

the class AtomicIntegerArrayTest method testWeakCompareAndSet.

/**
 * repeated weakCompareAndSet succeeds in changing value when equal
 * to expected
 */
public void testWeakCompareAndSet() {
    AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        do {
        } while (!aa.weakCompareAndSet(i, 1, 2));
        do {
        } while (!aa.weakCompareAndSet(i, 2, -4));
        assertEquals(-4, aa.get(i));
        do {
        } while (!aa.weakCompareAndSet(i, -4, 7));
        assertEquals(7, aa.get(i));
    }
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Aggregations

AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)74 Test (org.junit.Test)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 List (java.util.List)5 AtomicLongArray (java.util.concurrent.atomic.AtomicLongArray)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 ArrayList (java.util.ArrayList)3 Random (java.util.Random)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 CacheException (javax.cache.CacheException)3 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 GridRandom (org.apache.ignite.internal.util.GridRandom)3 CAX (org.apache.ignite.internal.util.typedef.CAX)3 AtomicIntegerArrayAssertBaseTest (org.assertj.core.api.AtomicIntegerArrayAssertBaseTest)3 JSONArray (com.alibaba.fastjson.JSONArray)2