Skip to content

Commit f61c321

Browse files
committed
fixed a race condition when the method is invoked too quickly and
is never registered as being run, thus making the test wait forever
1 parent 2257940 commit f61c321

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

jms/send-receive/src/test/java/org/javaee7/jms/send/receive/mdb/ReceptionSynchronizer.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ void registerInvocation(Method m) {
5656
synchronized (barrier) {
5757
if (barrier.containsKey(m)) {
5858
latch = barrier.get(m);
59+
} else {
60+
barrier.put(m, new CountDownLatch(0));
5961
}
6062
}
6163
if (latch != null) {
@@ -85,11 +87,6 @@ private static void waitFor(Method method, int timeoutInMillis) throws Interrupt
8587
synchronized (barrier) {
8688
if (barrier.containsKey(method)) {
8789
latch = barrier.get(method);
88-
if (latch.getCount() == 0) {
89-
throw new IllegalStateException("The invocation already happened");
90-
} else {
91-
throw new IllegalStateException("Sorry, I only serve the first one");
92-
}
9390
} else {
9491
latch = new CountDownLatch(1);
9592
barrier.put(method, latch);
@@ -99,5 +96,4 @@ private static void waitFor(Method method, int timeoutInMillis) throws Interrupt
9996
throw new AssertionError("Expected method has not been invoked in " + timeoutInMillis + "ms");
10097
}
10198
}
102-
10399
}

0 commit comments

Comments
 (0)