Search in sources :

Example 31 with RejectedExecutionException

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);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 32 with RejectedExecutionException

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);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 33 with 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);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 34 with 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();
        }
    }
}
Also used : RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 35 with RejectedExecutionException

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");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) TimeUnit(java.util.concurrent.TimeUnit) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)246 ExecutorService (java.util.concurrent.ExecutorService)42 IOException (java.io.IOException)34 Test (org.junit.Test)34 Future (java.util.concurrent.Future)19 ArrayList (java.util.ArrayList)18 Executor (java.util.concurrent.Executor)18 ExecutionException (java.util.concurrent.ExecutionException)15 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)15 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 List (java.util.List)11 TaskRejectedException (org.springframework.core.task.TaskRejectedException)11 BitmapDrawable (android.graphics.drawable.BitmapDrawable)10 Animation (android.view.animation.Animation)10 Map (java.util.Map)10 CancellationException (java.util.concurrent.CancellationException)10 CacheableBitmapDrawable (uk.co.senab.bitmapcache.CacheableBitmapDrawable)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9