This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 17bc76b CAMEL-15245: Added unit test 17bc76b is described below commit 17bc76b7265ca912e16bf6e3ffdcf30058c150ce Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Jun 26 09:09:43 2020 +0200 CAMEL-15245: Added unit test --- .../camel/processor/CamelInternalProcessor.java | 3 +- .../apache/camel/impl/StopTimeoutRouteTest.java | 74 ++++++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java b/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java index 1110ca7..4e44342 100644 --- a/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java +++ b/core/camel-base/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java @@ -225,14 +225,13 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor { // force shutdown so we should not continue originalCallback.done(true); return true; - } // optimise to use object array for states, and only for the number of advices that keep state final Object[] states = statefulAdvices > 0 ? new Object[statefulAdvices] : EMPTY_STATES; // optimise for loop using index access to avoid creating iterator object for (int i = 0, j = 0; i < advices.size(); i++) { - CamelInternalProcessorAdvice task = advices.get(i); + CamelInternalProcessorAdvice<?> task = advices.get(i); try { Object state = task.before(exchange); if (task.hasState()) { diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/StopTimeoutRouteTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/StopTimeoutRouteTest.java new file mode 100644 index 0000000..97e4bf9 --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/impl/StopTimeoutRouteTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.impl; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.ServiceStatus; +import org.apache.camel.builder.RouteBuilder; +import org.junit.jupiter.api.Test; + + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class StopTimeoutRouteTest extends ContextTestSupport { + + private CountDownLatch latch = new CountDownLatch(1); + + @Test + public void testStopTimeout() throws Exception { + getMockEndpoint("mock:foo").expectedBodiesReceived("Hello Foo"); + + // should stop the route before its routed to mock:foo + template.asyncSendBody("direct:start", "Hello World"); + context.getRouteController().stopRoute("start", 10, TimeUnit.MILLISECONDS); + + // send to the other running route + template.sendBody("direct:foo", "Hello Foo"); + + assertMockEndpointsSatisfied(); + + latch.countDown(); + + assertEquals(ServiceStatus.Stopped, context.getRouteController().getRouteStatus("start")); + assertEquals(ServiceStatus.Started, context.getRouteController().getRouteStatus("foo")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start").routeId("start") + .process(e -> { + try { + Thread.sleep(500); + } catch (Exception ex) { + // ignore + } + latch.countDown(); + }) + .to("mock:foo"); + + from("direct:foo").routeId("foo").to("mock:foo"); + } + }; + } + +}