Skip to content

Commit

Permalink
issue#293 : Always need to run CountDownLatch.countDown in finally block
Browse files Browse the repository at this point in the history
The endLatch.countDown was only being run if exceptions were not thrown, which deadlocks tests that fail.

Signed-off-by: Peter Ansell <p_ansell@yahoo.com>
  • Loading branch information
ansell committed Aug 22, 2016
1 parent b6bbac1 commit 214cbff
Showing 1 changed file with 11 additions and 2 deletions.
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -1051,6 +1052,7 @@ public void testMultithreadedAdd()
int numThreads = 3;
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch endLatch = new CountDownLatch(numThreads);
final Set<Throwable> exceptions = ConcurrentHashMap.newKeySet();
for (int i = 0; i < numThreads; i++) {
new Thread(new Runnable() {
public void run() {
Expand All @@ -1062,15 +1064,22 @@ public void run() {
vf.createLiteral(i));
}
}
catch (InterruptedException e) {
catch (Throwable e) {
exceptions.add(e);
throw new AssertionError(e);
}
endLatch.countDown();
finally {
endLatch.countDown();
}
}
}).start();
}
startLatch.countDown();
endLatch.await();
assertEquals(0, exceptions.size());
for(Throwable e : exceptions) {
throw new AssertionError(e);
}
}

protected void assertQueryResult(String literal, IRI predicate, Resource resultUri)
Expand Down

0 comments on commit 214cbff

Please sign in to comment.