use of org.mule.runtime.core.privileged.routing.ResponseTimeoutException in project mule by mulesoft.
the class AsyncRequestReplyRequesterTestCase method testSingleEventTimeout.
@Test
public void testSingleEventTimeout() throws Exception {
asyncReplyMP = new TestAsyncRequestReplyRequester(muleContext);
asyncReplyMP.setTimeout(1);
SensingNullMessageProcessor target = getSensingNullMessageProcessor();
target.setWaitTime(30000);
AsyncDelegateMessageProcessor asyncMP = createAsyncMessageProcessor(target);
initialiseIfNeeded(asyncMP, true, muleContext);
asyncMP.start();
asyncReplyMP.setListener(asyncMP);
asyncReplyMP.setReplySource(target.getMessageSource());
asyncReplyMP.setMuleContext(muleContext);
CoreEvent event = eventBuilder(muleContext).message(of(TEST_MESSAGE)).build();
try {
asyncReplyMP.process(event);
fail("ResponseTimeoutException expected");
} catch (Exception e) {
assertThat(e, instanceOf(ResponseTimeoutException.class));
}
}
use of org.mule.runtime.core.privileged.routing.ResponseTimeoutException in project mule by mulesoft.
the class AbstractAsyncRequestReplyRequester method receiveAsyncReply.
private PrivilegedEvent receiveAsyncReply(CoreEvent event) throws MuleException {
String asyncReplyCorrelationId = getAsyncReplyCorrelationId(event);
System.out.println("receiveAsyncReply: " + asyncReplyCorrelationId);
Latch asyncReplyLatch = getLatch(asyncReplyCorrelationId);
// flag for catching the interrupted status of the Thread waiting for a
// result
boolean interruptedWhileWaiting = false;
boolean resultAvailable = false;
PrivilegedEvent result;
try {
if (logger.isDebugEnabled()) {
logger.debug("Waiting for async reply message with id: " + asyncReplyCorrelationId);
}
// how long should we wait for the lock?
if (timeout <= 0) {
asyncReplyLatch.await();
resultAvailable = true;
} else {
resultAvailable = asyncReplyLatch.await(timeout, MILLISECONDS);
}
if (!resultAvailable) {
asyncReplyLatch.await(1000, MILLISECONDS);
resultAvailable = asyncReplyLatch.getCount() == 0;
}
} catch (InterruptedException e) {
interruptedWhileWaiting = true;
} finally {
locks.remove(asyncReplyCorrelationId);
result = responseEvents.remove(asyncReplyCorrelationId);
if (interruptedWhileWaiting) {
Thread.currentThread().interrupt();
return null;
}
}
if (resultAvailable) {
if (result == null) {
// this should never happen, just using it as a safe guard for now
throw new IllegalStateException("Response MuleEvent is null");
}
// Copy event because the async-reply message was received by a different
// receiver thread (or the senders dispatcher thread in case of vm
// with queueEvents="false") and the current thread may need to mutate
// the even. See MULE-4370
setCurrentEvent(result);
return result;
} else {
addProcessed(new ProcessedEvents(asyncReplyCorrelationId, EndReason.FINISHED_BY_TIMEOUT));
if (failOnTimeout) {
notificationFirer.dispatch(new RoutingNotification(event.getMessage(), null, ASYNC_REPLY_TIMEOUT));
throw new ResponseTimeoutException(responseTimedOutWaitingForId((int) timeout, asyncReplyCorrelationId), null);
} else {
return null;
}
}
}
Aggregations