public void testDecrement() throws Exception { AtomicInteger value = new AtomicInteger(7); List<Thread> threads = new ArrayList<>(THREAD_COUNT); for (int threadIndex = 0; threadIndex < THREAD_COUNT; ++threadIndex) { Thread thread = new Thread( () -> { for (int iterationIndex = 0; iterationIndex < ITERATION_COUNT; ++iterationIndex) { AtomicUtil.decrement(value, 9); } }); threads.add(thread); thread.start(); } for (int threadIndex = 0; threadIndex < THREAD_COUNT; ++threadIndex) { threads.get(threadIndex).join(); } assertEquals("AtomicUtil.decrement(AtomicInteger, int) failed.", 7, value.get()); }
public void testInvert() throws Exception { AtomicBoolean value = new AtomicBoolean(); List<Thread> threads = new ArrayList<>(THREAD_COUNT); for (int threadIndex = 0; threadIndex < THREAD_COUNT; ++threadIndex) { Thread thread = new Thread( () -> { for (int iterationIndex = 0; iterationIndex < ITERATION_COUNT; ++iterationIndex) { AtomicUtil.invert(value); } }); threads.add(thread); thread.start(); } for (int threadIndex = 0; threadIndex < THREAD_COUNT; ++threadIndex) { threads.get(threadIndex).join(); } assertEquals("AtomicUtil.invert(AtomicBoolean) failed.", false, value.get()); }