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