Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -122,7 +123,7 @@ public void testQueueSendReceiveOnTracedThread() throws Exception {
@Test
public void testQueueSendReceiveNoWaitOnTracedThread() throws Exception {
final Queue queue = brokerFacade.createQueue(TEST_Q_NAME);
testQueueSendReceiveOnTracedThread(() -> brokerFacade.receiveNoWait(queue), queue);
testQueueSendReceiveOnTracedThread(() -> loopReceive(() -> brokerFacade.receiveNoWait(queue), 3000), queue);
}

@Test
Expand All @@ -134,7 +135,23 @@ public void testQueueSendReceiveOnNonTracedThread() throws Exception {
@Test
public void testQueueSendReceiveNoWaitOnNonTracedThread() throws Exception {
final Queue queue = brokerFacade.createQueue(TEST_Q_NAME);
testQueueSendReceiveOnNonTracedThread(() -> brokerFacade.receiveNoWait(queue), queue);
testQueueSendReceiveOnNonTracedThread(() -> loopReceive(() -> brokerFacade.receiveNoWait(queue), 3000), queue);
}

// A utility method for testing the receiveNoWait API consistently
private Message loopReceive(Callable<Message> receiveMethod, @SuppressWarnings("SameParameterValue") long timeout) throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using Awaitility

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! But let's merge this now, and consider next time?

long start = System.currentTimeMillis();
long curr = start;
while (curr - start < timeout) {
Message ret = receiveMethod.call();
if (ret != null) {
return ret;
} else {
Thread.sleep(100);
curr = System.currentTimeMillis();
}
}
throw new TimeoutException();
}

private void testQueueSendReceiveOnTracedThread(Callable<Message> receiveMethod, Queue queue) throws Exception {
Expand Down