Skip to content

Commit

Permalink
fixed testMapTryPut test. It seems there was a timing issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetmircik committed May 25, 2015
1 parent 4ec927f commit cf40e6a
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions hazelcast/src/test/java/com/hazelcast/map/BasicMapTest.java
Expand Up @@ -678,26 +678,34 @@ public void testMapTryPut() throws InterruptedException {
map.lock(key1);
final AtomicInteger counter = new AtomicInteger(6);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch waitTryPutFailure = new CountDownLatch(1);
Thread thread = new Thread(new Runnable() {
public void run() {
try {
if (map.tryPut(key1, "value1", 100, TimeUnit.MILLISECONDS) == false)
if (map.tryPut(key1, "value1", 100, TimeUnit.MILLISECONDS) == false) {
counter.decrementAndGet();
waitTryPutFailure.countDown();
}

if (map.get(key1) == null)
if (map.get(key1) == null) {
counter.decrementAndGet();
}

if (map.tryPut(key2, "value", 100, TimeUnit.MILLISECONDS))
if (map.tryPut(key2, "value", 100, TimeUnit.MILLISECONDS)) {
counter.decrementAndGet();
}

if (map.get(key2).equals("value"))
if (map.get(key2).equals("value")) {
counter.decrementAndGet();
}

if (map.tryPut(key1, "value1", 5, TimeUnit.SECONDS))
if (map.tryPut(key1, "value1", 5, TimeUnit.SECONDS)) {
counter.decrementAndGet();
}

if (map.get(key1).equals("value1"))
if (map.get(key1).equals("value1")) {
counter.decrementAndGet();
}

latch.countDown();
} catch (Exception e) {
Expand All @@ -706,12 +714,16 @@ public void run() {
}
}
});

thread.start();
Thread.sleep(1000);

assertOpenEventually(waitTryPutFailure);

map.unlock("key1");
latch.await(10, TimeUnit.SECONDS);

assertOpenEventually(latch);
assertEquals(0, counter.get());
thread.join(10000);
assertJoinable(thread);
}

@Test
Expand Down

0 comments on commit cf40e6a

Please sign in to comment.