diff --git a/docs/modules/ROOT/pages/reference/extensions/core.adoc b/docs/modules/ROOT/pages/reference/extensions/core.adoc index 5c575df74680..3a0c5aafff8a 100644 --- a/docs/modules/ROOT/pages/reference/extensions/core.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/core.adoc @@ -239,6 +239,14 @@ What to do if it is not possible to extract CSimple expressions from a route def | `org.apache.camel.quarkus.core.CamelConfig.FailureRemedy` | `warn` +|icon:lock[title=Fixed at build time] [[quarkus.camel.event-bridge.enabled]]`link:#quarkus.camel.event-bridge.enabled[quarkus.camel.event-bridge.enabled]` + +Whether to enable the bridging of Camel events to CDI events. + This allows CDI observers to be configured for Camel events. E.g. those belonging to the `org.apache.camel.quarkus.core.events`, `org.apache.camel.quarkus.main.events` & `org.apache.camel.impl.event` packages. + Note that this configuration item only has any effect when observers configured for Camel events are present in the application. +| `boolean` +| `true` + |icon:lock[title=Fixed at build time] [[quarkus.camel.main.enabled]]`link:#quarkus.camel.main.enabled[quarkus.camel.main.enabled]` If `true` all `camel-main` features are enabled; otherwise no `camel-main` features are enabled. See described the xref:user-guide/configuration.adoc[Configuration] section of Camel Quarkus documentation for more details. diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelContextProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelContextProcessor.java index e5b3addb7144..73aa22989d85 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelContextProcessor.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelContextProcessor.java @@ -16,9 +16,14 @@ */ package org.apache.camel.quarkus.core.deployment; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.function.BooleanSupplier; +import java.util.stream.Collectors; import io.quarkus.arc.deployment.BeanContainerBuildItem; +import io.quarkus.arc.deployment.BeanDiscoveryFinishedBuildItem; import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.Consume; @@ -163,4 +168,54 @@ public CamelRuntimeBuildItem runtime( recorder.createRuntime(beanContainer.getValue(), context.getCamelContext()), config.bootstrap.enabled); } + + /** + * Registers Camel CDI event bridges if quarkus.camel.event-bridge.enabled=true and if + * the relevant events have CDI observers configured for them. + * + * @param beanDiscovery build item containing the results of bean discovery + * @param context build item containing the CamelContext instance + * @param recorder the CamelContext recorder instance + */ + @Record(ExecutionTime.STATIC_INIT) + @BuildStep(onlyIf = EventBridgeEnabled.class) + public void registerCamelEventBridges( + BeanDiscoveryFinishedBuildItem beanDiscovery, + CamelContextBuildItem context, + CamelContextRecorder recorder) { + + Set observedLifecycleEvents = beanDiscovery.getObservers() + .stream() + .map(observerInfo -> observerInfo.getObservedType().name().toString()) + .filter(observedType -> observedType.startsWith("org.apache.camel.quarkus.core.events")) + .collect(Collectors.collectingAndThen(Collectors.toUnmodifiableSet(), HashSet::new)); + + // For management events the event class simple name is collected as users can + // observe events on either the Camel event interface or the concrete event class, and + // these are located in different packages + Set observedManagementEvents = beanDiscovery.getObservers() + .stream() + .map(observerInfo -> observerInfo.getObservedType().name().toString()) + .filter(className -> className.matches("org.apache.camel(?!.quarkus).*Event$")) + .map(className -> CamelSupport.loadClass(className, Thread.currentThread().getContextClassLoader())) + .map(observedEventClass -> observedEventClass.getSimpleName()) + .collect(Collectors.collectingAndThen(Collectors.toUnmodifiableSet(), HashSet::new)); + + if (!observedLifecycleEvents.isEmpty()) { + recorder.registerLifecycleEventBridge(context.getCamelContext(), observedLifecycleEvents); + } + + if (!observedManagementEvents.isEmpty()) { + recorder.registerManagementEventBridge(context.getCamelContext(), observedManagementEvents); + } + } + + public static final class EventBridgeEnabled implements BooleanSupplier { + CamelConfig config; + + @Override + public boolean getAsBoolean() { + return config.eventBridge.enabled; + } + } } diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/main/CamelMainProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/main/CamelMainProcessor.java index 5acba9e89210..07dae03fd8f0 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/main/CamelMainProcessor.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/main/CamelMainProcessor.java @@ -16,11 +16,14 @@ */ package org.apache.camel.quarkus.core.deployment.main; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import io.quarkus.arc.deployment.AdditionalBeanBuildItem; import io.quarkus.arc.deployment.BeanContainerBuildItem; +import io.quarkus.arc.deployment.BeanDiscoveryFinishedBuildItem; import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; @@ -36,6 +39,7 @@ import org.apache.camel.quarkus.core.CamelConfig; import org.apache.camel.quarkus.core.CamelRecorder; import org.apache.camel.quarkus.core.CamelRuntime; +import org.apache.camel.quarkus.core.deployment.CamelContextProcessor.EventBridgeEnabled; import org.apache.camel.quarkus.core.deployment.main.spi.CamelMainBuildItem; import org.apache.camel.quarkus.core.deployment.main.spi.CamelMainEnabled; import org.apache.camel.quarkus.core.deployment.main.spi.CamelMainListenerBuildItem; @@ -191,6 +195,32 @@ CamelRuntimeBuildItem runtime( index.getIndex().getAnnotations(DotName.createSimple(QuarkusMain.class.getName())).isEmpty()); } + /** + * Registers Camel Main CDI event bridges if quarkus.camel.event-bridge.enabled=true and if + * the relevant events have CDI observers configured for them. + * + * @param beanDiscovery build item containing the results of bean discovery + * @param main build item containing the CamelMain instance + * @param recorder the CamelContext recorder instance + */ + @Record(ExecutionTime.STATIC_INIT) + @BuildStep(onlyIf = { CamelMainEnabled.class, EventBridgeEnabled.class }) + public void registerCamelMainEventBridge( + BeanDiscoveryFinishedBuildItem beanDiscovery, + CamelMainBuildItem main, + CamelMainRecorder recorder) { + + Set observedMainEvents = beanDiscovery.getObservers() + .stream() + .map(observerInfo -> observerInfo.getObservedType().name().toString()) + .filter(observedType -> observedType.startsWith("org.apache.camel.quarkus.main.events")) + .collect(Collectors.collectingAndThen(Collectors.toUnmodifiableSet(), HashSet::new)); + + if (!observedMainEvents.isEmpty()) { + recorder.registerCamelMainEventBridge(main.getInstance(), observedMainEvents); + } + } + @BuildStep(onlyIf = CamelMainEnabled.class) AdditionalIndexedClassesBuildItem indexCamelMainApplication() { // Required for launching CamelMain based applications from the IDE diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainEventBridgeDisabledConfigTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainEventBridgeDisabledConfigTest.java new file mode 100644 index 000000000000..032396ef557b --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainEventBridgeDisabledConfigTest.java @@ -0,0 +1,119 @@ +/* + * 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.main; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.ModelCamelContext; +import org.apache.camel.quarkus.main.CamelMain; +import org.apache.camel.quarkus.main.CamelMainEventBridge; +import org.apache.camel.quarkus.main.events.AfterConfigure; +import org.apache.camel.quarkus.main.events.AfterStart; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.Asset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CamelMainEventBridgeDisabledConfigTest { + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addAsResource(applicationProperties(), "application.properties")); + + @Inject + CamelMain main; + + @Inject + EventHandler handler; + + @Test + public void testObservers() { + assertFalse(main.getMainListeners().stream().anyMatch(mainListener -> mainListener + .getClass() + .equals(CamelMainEventBridge.class))); + assertTrue(handler.builders().isEmpty()); + assertTrue(handler.routes().isEmpty()); + } + + public static Asset applicationProperties() { + Writer writer = new StringWriter(); + + Properties props = new Properties(); + props.setProperty("quarkus.banner.enabled", "false"); + props.setProperty("quarkus.camel.event-bridge.enabled", "false"); + + try { + props.store(writer, ""); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return new StringAsset(writer.toString()); + } + + @ApplicationScoped + public static class EventHandler { + private final Set builders = new CopyOnWriteArraySet<>(); + private final Set routes = new CopyOnWriteArraySet<>(); + + public void afterConfigure(@Observes AfterConfigure event) { + event.getMain().configure().getRoutesBuilders().forEach( + builder -> builders.add(builder.getClass().getName())); + } + + public void afterStart(@Observes AfterStart event) { + event.getCamelContext(ModelCamelContext.class).getRoutes().forEach( + route -> routes.add(route.getRouteId())); + } + + public Set builders() { + return builders; + } + + public Set routes() { + return routes; + } + } + + public static class MyRoutes extends RouteBuilder { + public static String ROUTE_ID = "myRoute"; + public static String FROM_ENDPOINT = "direct://start"; + + @Override + public void configure() throws Exception { + from(FROM_ENDPOINT) + .routeId(ROUTE_ID) + .log("${body}"); + } + } +} diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainEventBridgeDisabledTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainEventBridgeDisabledTest.java new file mode 100644 index 000000000000..2d63674d9a4d --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/deployment/main/CamelMainEventBridgeDisabledTest.java @@ -0,0 +1,59 @@ +/* + * 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.main; + +import javax.inject.Inject; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.quarkus.main.CamelMain; +import org.apache.camel.quarkus.main.CamelMainEventBridge; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class CamelMainEventBridgeDisabledTest { + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Inject + CamelMain main; + + @Test + public void camelMainEventBridgeNotConfigured() { + // Since no CDI observers for main events are configured the event bridge should not be present + assertFalse(main.getMainListeners().stream().anyMatch(mainListener -> mainListener + .getClass() + .equals(CamelMainEventBridge.class))); + } + + public static class MyRoutes extends RouteBuilder { + public static String ROUTE_ID = "myRoute"; + public static String FROM_ENDPOINT = "direct://start"; + + @Override + public void configure() throws Exception { + from(FROM_ENDPOINT) + .routeId(ROUTE_ID) + .log("${body}"); + } + } +} diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelEventBridgeDisabledConfigTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelEventBridgeDisabledConfigTest.java new file mode 100644 index 000000000000..2ca706b6d5b3 --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelEventBridgeDisabledConfigTest.java @@ -0,0 +1,116 @@ +/* + * 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.runtime; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.CamelContext; +import org.apache.camel.impl.event.RouteAddedEvent; +import org.apache.camel.quarkus.core.CamelLifecycleEventBridge; +import org.apache.camel.quarkus.core.events.ServiceAddEvent; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.Asset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.apache.camel.spi.CamelEvent.*; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CamelEventBridgeDisabledConfigTest { + + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addAsResource(applicationProperties(), "application.properties")); + + @Inject + CamelContext context; + + @Inject + EventHandler handler; + + @Test + public void camelManagementEventBridgeNotConfigured() { + assertFalse(context.getLifecycleStrategies() + .stream() + .anyMatch(lifecycleStrategy -> lifecycleStrategy.getClass().equals(CamelLifecycleEventBridge.class))); + assertTrue(context.getManagementStrategy().getEventNotifiers().isEmpty()); + assertTrue(handler.getServices().isEmpty()); + assertTrue(handler.getRoutesAdded().isEmpty()); + assertTrue(handler.getRoutesRemoved().isEmpty()); + } + + public static Asset applicationProperties() { + Writer writer = new StringWriter(); + + Properties props = new Properties(); + props.setProperty("quarkus.banner.enabled", "false"); + props.setProperty("quarkus.camel.event-bridge.enabled", "false"); + + try { + props.store(writer, ""); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return new StringAsset(writer.toString()); + } + + @ApplicationScoped + static final class EventHandler { + private final Set services = new CopyOnWriteArraySet<>(); + private final Set routesAdded = new CopyOnWriteArraySet<>(); + private final Set routesRemoved = new CopyOnWriteArraySet<>(); + + public void onServiceAdd(@Observes ServiceAddEvent event) { + services.add(event); + } + + public void onRouteAdd(@Observes RouteAddedEvent event) { + routesAdded.add(event); + } + + public void onRouteRemoved(@Observes RouteRemovedEvent event) { + routesRemoved.add(event); + } + + public Set getServices() { + return services; + } + + public Set getRoutesAdded() { + return routesAdded; + } + + public Set getRoutesRemoved() { + return routesRemoved; + } + } +} diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelEventBridgeDisabledTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelEventBridgeDisabledTest.java new file mode 100644 index 000000000000..86b813869713 --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelEventBridgeDisabledTest.java @@ -0,0 +1,72 @@ +/* + * 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.runtime; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Properties; + +import javax.inject.Inject; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.CamelContext; +import org.apache.camel.quarkus.core.CamelLifecycleEventBridge; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.Asset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CamelEventBridgeDisabledTest { + + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addAsResource(applicationProperties(), "application.properties")); + + @Inject + CamelContext context; + + @Test + public void camelEventBridgeNotConfigured() { + // No CDI observers for camel events are configured so event bridging support should not be present + assertFalse(context.getLifecycleStrategies() + .stream() + .anyMatch(lifecycleStrategy -> lifecycleStrategy.getClass().equals(CamelLifecycleEventBridge.class))); + assertTrue(context.getManagementStrategy().getEventNotifiers().isEmpty()); + } + + public static Asset applicationProperties() { + Writer writer = new StringWriter(); + + Properties props = new Properties(); + props.setProperty("quarkus.banner.enabled", "false"); + + try { + props.store(writer, ""); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return new StringAsset(writer.toString()); + } +} diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelEventBridgeTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelEventBridgeTest.java new file mode 100644 index 000000000000..138f631b8dfe --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelEventBridgeTest.java @@ -0,0 +1,128 @@ +/* + * 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.runtime; + +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.TimeUnit; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.direct.DirectComponent; +import org.apache.camel.impl.event.RouteStartedEvent; +import org.apache.camel.quarkus.core.events.ComponentAddEvent; +import org.apache.camel.quarkus.core.events.EndpointAddEvent; +import org.apache.camel.quarkus.core.events.ServiceAddEvent; +import org.apache.camel.spi.CamelEvent; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + +public class CamelEventBridgeTest { + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Inject + EventHandler handler; + + @Test + public void testObservers() { + await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> { + assertThat(handler.routesAdded()) + .contains(MyRoutes.ROUTE_ID); + assertThat(handler.routesStarted()) + .contains(MyRoutes.ROUTE_ID); + assertThat(handler.components()) + .contains(DirectComponent.class.getName()); + assertThat(handler.endpoints()) + .contains(MyRoutes.FROM_ENDPOINT); + assertThat(handler.service()) + .isNotEmpty(); + }); + } + + @ApplicationScoped + public static class EventHandler { + private final Set routesAdded = new CopyOnWriteArraySet<>(); + private final Set routesStarted = new CopyOnWriteArraySet<>(); + private final Set endpoints = new CopyOnWriteArraySet<>(); + private final Set components = new CopyOnWriteArraySet<>(); + private final Set service = new CopyOnWriteArraySet<>(); + + public void onRouteAdded(@Observes CamelEvent.RouteAddedEvent event) { + routesAdded.add(event.getRoute().getRouteId()); + } + + public void onRouteStarted(@Observes RouteStartedEvent event) { + routesStarted.add(event.getRoute().getRouteId()); + } + + public void onComponentAdd(@Observes ComponentAddEvent event) { + components.add(event.getComponent().getClass().getName()); + } + + public void onEndpointAdd(@Observes EndpointAddEvent event) { + endpoints.add(event.getEndpoint().getEndpointUri()); + } + + public void onServiceAdd(@Observes ServiceAddEvent event) { + service.add(event.getService().getClass().getName()); + } + + public Set routesAdded() { + return routesAdded; + } + + public Set routesStarted() { + return routesStarted; + } + + public Set components() { + return components; + } + + public Set endpoints() { + return endpoints; + } + + public Set service() { + return service; + } + } + + @ApplicationScoped + public static class MyRoutes extends RouteBuilder { + public static String ROUTE_ID = "myRoute"; + public static String FROM_ENDPOINT = "direct://start"; + + @Override + public void configure() throws Exception { + from(FROM_ENDPOINT) + .routeId(ROUTE_ID) + .log("${body}"); + } + } +} diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelObserversTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelLifecycleEventBridgeTest.java similarity index 88% rename from extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelObserversTest.java rename to extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelLifecycleEventBridgeTest.java index 12a301acefd9..847943908483 100644 --- a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelObserversTest.java +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelLifecycleEventBridgeTest.java @@ -25,9 +25,9 @@ import javax.inject.Inject; import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.direct.DirectComponent; -import org.apache.camel.impl.event.RouteStartedEvent; import org.apache.camel.quarkus.core.events.ComponentAddEvent; import org.apache.camel.quarkus.core.events.EndpointAddEvent; import org.apache.camel.quarkus.core.events.ServiceAddEvent; @@ -38,8 +38,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class CamelObserversTest { +public class CamelLifecycleEventBridgeTest { @RegisterExtension static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); @@ -47,11 +48,15 @@ public class CamelObserversTest { @Inject EventHandler handler; + @Inject + CamelContext context; + @Test public void testObservers() { + // We're only observing lifecycle events so the management strategy should not be configured + assertTrue(context.getManagementStrategy().getEventNotifiers().isEmpty()); + await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> { - assertThat(handler.routes()) - .contains(MyRoutes.ROUTE_ID); assertThat(handler.components()) .contains(DirectComponent.class.getName()); assertThat(handler.endpoints()) @@ -63,15 +68,10 @@ public void testObservers() { @ApplicationScoped public static class EventHandler { - private final Set routes = new CopyOnWriteArraySet<>(); private final Set endpoints = new CopyOnWriteArraySet<>(); private final Set components = new CopyOnWriteArraySet<>(); private final Set service = new CopyOnWriteArraySet<>(); - public void onRouteStarted(@Observes RouteStartedEvent event) { - routes.add(event.getRoute().getRouteId()); - } - public void onComponentAdd(@Observes ComponentAddEvent event) { components.add(event.getComponent().getClass().getName()); } @@ -84,10 +84,6 @@ public void onServiceAdd(@Observes ServiceAddEvent event) { service.add(event.getService().getClass().getName()); } - public Set routes() { - return routes; - } - public Set components() { return components; } diff --git a/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelManagementEventBridgeTest.java b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelManagementEventBridgeTest.java new file mode 100644 index 000000000000..50b0530966ed --- /dev/null +++ b/extensions-core/core/deployment/src/test/java/org/apache/camel/quarkus/core/runtime/CamelManagementEventBridgeTest.java @@ -0,0 +1,102 @@ +/* + * 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.runtime; + +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.TimeUnit; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; + +import io.quarkus.test.QuarkusUnitTest; +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.event.RouteStartedEvent; +import org.apache.camel.quarkus.core.CamelLifecycleEventBridge; +import org.apache.camel.spi.CamelEvent.RouteAddedEvent; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class CamelManagementEventBridgeTest { + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Inject + EventHandler handler; + + @Inject + CamelContext context; + + @Test + public void testObservers() { + // We're only observing management events so the lifecycle strategy should not be configured + assertFalse(context.getLifecycleStrategies() + .stream() + .anyMatch(lifecycleStrategy -> lifecycleStrategy.getClass().equals(CamelLifecycleEventBridge.class))); + + await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> { + assertThat(handler.routesAdded()) + .contains(MyRoutes.ROUTE_ID); + assertThat(handler.routesStarted()) + .contains(MyRoutes.ROUTE_ID); + }); + } + + @ApplicationScoped + public static class EventHandler { + private final Set routesAdded = new CopyOnWriteArraySet<>(); + private final Set routesStarted = new CopyOnWriteArraySet<>(); + + public void onRouteAdded(@Observes RouteAddedEvent event) { + routesAdded.add(event.getRoute().getRouteId()); + } + + public void onRouteStarted(@Observes RouteStartedEvent event) { + routesStarted.add(event.getRoute().getRouteId()); + } + + public Set routesAdded() { + return routesAdded; + } + + public Set routesStarted() { + return routesStarted; + } + } + + @ApplicationScoped + public static class MyRoutes extends RouteBuilder { + public static String ROUTE_ID = "myRoute"; + public static String FROM_ENDPOINT = "direct://start"; + + @Override + public void configure() throws Exception { + from(FROM_ENDPOINT) + .routeId(ROUTE_ID) + .log("${body}"); + } + } +} diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java index 42883998389b..0249167f5d5a 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java @@ -66,6 +66,12 @@ public enum FailureRemedy { @ConfigItem public CSimpleConfig csimple; + /** + * Build time configuration options for the Camel CDI event bridge. + */ + @ConfigItem + public EventBridgeConfig eventBridge; + @ConfigGroup public static class BootstrapConfig { /** @@ -353,4 +359,21 @@ public static class CSimpleConfig { @ConfigItem(defaultValue = "warn") public FailureRemedy onBuildTimeAnalysisFailure; } + + @ConfigGroup + public static class EventBridgeConfig { + + /** + * Whether to enable the bridging of Camel events to CDI events. + *

+ * This allows CDI observers to be configured for Camel events. E.g. those belonging to the + * {@code org.apache.camel.quarkus.core.events}, {@code org.apache.camel.quarkus.main.events} & + * {@code org.apache.camel.impl.event} packages. + *

+ * Note that this configuration item only has any effect when observers configured for Camel events + * are present in the application. + */ + @ConfigItem(defaultValue = "true") + public boolean enabled; + } } diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java index 25deef0f99d7..7c2df25e938d 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelContextRecorder.java @@ -16,6 +16,8 @@ */ package org.apache.camel.quarkus.core; +import java.util.Set; + import io.quarkus.arc.runtime.BeanContainer; import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.annotations.Recorder; @@ -63,8 +65,6 @@ public RuntimeValue createContext( context.setModelJAXBContextFactory(contextFactory.getValue()); context.adapt(ExtendedCamelContext.class).setStartupStepRecorder(startupStepRecorder.getValue()); context.build(); - context.addLifecycleStrategy(new CamelLifecycleEventBridge()); - context.getManagementStrategy().addEventNotifier(new CamelManagementEventBridge()); context.setComponentNameResolver(componentNameResolver.getValue()); // register to the container @@ -122,4 +122,14 @@ public void configure() throws Exception { throw new RuntimeException(e); } } + + public void registerLifecycleEventBridge(RuntimeValue context, Set observedLifecycleEvents) { + context.getValue().addLifecycleStrategy(new CamelLifecycleEventBridge(observedLifecycleEvents)); + } + + public void registerManagementEventBridge(RuntimeValue camelContext, Set observedManagementEvents) { + camelContext.getValue() + .getManagementStrategy() + .addEventNotifier(new CamelManagementEventBridge(observedManagementEvents)); + } } diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelLifecycleEventBridge.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelLifecycleEventBridge.java index a675ed988059..0f9fcc9b3bf2 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelLifecycleEventBridge.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelLifecycleEventBridge.java @@ -17,6 +17,7 @@ package org.apache.camel.quarkus.core; import java.util.Collection; +import java.util.Set; import java.util.concurrent.ThreadPoolExecutor; import java.util.function.Supplier; @@ -45,7 +46,7 @@ /** * Bridges {@link org.apache.camel.spi.LifecycleStrategy} callbacks and CDI by producing the correspondent - * events. + * events. Events are only fired if a corresponding CDI observer is configured for them. *

* Note that this class does not implement all the callback as some notifications them are already covered * by management events {@link CamelManagementEventBridge} @@ -64,9 +65,11 @@ */ public class CamelLifecycleEventBridge implements LifecycleStrategy { private final Supplier beanManager; + private final Set observedLifecycleEvents; - public CamelLifecycleEventBridge() { + public CamelLifecycleEventBridge(Set observedLifecycleEvents) { this.beanManager = Suppliers.memorize(Arc.container()::beanManager); + this.observedLifecycleEvents = observedLifecycleEvents; } private void fireEvent(T event) { @@ -75,43 +78,59 @@ private void fireEvent(T event) { @Override public void onComponentAdd(String name, Component component) { - fireEvent(new ComponentAddEvent(component)); + if (observedLifecycleEvents.contains(ComponentAddEvent.class.getName())) { + fireEvent(new ComponentAddEvent(component)); + } } @Override public void onComponentRemove(String name, Component component) { - fireEvent(new ComponentRemoveEvent(component)); + if (observedLifecycleEvents.contains(ComponentRemoveEvent.class.getName())) { + fireEvent(new ComponentRemoveEvent(component)); + } } @Override public void onEndpointAdd(Endpoint endpoint) { - fireEvent(new EndpointAddEvent(endpoint)); + if (observedLifecycleEvents.contains(EndpointAddEvent.class.getName())) { + fireEvent(new EndpointAddEvent(endpoint)); + } } @Override public void onEndpointRemove(Endpoint endpoint) { - fireEvent(new EndpointRemoveEvent(endpoint)); + if (observedLifecycleEvents.contains(EndpointRemoveEvent.class.getName())) { + fireEvent(new EndpointRemoveEvent(endpoint)); + } } @Override public void onThreadPoolAdd(CamelContext camelContext, ThreadPoolExecutor threadPool, String id, String sourceId, String routeId, String threadPoolProfileId) { - fireEvent(new ThreadPoolAddEvent(camelContext, threadPool, id, sourceId, routeId, threadPoolProfileId)); + if (observedLifecycleEvents.contains(ThreadPoolAddEvent.class.getName())) { + fireEvent(new ThreadPoolAddEvent(camelContext, threadPool, id, sourceId, routeId, threadPoolProfileId)); + } } @Override public void onThreadPoolRemove(CamelContext camelContext, ThreadPoolExecutor threadPool) { - fireEvent(new ThreadPoolRemoveEvent(camelContext, threadPool)); + if (observedLifecycleEvents.contains(ThreadPoolRemoveEvent.class.getName())) { + fireEvent(new ThreadPoolRemoveEvent(camelContext, threadPool)); + } } @Override public void onServiceAdd(CamelContext context, Service service, org.apache.camel.Route route) { - fireEvent(new ServiceAddEvent(context, service, route)); + if (observedLifecycleEvents.contains(ServiceAddEvent.class.getName())) { + fireEvent(new ServiceAddEvent(context, service, route)); + } } @Override public void onServiceRemove(CamelContext context, Service service, org.apache.camel.Route route) { - fireEvent(new ServiceRemoveEvent(context, service, route)); + if (observedLifecycleEvents.contains(ServiceAddEvent.class.getName())) { + fireEvent(new ServiceRemoveEvent(context, service, route)); + } } @Override @@ -121,25 +140,21 @@ public void onContextStart(CamelContext context) throws VetoCamelContextStartExc @Override public void onContextStop(CamelContext context) { - // superseded by management events } @Override public void onRoutesAdd(Collection routes) { - // superseded by management events } @Override public void onRoutesRemove(Collection routes) { - // superseded by management events } @Override public void onRouteContextCreate(Route route) { - // superseded by management events } diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelManagementEventBridge.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelManagementEventBridge.java index 980b8470a33f..94c45e48280b 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelManagementEventBridge.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelManagementEventBridge.java @@ -16,6 +16,8 @@ */ package org.apache.camel.quarkus.core; +import java.util.Set; + import javax.enterprise.inject.spi.BeanManager; import io.quarkus.arc.Arc; @@ -29,8 +31,13 @@ * @see EventNotifier */ public class CamelManagementEventBridge extends EventNotifierSupport { + private final Set observedManagementEvents; private BeanManager beanManager; + public CamelManagementEventBridge(Set observedManagementEvents) { + this.observedManagementEvents = observedManagementEvents; + } + @Override protected void doInit() { beanManager = Arc.container().beanManager(); @@ -43,6 +50,6 @@ public void notify(CamelEvent event) throws Exception { @Override public boolean isEnabled(CamelEvent event) { - return true; + return observedManagementEvents.contains(event.getClass().getSimpleName()); } } diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainEventBridge.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainEventBridge.java index 21280086e5a6..1522ca467bfb 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainEventBridge.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainEventBridge.java @@ -16,6 +16,7 @@ */ package org.apache.camel.quarkus.main; +import java.util.Set; import java.util.function.Supplier; import javax.enterprise.inject.spi.BeanManager; @@ -40,24 +41,32 @@ */ public class CamelMainEventBridge implements MainListener { private final Supplier beanManager; + private final Set observedMainEvents; - public CamelMainEventBridge() { + public CamelMainEventBridge(Set observedMainEvents) { this.beanManager = Suppliers.memorize(Arc.container()::beanManager); + this.observedMainEvents = observedMainEvents; } @Override public void beforeInitialize(BaseMainSupport main) { - fireEvent(new BeforeInitialize(main)); + if (observedMainEvents.contains(BeforeInitialize.class.getName())) { + fireEvent(new BeforeInitialize(main)); + } } @Override public void beforeConfigure(BaseMainSupport main) { - fireEvent(new BeforeConfigure(main)); + if (observedMainEvents.contains(BeforeConfigure.class.getName())) { + fireEvent(new BeforeConfigure(main)); + } } @Override public void afterConfigure(BaseMainSupport main) { - fireEvent(new AfterConfigure(main)); + if (observedMainEvents.contains(AfterConfigure.class.getName())) { + fireEvent(new AfterConfigure(main)); + } } @Override @@ -67,22 +76,30 @@ public void configure(CamelContext context) { @Override public void beforeStart(BaseMainSupport main) { - fireEvent(new BeforeStart(main)); + if (observedMainEvents.contains(BeforeStart.class.getName())) { + fireEvent(new BeforeStart(main)); + } } @Override public void afterStart(BaseMainSupport main) { - fireEvent(new AfterStart(main)); + if (observedMainEvents.contains(AfterStart.class.getName())) { + fireEvent(new AfterStart(main)); + } } @Override public void beforeStop(BaseMainSupport main) { - fireEvent(new BeforeStop(main)); + if (observedMainEvents.contains(BeforeStop.class.getName())) { + fireEvent(new BeforeStop(main)); + } } @Override public void afterStop(BaseMainSupport main) { - fireEvent(new AfterStop(main)); + if (observedMainEvents.contains(AfterStop.class.getName())) { + fireEvent(new AfterStop(main)); + } } private void fireEvent(T event) { diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRecorder.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRecorder.java index edba747a5848..55e765102dbe 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRecorder.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMainRecorder.java @@ -17,6 +17,7 @@ package org.apache.camel.quarkus.main; import java.util.List; +import java.util.Set; import io.quarkus.arc.runtime.BeanContainer; import io.quarkus.runtime.RuntimeValue; @@ -41,7 +42,6 @@ public RuntimeValue createCamelMain(RuntimeValue runtim FailureRemedy failureRemedy) { CamelMain main = new CamelMain(runtime.getValue(), failureRemedy); main.setRoutesCollector(routesCollector.getValue()); - main.addMainListener(new CamelMainEventBridge()); // properties are loaded through MicroProfile Config so there's // no need to look for sources. @@ -95,4 +95,8 @@ public RuntimeValue createRuntime( return new RuntimeValue<>(runtime); } + + public void registerCamelMainEventBridge(RuntimeValue main, Set observedMainEvents) { + main.getValue().addMainListener(new CamelMainEventBridge(observedMainEvents)); + } } diff --git a/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigDefaultsTest.java b/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigDefaultsTest.java index 0131b0c31a6a..2a1f08804d0b 100644 --- a/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigDefaultsTest.java +++ b/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigDefaultsTest.java @@ -56,6 +56,6 @@ public void testMicrometerMetricsConfiguration() { assertTrue(messageHistoryFactory instanceof DefaultMessageHistoryFactory); List eventNotifiers = context.getManagementStrategy().getEventNotifiers(); - assertEquals(3, eventNotifiers.size()); + assertEquals(2, eventNotifiers.size()); } } diff --git a/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigOverrideTest.java b/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigOverrideTest.java index 6867a78197c9..16b965116b3a 100644 --- a/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigOverrideTest.java +++ b/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigOverrideTest.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; -import java.util.List; import java.util.Properties; import javax.inject.Inject; @@ -27,8 +26,6 @@ import io.quarkus.test.QuarkusUnitTest; import org.apache.camel.CamelContext; import org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory; -import org.apache.camel.quarkus.core.CamelManagementEventBridge; -import org.apache.camel.spi.EventNotifier; import org.apache.camel.spi.MessageHistoryFactory; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.Asset; @@ -37,7 +34,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -58,11 +54,6 @@ public void testMicroProfileMetricsConfiguration() { MessageHistoryFactory messageHistoryFactory = context.getMessageHistoryFactory(); assertNotNull(messageHistoryFactory); assertTrue(messageHistoryFactory instanceof MicrometerMessageHistoryFactory); - - // There should always be one event notifier added by core for CamelManagementEventBridge - List eventNotifiers = context.getManagementStrategy().getEventNotifiers(); - assertEquals(1, eventNotifiers.size()); - assertTrue(eventNotifiers.get(0) instanceof CamelManagementEventBridge); } public static final Asset applicationProperties() { diff --git a/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsDisabledTest.java b/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsDisabledTest.java index 9583704cd765..22b1d79056d1 100644 --- a/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsDisabledTest.java +++ b/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsDisabledTest.java @@ -27,8 +27,6 @@ import io.quarkus.test.QuarkusUnitTest; import org.apache.camel.CamelContext; import org.apache.camel.impl.engine.DefaultMessageHistoryFactory; -import org.apache.camel.quarkus.core.CamelManagementEventBridge; -import org.apache.camel.spi.EventNotifier; import org.apache.camel.spi.MessageHistoryFactory; import org.apache.camel.spi.RoutePolicyFactory; import org.jboss.shrinkwrap.api.ShrinkWrap; @@ -38,7 +36,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -60,11 +57,6 @@ public void testMicrometerMetricsDisabled() { MessageHistoryFactory messageHistoryFactory = context.getMessageHistoryFactory(); assertNotNull(messageHistoryFactory); assertTrue(messageHistoryFactory instanceof DefaultMessageHistoryFactory); - - // There should always be one event notifier added by core for CamelManagementEventBridge - List eventNotifiers = context.getManagementStrategy().getEventNotifiers(); - assertEquals(1, eventNotifiers.size()); - assertTrue(eventNotifiers.get(0) instanceof CamelManagementEventBridge); } public static final Asset applicationProperties() { diff --git a/extensions/microprofile-metrics/deployment/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsConfigDefaultsTest.java b/extensions/microprofile-metrics/deployment/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsConfigDefaultsTest.java index 844c8c3257de..bf22d1d113d3 100644 --- a/extensions/microprofile-metrics/deployment/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsConfigDefaultsTest.java +++ b/extensions/microprofile-metrics/deployment/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsConfigDefaultsTest.java @@ -56,6 +56,6 @@ public void testMicroProfileMetricsConfiguration() { assertTrue(messageHistoryFactory instanceof DefaultMessageHistoryFactory); List eventNotifiers = context.getManagementStrategy().getEventNotifiers(); - assertEquals(4, eventNotifiers.size()); + assertEquals(3, eventNotifiers.size()); } } diff --git a/extensions/microprofile-metrics/deployment/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsConfigOverrideTest.java b/extensions/microprofile-metrics/deployment/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsConfigOverrideTest.java index 2b6b740e7e7f..8f27318879eb 100644 --- a/extensions/microprofile-metrics/deployment/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsConfigOverrideTest.java +++ b/extensions/microprofile-metrics/deployment/src/test/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsConfigOverrideTest.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; -import java.util.List; import java.util.Properties; import javax.inject.Inject; @@ -27,8 +26,6 @@ import io.quarkus.test.QuarkusUnitTest; import org.apache.camel.CamelContext; import org.apache.camel.component.microprofile.metrics.message.history.MicroProfileMetricsMessageHistoryFactory; -import org.apache.camel.quarkus.core.CamelManagementEventBridge; -import org.apache.camel.spi.EventNotifier; import org.apache.camel.spi.MessageHistoryFactory; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.Asset; @@ -37,7 +34,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -58,11 +54,6 @@ public void testMicroProfileMetricsConfiguration() { MessageHistoryFactory messageHistoryFactory = context.getMessageHistoryFactory(); assertNotNull(messageHistoryFactory); assertTrue(messageHistoryFactory instanceof MicroProfileMetricsMessageHistoryFactory); - - // There should always be one event notifier added by core for CamelManagementEventBridge - List eventNotifiers = context.getManagementStrategy().getEventNotifiers(); - assertEquals(1, eventNotifiers.size()); - assertTrue(eventNotifiers.get(0) instanceof CamelManagementEventBridge); } public static final Asset applicationProperties() {