use of java.util.concurrent.RejectedExecutionException in project camel by apache.
the class CircuitBreakerLoadBalancerTest method halfOpenToCloseTransition.
private void halfOpenToCloseTransition(String endpoint) throws Exception {
expectsMessageCount(2, result);
result.whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.setException(new MyCustomException());
}
});
Exchange exchangeOne = sendMessage(endpoint, "message one");
Exchange exchangeTwo = sendMessage(endpoint, "message two");
Exchange exchangeThree = sendMessage(endpoint, "message three");
assertMockEndpointsSatisfied();
Thread.sleep(1000);
result.reset();
expectsMessageCount(2, result);
Exchange exchangeFour = sendMessage(endpoint, "message four");
Exchange exchangeFive = sendMessage(endpoint, "message five");
assertMockEndpointsSatisfied();
assertTrue(exchangeOne.getException() instanceof MyCustomException);
assertTrue(exchangeTwo.getException() instanceof MyCustomException);
assertTrue(exchangeThree.getException() instanceof RejectedExecutionException);
assertTrue(exchangeFour.getException() == null);
assertTrue(exchangeFive.getException() == null);
}
use of java.util.concurrent.RejectedExecutionException in project camel by apache.
the class CircuitBreakerLoadBalancerTest method failedMessagesOpenCircuitToPreventMessageThree.
private void failedMessagesOpenCircuitToPreventMessageThree(String endpoint) throws InterruptedException, Exception {
expectsMessageCount(2, result);
result.whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.setException(new MyCustomException());
}
});
Exchange exchangeOne = sendMessage(endpoint, "message one");
Exchange exchangeTwo = sendMessage(endpoint, "message two");
Exchange exchangeThree = sendMessage(endpoint, "message three");
assertMockEndpointsSatisfied();
assertTrue(exchangeOne.getException() instanceof MyCustomException);
assertTrue(exchangeTwo.getException() instanceof MyCustomException);
assertTrue(exchangeThree.getException() instanceof RejectedExecutionException);
}
use of java.util.concurrent.RejectedExecutionException in project camel by apache.
the class CircuitBreakerLoadBalancerTest method halfOpenAfterTimeout.
private void halfOpenAfterTimeout(String endpoint) throws InterruptedException, Exception {
expectsMessageCount(2, result);
result.whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.setException(new MyCustomException());
}
});
Exchange exchangeOne = sendMessage(endpoint, "message one");
Exchange exchangeTwo = sendMessage(endpoint, "message two");
Exchange exchangeThree = sendMessage(endpoint, "message three");
Exchange exchangeFour = sendMessage(endpoint, "message four");
assertMockEndpointsSatisfied();
Thread.sleep(1000);
result.reset();
result.whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.setException(new MyCustomException());
}
});
expectsMessageCount(1, result);
Exchange exchangeFive = sendMessage(endpoint, "message five");
Exchange exchangeSix = sendMessage(endpoint, "message six");
assertMockEndpointsSatisfied();
assertTrue(exchangeOne.getException() instanceof MyCustomException);
assertTrue(exchangeTwo.getException() instanceof MyCustomException);
assertTrue(exchangeThree.getException() instanceof RejectedExecutionException);
assertTrue(exchangeFour.getException() instanceof RejectedExecutionException);
assertTrue(exchangeFive.getException() instanceof MyCustomException);
assertTrue(exchangeSix.getException() instanceof RejectedExecutionException);
}
use of java.util.concurrent.RejectedExecutionException in project camel by apache.
the class DefaultAsyncProcessorAwaitManager method interrupt.
@Override
public void interrupt(Exchange exchange) {
AwaitThreadEntry entry = (AwaitThreadEntry) inflight.get(exchange);
if (entry != null) {
try {
StringBuilder sb = new StringBuilder();
sb.append("Interrupted while waiting for asynchronous callback, will release the following blocked thread which was waiting for exchange to finish processing with exchangeId: ");
sb.append(exchange.getExchangeId());
sb.append("\n");
sb.append(dumpBlockedThread(entry));
// dump a route stack trace of the exchange
String routeStackTrace = MessageHelper.dumpMessageHistoryStacktrace(exchange, exchangeFormatter, false);
if (routeStackTrace != null) {
sb.append(routeStackTrace);
}
LOG.warn(sb.toString());
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
} finally {
if (statistics.isStatisticsEnabled()) {
interruptedCounter.incrementAndGet();
}
exchange.setException(new RejectedExecutionException("Interrupted while waiting for asynchronous callback for exchangeId: " + exchange.getExchangeId()));
entry.getLatch().countDown();
}
}
}
use of java.util.concurrent.RejectedExecutionException in project camel by apache.
the class ManagedThrottlerTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
final ScheduledExecutorService badService = new ScheduledThreadPoolExecutor(1) {
@Override
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
throw new RejectedExecutionException();
}
};
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("log:foo").throttle(10).id("mythrottler").to("mock:result");
from("seda:throttleCount").throttle(1).timePeriodMillis(250).id("mythrottler2").to("mock:end");
from("seda:throttleCountAsync").throttle(1).asyncDelayed().timePeriodMillis(250).id("mythrottler3").to("mock:endAsync");
from("seda:throttleCountAsyncException").throttle(1).asyncDelayed().timePeriodMillis(250).id("mythrottler4").to("mock:endAsyncException").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new RuntimeException("Fail me");
}
});
from("seda:throttleCountRejectExecutionCallerRuns").onException(RejectedExecutionException.class).to("mock:rejectedExceptionEndpoint1").end().throttle(1).timePeriodMillis(250).asyncDelayed().executorService(badService).callerRunsWhenRejected(true).id("mythrottler5").to("mock:endAsyncRejectCallerRuns");
from("seda:throttleCountRejectExecution").onException(RejectedExecutionException.class).to("mock:rejectedExceptionEndpoint1").end().throttle(1).timePeriodMillis(250).asyncDelayed().executorService(badService).callerRunsWhenRejected(false).id("mythrottler6").to("mock:endAsyncReject");
}
};
}
Aggregations