From acc27f4ccd750b072d44d0489da028f370d913d7 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 25 Jan 2013 12:48:00 +0200 Subject: [PATCH] update integration test --- .../support/atomic/RedisAtomicTests.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicTests.java index 5557a9f56..630a8ef01 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicTests.java @@ -18,7 +18,6 @@ package org.springframework.data.redis.support.atomic; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.util.Collection; import java.util.concurrent.CountDownLatch; @@ -121,24 +120,32 @@ public class RedisAtomicTests { // DATAREDIS-108 @Test public void testCompareSet() throws Exception { - final AtomicBoolean flag = new AtomicBoolean(false); - int NUM = 123; + final AtomicBoolean alreadySet = new AtomicBoolean(false); + final int NUM = 50; + final String KEY = getClass().getSimpleName() + ":atomic:counter"; final CountDownLatch latch = new CountDownLatch(NUM); + + final AtomicBoolean failed = new AtomicBoolean(false); for (int i = 0; i < NUM; i++) { new Thread(new Runnable() { public void run() { - RedisAtomicInteger atomicInteger = new RedisAtomicInteger("key", factory); - if (atomicInteger.compareAndSet(0, 1)) { - if (flag.get()) { - fail("counter already modified"); + RedisAtomicInteger atomicInteger = new RedisAtomicInteger(KEY, factory); + try { + if (atomicInteger.compareAndSet(0, 1)) { + System.out.println(atomicInteger.get()); + if (alreadySet.get()) { + failed.set(true); + } + alreadySet.set(true); } - - flag.set(true); + } finally { + latch.countDown(); } - latch.countDown(); } }).start(); } latch.await(); + + assertFalse("counter already modified", failed.get()); } } \ No newline at end of file