Skip to content

Commit 802a741

Browse files
committedDec 26, 2017
Fix Race in DMLC Events test
ConsumeOkEvent introduced a race condition into the test.
1 parent 822593b commit 802a741

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed
 

‎spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainerIntegrationTests.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.amqp.rabbit.listener;
1818

1919
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
20-
import static org.hamcrest.Matchers.instanceOf;
2120
import static org.junit.Assert.assertArrayEquals;
2221
import static org.junit.Assert.assertEquals;
2322
import static org.junit.Assert.assertFalse;
@@ -68,7 +67,6 @@
6867
import org.springframework.amqp.support.converter.MessageConversionException;
6968
import org.springframework.amqp.utils.test.TestUtils;
7069
import org.springframework.context.ApplicationContext;
71-
import org.springframework.context.ApplicationEvent;
7270
import org.springframework.context.event.ContextClosedEvent;
7371
import org.springframework.context.support.GenericApplicationContext;
7472
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@@ -317,15 +315,13 @@ public void testEvents() throws Exception {
317315
container.setQueueNames(EQ1, EQ2);
318316
final List<Long> times = new ArrayList<>();
319317
final CountDownLatch latch1 = new CountDownLatch(2);
320-
final AtomicReference<ApplicationEvent> failEvent = new AtomicReference<>();
321318
final CountDownLatch latch2 = new CountDownLatch(2);
322319
container.setApplicationEventPublisher(event -> {
323320
if (event instanceof ListenerContainerIdleEvent) {
324321
times.add(System.currentTimeMillis());
325322
latch1.countDown();
326323
}
327-
else {
328-
failEvent.set((ApplicationEvent) event);
324+
else if (event instanceof ListenerContainerConsumerTerminatedEvent) {
329325
latch2.countDown();
330326
}
331327
});
@@ -339,8 +335,6 @@ public void testEvents() throws Exception {
339335
assertThat(times.get(1) - times.get(0), greaterThanOrEqualTo(50L));
340336
brokerRunning.deleteQueues(EQ1, EQ2);
341337
assertTrue(latch2.await(10, TimeUnit.SECONDS));
342-
assertNotNull(failEvent.get());
343-
assertThat(failEvent.get(), instanceOf(ListenerContainerConsumerTerminatedEvent.class));
344338
container.stop();
345339
cf.destroy();
346340
}

0 commit comments

Comments
 (0)
Please sign in to comment.