Source:
<code>public void testCompareAndSetConcurrent(Method method) throws ExecutionException, InterruptedException, TimeoutException { final int numThreadsPerNode = 2; final int totalThreads = CLUSTER_SIZE * numThreadsPerNode; final List<Future<LinkedList<Boolean>>> workers = new ArrayList<>(totalThreads); <START> final String counterName = method.getName(); <END> final CyclicBarrier barrier = new CyclicBarrier(totalThreads); final long maxIterations = 100; for (int i = 0; i < totalThreads; ++i) { final int cmIndex = i % numThreadsPerNode; workers.add(fork(() -> { long iteration = 0; final long initialValue = 0; long previousValue = initialValue; LinkedList<Boolean> retValues = new LinkedList<>(); CounterManager manager = counterManager(cmIndex); StrongTestCounter counter = createCounter(manager, counterName, initialValue); while (iteration < maxIterations) { assertEquals(previousValue, counter.getValue()); long update = previousValue + 1; barrier.await(); boolean ret = counter.compareAndSet(previousValue, update); if (ret) { previousValue = update; } else { previousValue = counter.getValue(); } retValues.add(ret); ++iteration; } return retValues; })); } List<LinkedList<Boolean>> workerList = new LinkedList<>(); for (Future<LinkedList<Boolean>> w : workers) { LinkedList<Boolean> returnValues = w.get(1, TimeUnit.MINUTES); workerList.add(returnValues); } for (int i = 0; i != maxIterations; i++) { List<Boolean> headOfWorkers = new LinkedList<>(); for (LinkedList<Boolean> worker: workerList) { headOfWorkers.add(worker.removeFirst()); } assertEquals("Incomplete results in iteration " + i, totalThreads, headOfWorkers.size()); assertEquals("Multiple threads succeeded with update in iteration " + i, 1, headOfWorkers.stream().filter(Boolean::booleanValue).count()); } }</code><technical_language>I number of nodes in cluster originate ISPN-8134</technical_language>

Target:
public void testCompareAndSetConcurrent(Method method) throws ExecutionException, InterruptedException, TimeoutException { final int numThreadsPerNode = 2; final int totalThreads = CLUSTER_SIZE * numThreadsPerNode; final List<Future<Boolean>> workers = new ArrayList<>(totalThreads); final String counterName = method.getName(); final CyclicBarrier barrier = new CyclicBarrier(totalThreads); final AtomicIntegerArray retValues = new AtomicIntegerArray(totalThreads); final long maxIterations = 100; for (int i = 0; i < totalThreads; ++i) { final int threadIndex = i; final int cmIndex = i % CLUSTER_SIZE; workers.add(fork(() -> { long iteration = 0; final long initialValue = 0; long previousValue = initialValue; CounterManager manager = counterManager(cmIndex); StrongTestCounter counter = createCounter(manager, counterName, initialValue); while (iteration < maxIterations) { assertEquals(previousValue, counter.getValue()); long update = previousValue + 1; barrier.await(); boolean ret = counter.compareAndSet(previousValue, update); if (ret) { previousValue = update; } else { previousValue = counter.getValue(); } retValues.set(threadIndex, ret == true ? 1 : 0); barrier.await(); assertUnique(retValues, iteration); ++iteration; } return true; })); } for (Future<?> w : workers) { w.get(1, TimeUnit.MINUTES); } }