You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2012/09/22 18:52:47 UTC
svn commit: r1388842 - in /camel/branches/camel-2.9.x/camel-core/src:
main/java/org/apache/camel/util/EventHelper.java
test/java/org/apache/camel/util/EventHelperTest.java
Author: cmueller
Date: Sat Sep 22 16:52:47 2012
New Revision: 1388842
URL: http://svn.apache.org/viewvc?rev=1388842&view=rev
Log:
CAMEL-5631: EventHelper.notifyRouteStarted skips all remaining notifiers if one if the notifiers ignores route events
Added:
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/util/EventHelperTest.java
Modified:
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/EventHelper.java
Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/EventHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/EventHelper.java?rev=1388842&r1=1388841&r2=1388842&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/EventHelper.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/EventHelper.java Sat Sep 22 16:52:47 2012
@@ -119,7 +119,7 @@ public final class EventHelper {
for (EventNotifier notifier : notifiers) {
if (notifier.isIgnoreCamelContextEvents()) {
- return;
+ continue;
}
EventFactory factory = context.getManagementStrategy().getEventFactory();
@@ -234,7 +234,7 @@ public final class EventHelper {
for (EventNotifier notifier : notifiers) {
if (notifier.isIgnoreRouteEvents()) {
- return;
+ continue;
}
EventFactory factory = context.getManagementStrategy().getEventFactory();
Added: camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/util/EventHelperTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/util/EventHelperTest.java?rev=1388842&view=auto
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/util/EventHelperTest.java (added)
+++ camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/util/EventHelperTest.java Sat Sep 22 16:52:47 2012
@@ -0,0 +1,161 @@
+/**
+ * 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.util;
+
+import java.util.EventObject;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.management.DefaultManagementStrategy;
+import org.apache.camel.management.event.CamelContextStoppingEvent;
+import org.apache.camel.management.event.RouteStartedEvent;
+import org.apache.camel.management.event.RouteStoppedEvent;
+import org.apache.camel.spi.ManagementStrategy;
+import org.apache.camel.support.EventNotifierSupport;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class EventHelperTest {
+
+ @Test
+ public void testStartStopEventsReceived() throws Exception {
+ MyEventNotifier en1 = new MyEventNotifier();
+ MyEventNotifier en2 = new MyEventNotifier();
+
+ CamelContext camelContext = new DefaultCamelContext();
+ camelContext.addRoutes(new RouteBuilder() {
+ public void configure() throws Exception {
+ from("direct:start").routeId("route-1")
+ .to("mock:end");
+ }
+
+ });
+ ManagementStrategy managementStrategy = new DefaultManagementStrategy();
+ managementStrategy.addEventNotifier(en1);
+ managementStrategy.addEventNotifier(en2);
+ camelContext.setManagementStrategy(managementStrategy);
+
+ camelContext.start();
+ camelContext.stop();
+
+ assertEquals(1, en1.routeStartedEvent.get());
+ assertEquals(1, en1.routeStoppedEvent.get());
+ assertEquals(1, en1.camelContextStoppingEvent.get());
+
+ assertEquals(1, en2.routeStartedEvent.get());
+ assertEquals(1, en2.routeStoppedEvent.get());
+ assertEquals(1, en2.camelContextStoppingEvent.get());
+ }
+
+ @Test
+ public void testStartStopEventsReceivedWhenTheFirstOneIgnoreTheseEvents() throws Exception {
+ MyEventNotifier en1 = new MyEventNotifier();
+ en1.setIgnoreRouteEvents(true);
+ en1.setIgnoreCamelContextEvents(true);
+ MyEventNotifier en2 = new MyEventNotifier();
+
+ CamelContext camelContext = new DefaultCamelContext();
+ camelContext.addRoutes(new RouteBuilder() {
+ public void configure() throws Exception {
+ from("direct:start").routeId("route-1")
+ .to("mock:end");
+ }
+
+ });
+ ManagementStrategy managementStrategy = new DefaultManagementStrategy();
+ managementStrategy.addEventNotifier(en1);
+ managementStrategy.addEventNotifier(en2);
+ camelContext.setManagementStrategy(managementStrategy);
+
+ camelContext.start();
+ camelContext.stop();
+
+ assertEquals(0, en1.routeStartedEvent.get());
+ assertEquals(0, en1.routeStoppedEvent.get());
+ assertEquals(0, en1.camelContextStoppingEvent.get());
+
+ assertEquals(1, en2.routeStartedEvent.get());
+ assertEquals(1, en2.routeStoppedEvent.get());
+ assertEquals(1, en2.camelContextStoppingEvent.get());
+ }
+
+ @Test
+ public void testStartStopEventsReceivedWhenTheSecondOneIgnoreTheseEvents() throws Exception {
+ MyEventNotifier en1 = new MyEventNotifier();
+ MyEventNotifier en2 = new MyEventNotifier();
+ en2.setIgnoreRouteEvents(true);
+ en2.setIgnoreCamelContextEvents(true);
+
+ CamelContext camelContext = new DefaultCamelContext();
+ camelContext.addRoutes(new RouteBuilder() {
+ public void configure() throws Exception {
+ from("direct:start").routeId("route-1")
+ .to("mock:end");
+ }
+
+ });
+ ManagementStrategy managementStrategy = new DefaultManagementStrategy();
+ managementStrategy.addEventNotifier(en1);
+ managementStrategy.addEventNotifier(en2);
+ camelContext.setManagementStrategy(managementStrategy);
+
+ camelContext.start();
+ camelContext.stop();
+
+ assertEquals(1, en1.routeStartedEvent.get());
+ assertEquals(1, en1.routeStoppedEvent.get());
+ assertEquals(1, en1.camelContextStoppingEvent.get());
+
+ assertEquals(0, en2.routeStartedEvent.get());
+ assertEquals(0, en2.routeStoppedEvent.get());
+ assertEquals(0, en2.camelContextStoppingEvent.get());
+ }
+
+ static class MyEventNotifier extends EventNotifierSupport {
+
+ AtomicInteger routeStartedEvent = new AtomicInteger();
+ AtomicInteger routeStoppedEvent = new AtomicInteger();
+ AtomicInteger camelContextStoppingEvent = new AtomicInteger();
+
+ @Override
+ public void notify(EventObject event) throws Exception {
+ if (event instanceof RouteStartedEvent) {
+ routeStartedEvent.incrementAndGet();
+ } else if (event instanceof RouteStoppedEvent) {
+ routeStoppedEvent.incrementAndGet();
+ } else if (event instanceof CamelContextStoppingEvent) {
+ camelContextStoppingEvent.incrementAndGet();
+ }
+ }
+
+ @Override
+ public boolean isEnabled(EventObject event) {
+ return true;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ }
+ }
+}