Search in sources :

Example 31 with AtomicIntegerArray

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

the class AtomicIntegerArrayTest method testGetAndIncrement.

/**
 * getAndIncrement returns previous value and increments
 */
public void testGetAndIncrement() {
    AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        assertEquals(1, aa.getAndIncrement(i));
        assertEquals(2, aa.get(i));
        aa.set(i, -2);
        assertEquals(-2, aa.getAndIncrement(i));
        assertEquals(-1, aa.getAndIncrement(i));
        assertEquals(0, aa.getAndIncrement(i));
        assertEquals(1, aa.get(i));
    }
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 32 with AtomicIntegerArray

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

the class AtomicIntegerArrayTest method testGetAndDecrement.

/**
 * getAndDecrement returns previous value and decrements
 */
public void testGetAndDecrement() {
    AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        assertEquals(1, aa.getAndDecrement(i));
        assertEquals(0, aa.getAndDecrement(i));
        assertEquals(-1, aa.getAndDecrement(i));
    }
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 33 with AtomicIntegerArray

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

the class AtomicIntegerArrayTest method testSerialization.

/**
 * a deserialized serialized array holds same values
 */
public void testSerialization() throws Exception {
    AtomicIntegerArray x = new AtomicIntegerArray(SIZE);
    for (int i = 0; i < SIZE; i++) x.set(i, -i);
    AtomicIntegerArray y = serialClone(x);
    assertNotSame(x, y);
    assertEquals(x.length(), y.length());
    for (int i = 0; i < SIZE; i++) {
        assertEquals(x.get(i), y.get(i));
    }
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 34 with AtomicIntegerArray

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

the class AtomicIntegerArrayTest method testIncrementAndGet.

/**
 * incrementAndGet increments and returns current value
 */
public void testIncrementAndGet() {
    AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        aa.set(i, 1);
        assertEquals(2, aa.incrementAndGet(i));
        assertEquals(2, aa.get(i));
        aa.set(i, -2);
        assertEquals(-1, aa.incrementAndGet(i));
        assertEquals(0, aa.incrementAndGet(i));
        assertEquals(1, aa.incrementAndGet(i));
        assertEquals(1, aa.get(i));
    }
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Example 35 with AtomicIntegerArray

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

the class AtomicIntegerArrayTest method testCountingInMultipleThreads.

/**
 * Multiple threads using same array of counters successfully
 * update a number of times equal to total count
 */
public void testCountingInMultipleThreads() throws InterruptedException {
    final AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
    int countdown = 10000;
    for (int i = 0; i < SIZE; i++) aa.set(i, countdown);
    Counter c1 = new Counter(aa);
    Counter c2 = new Counter(aa);
    Thread t1 = new Thread(c1);
    Thread t2 = new Thread(c2);
    t1.start();
    t2.start();
    t1.join();
    t2.join();
    assertEquals(c1.counts + c2.counts, SIZE * countdown);
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray)

Aggregations

AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)85 Test (org.junit.Test)24 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 Test (org.junit.jupiter.api.Test)11 CountDownLatch (java.util.concurrent.CountDownLatch)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 List (java.util.List)6 AtomicLongArray (java.util.concurrent.atomic.AtomicLongArray)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 JSONArray (com.alibaba.fastjson.JSONArray)3 ArrayList (java.util.ArrayList)3 Random (java.util.Random)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