use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.
the class AtomicIntegerArrayTest method testCompareAndSet.
/**
* compareAndSet succeeds in changing value if equal to expected else fails
*/
public void testCompareAndSet() {
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
for (int i = 0; i < SIZE; i++) {
aa.set(i, 1);
assertTrue(aa.compareAndSet(i, 1, 2));
assertTrue(aa.compareAndSet(i, 2, -4));
assertEquals(-4, aa.get(i));
assertFalse(aa.compareAndSet(i, -5, 7));
assertEquals(-4, aa.get(i));
assertTrue(aa.compareAndSet(i, -4, 7));
assertEquals(7, aa.get(i));
}
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.
the class AtomicIntegerArrayTest method testToString.
/**
* toString returns current value.
*/
public void testToString() {
int[] a = { 17, 3, -42, 99, -7 };
AtomicIntegerArray aa = new AtomicIntegerArray(a);
assertEquals(Arrays.toString(a), aa.toString());
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.
the class AtomicIntegerArrayTest method testConstructor2.
/**
* constructor with array is of same size and has all elements
*/
public void testConstructor2() {
int[] a = { 17, 3, -42, 99, -7 };
AtomicIntegerArray aa = new AtomicIntegerArray(a);
assertEquals(a.length, aa.length());
for (int i = 0; i < a.length; i++) assertEquals(a[i], aa.get(i));
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project j2objc by google.
the class Atomic8Test method testIntArrayAccumulateAndGet.
/**
* AtomicIntegerArray accumulateAndGet updates with supplied function and
* returns result.
*/
public void testIntArrayAccumulateAndGet() {
AtomicIntegerArray a = new AtomicIntegerArray(1);
a.set(0, 1);
assertEquals(7, a.accumulateAndGet(0, 6, Integer::sum));
assertEquals(10, a.accumulateAndGet(0, 3, Integer::sum));
}
use of java.util.concurrent.atomic.AtomicIntegerArray in project elasticsearch by elastic.
the class IndexActionIT method testCreatedFlagParallelExecution.
public void testCreatedFlagParallelExecution() throws Exception {
createIndex("test");
ensureGreen();
int threadCount = 20;
final int docCount = 300;
int taskCount = docCount * threadCount;
final AtomicIntegerArray createdCounts = new AtomicIntegerArray(docCount);
ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
List<Callable<Void>> tasks = new ArrayList<>(taskCount);
final Random random = random();
for (int i = 0; i < taskCount; i++) {
tasks.add(new Callable<Void>() {
@Override
public Void call() throws Exception {
int docId = random.nextInt(docCount);
IndexResponse indexResponse = index("test", "type", Integer.toString(docId), "field1", "value");
if (indexResponse.getResult() == DocWriteResponse.Result.CREATED) {
createdCounts.incrementAndGet(docId);
}
return null;
}
});
}
threadPool.invokeAll(tasks);
for (int i = 0; i < docCount; i++) {
assertThat(createdCounts.get(i), lessThanOrEqualTo(1));
}
terminate(threadPool);
}
Aggregations