This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit cf856bfde72883c080c601019ea6d2c071ffb2d7 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Dec 31 10:05:45 2021 +0100 CAMEL-17390: Cannot enable tracing (standby mode) when adding new routes. --- .../camel/impl/engine/AbstractCamelContext.java | 3 +- .../camel/issues/TracingStandbyNoRouteTest.java | 62 ++++++++++++++++ .../apache/camel/issues/TracingStandbyTest.java | 83 ++++++++++++++++++++++ 3 files changed, 147 insertions(+), 1 deletion(-) diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java index df4e243..de9eea0 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java @@ -4578,7 +4578,8 @@ public abstract class AbstractCamelContext extends BaseService @Override public void setTracer(Tracer tracer) { - if (isStartingOrStarted()) { + // if tracing is in standby mode, then we can use it after camel is started + if (!isTracingStandby() && isStartingOrStarted()) { throw new IllegalStateException("Cannot set tracer on a started CamelContext"); } this.tracer = doAddService(tracer, true, false, true); diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/TracingStandbyNoRouteTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/TracingStandbyNoRouteTest.java new file mode 100644 index 0000000..0f65b6f --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/issues/TracingStandbyNoRouteTest.java @@ -0,0 +1,62 @@ +/* + * 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.issues; + +import org.apache.camel.CamelContext; +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.junit.jupiter.api.Test; + +public class TracingStandbyNoRouteTest extends ContextTestSupport { + + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext context = super.createCamelContext(); + context.setTracingStandby(true); + return context; + } + + @Override + public boolean isUseRouteBuilder() { + return false; + } + + @Test + public void testAddRoute() throws Exception { + context.start(); + + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:bye") + .to("mock:bye"); + } + }); + + getMockEndpoint("mock:bye").expectedMessageCount(1); + template.sendBody("direct:bye", "Hello World"); + assertMockEndpointsSatisfied(); + + resetMocks(); + context.getTracer().setEnabled(true); + + getMockEndpoint("mock:bye").expectedMessageCount(1); + template.sendBody("direct:bye", "Hello Tracer"); + assertMockEndpointsSatisfied(); + } + +} diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/TracingStandbyTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/TracingStandbyTest.java new file mode 100644 index 0000000..719133e --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/issues/TracingStandbyTest.java @@ -0,0 +1,83 @@ +/* + * 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.issues; + +import org.apache.camel.CamelContext; +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.junit.jupiter.api.Test; + +public class TracingStandbyTest extends ContextTestSupport { + + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext context = super.createCamelContext(); + context.setTracingStandby(true); + return context; + } + + @Test + public void testEnableTracer() throws Exception { + context.start(); + + getMockEndpoint("mock:result").expectedMessageCount(1); + template.sendBody("direct:start", "Hello World"); + assertMockEndpointsSatisfied(); + + resetMocks(); + context.getTracer().setEnabled(true); + + getMockEndpoint("mock:result").expectedMessageCount(1); + template.sendBody("direct:start", "Hello Tracer"); + assertMockEndpointsSatisfied(); + } + + @Test + public void testAddRoute() throws Exception { + context.start(); + + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:bye") + .to("mock:bye"); + } + }); + + getMockEndpoint("mock:bye").expectedMessageCount(1); + template.sendBody("direct:bye", "Hello World"); + assertMockEndpointsSatisfied(); + + resetMocks(); + context.getTracer().setEnabled(true); + + getMockEndpoint("mock:bye").expectedMessageCount(1); + template.sendBody("direct:bye", "Hello Tracer"); + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("mock:result"); + } + }; + } +}