This is an automated email from the ASF dual-hosted git repository. nfilotto pushed a commit to branch 3876/add-camel-debug-in-dev-mode in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 3e6d92345a15492bb6ec0867965e9be5bbf1008d Author: Nicolas Filotto <[email protected]> AuthorDate: Wed Jul 6 16:58:03 2022 +0200 Testing camel-debug and camel-management in core --- extensions-core/core/deployment/pom.xml | 10 +++++ .../core/deployment/debug/DebugProcessor.java | 39 +++++++++++++++++ .../deployment/management/ManagementProcessor.java | 42 ++++++++++++++++++ .../core/deployment/debug/DebugResource.java | 40 +++++++++++++++++ .../quarkus/core/deployment/debug/DebugTest.java | 51 ++++++++++++++++++++++ extensions-core/core/runtime/pom.xml | 8 ++++ .../quarkus/core/CamelManagementRecorder.java | 38 ++++++++++++++++ 7 files changed, 228 insertions(+) diff --git a/extensions-core/core/deployment/pom.xml b/extensions-core/core/deployment/pom.xml index 765250a7de..ffc35521d3 100644 --- a/extensions-core/core/deployment/pom.xml +++ b/extensions-core/core/deployment/pom.xml @@ -76,6 +76,16 @@ <artifactId>quarkus-junit5-internal</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/debug/DebugProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/debug/DebugProcessor.java new file mode 100644 index 0000000000..769cd8d36c --- /dev/null +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/debug/DebugProcessor.java @@ -0,0 +1,39 @@ +/* + * 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.quarkus.core.deployment.debug; + +import io.quarkus.deployment.IsDevelopment; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.AllowJNDIBuildItem; +import org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination; +import org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem; + +class DebugProcessor { + + @BuildStep(onlyIf = IsDevelopment.class) + AllowJNDIBuildItem allowJNDI() { + return new AllowJNDIBuildItem(); + } + + @BuildStep(onlyIfNot = IsDevelopment.class) + CamelServicePatternBuildItem camelDebuggerFactoryServicePattern() { + // Prevent debugging if not in dev mode. This is added as an exclusion since + // core defines an include path filter for META-INF/services/org/apache/camel/* + return new CamelServicePatternBuildItem(CamelServiceDestination.DISCOVERY, false, + "META-INF/services/org/apache/camel/debugger-factory"); + } +} diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/management/ManagementProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/management/ManagementProcessor.java new file mode 100644 index 0000000000..415069e349 --- /dev/null +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/management/ManagementProcessor.java @@ -0,0 +1,42 @@ +/* + * 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.quarkus.core.deployment.management; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.annotations.ExecutionTime; +import io.quarkus.deployment.annotations.Record; +import io.quarkus.deployment.pkg.steps.NativeBuild; +import org.apache.camel.quarkus.core.CamelManagementRecorder; +import org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination; +import org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem; +import org.apache.camel.quarkus.core.deployment.spi.RuntimeCamelContextCustomizerBuildItem; + +class ManagementProcessor { + + @Record(ExecutionTime.RUNTIME_INIT) + @BuildStep(onlyIfNot = NativeBuild.class) + RuntimeCamelContextCustomizerBuildItem configureCamelContext(CamelManagementRecorder recorder) { + return new RuntimeCamelContextCustomizerBuildItem(recorder.createContextCustomizer()); + } + + @BuildStep(onlyIf = NativeBuild.class) + CamelServicePatternBuildItem managementFactoryServicePattern() { + // Disable JMX in native mode + return new CamelServicePatternBuildItem(CamelServiceDestination.DISCOVERY, false, + "META-INF/services/org/apache/camel/management/*"); + } +} diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/debug/DebugResource.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/debug/DebugResource.java new file mode 100644 index 0000000000..db1e30d253 --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/debug/DebugResource.java @@ -0,0 +1,40 @@ +/* + * 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.quarkus.core.deployment.debug; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.apache.camel.CamelContext; +import org.apache.camel.impl.debugger.BacklogDebugger; + +@Path("/debug") +public class DebugResource { + @Inject + CamelContext context; + + @Path("/enabled") + @GET + @Produces(MediaType.TEXT_PLAIN) + public boolean debuggingEnabled() { + BacklogDebugger debugger = BacklogDebugger.getBacklogDebugger(context); + return debugger != null && debugger.isEnabled(); + } +} diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/debug/DebugTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/debug/DebugTest.java new file mode 100644 index 0000000000..97d4ae4324 --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/debug/DebugTest.java @@ -0,0 +1,51 @@ +/* + * 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.quarkus.core.deployment.debug; + +import java.io.IOException; +import java.net.Socket; + +import io.quarkus.test.QuarkusDevModeTest; +import io.restassured.RestAssured; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.hamcrest.Matchers.is; + +public class DebugTest { + + @RegisterExtension + static final QuarkusDevModeTest TEST = new QuarkusDevModeTest() + .setArchiveProducer(() -> ShrinkWrap + .create(JavaArchive.class) + .addClass(DebugResource.class)); + + @Test + public void camelDebuggingEnabledInDevMode() throws IOException { + RestAssured.get("/debug/enabled") + .then() + .body(is("true")) + .statusCode(200); + + try (Socket socket = new Socket("localhost", 1099)) { + Assertions.assertTrue(socket.isConnected()); + } + } +} diff --git a/extensions-core/core/runtime/pom.xml b/extensions-core/core/runtime/pom.xml index a6e218a0ca..bf3702c574 100644 --- a/extensions-core/core/runtime/pom.xml +++ b/extensions-core/core/runtime/pom.xml @@ -72,6 +72,10 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-core-processor</artifactId> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-debug</artifactId> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-endpointdsl</artifactId> @@ -80,6 +84,10 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-main</artifactId> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-management</artifactId> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-microprofile-config</artifactId> diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelManagementRecorder.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelManagementRecorder.java new file mode 100644 index 0000000000..125e29b569 --- /dev/null +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelManagementRecorder.java @@ -0,0 +1,38 @@ +/* + * 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.quarkus.core; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import org.apache.camel.CamelContext; +import org.apache.camel.spi.CamelContextCustomizer; + +@Recorder +public class CamelManagementRecorder { + + public RuntimeValue<CamelContextCustomizer> createContextCustomizer() { + return new RuntimeValue<>(new CamelManagementCustomizer()); + } + + private static final class CamelManagementCustomizer implements CamelContextCustomizer { + + @Override + public void configure(CamelContext context) { + context.setManagementName(context.getName()); + } + } +}
