Author: davsclaus
Date: Mon Aug 23 17:20:53 2010
New Revision: 988215

URL: http://svn.apache.org/viewvc?rev=988215&view=rev
Log:
CAMEL-3069: Fixed JMX stats being counted double for processor types.

Added:
    
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsTest.java
      - copied, changed from r988148, 
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsLevelOffTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsWithSplitterTest.java
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java?rev=988215&r1=988214&r2=988215&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
 Mon Aug 23 17:20:53 2010
@@ -185,5 +185,4 @@ public abstract class ManagedPerformance
         lastExchangeFailureTimestamp.updateValue(now);
     }
 
-
 }

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=988215&r1=988214&r2=988215&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
 Mon Aug 23 17:20:53 2010
@@ -219,9 +219,6 @@ public abstract class ProcessorDefinitio
         // add interceptor strategies to the channel must be in this order: 
camel context, route context, local
         addInterceptStrategies(routeContext, channel, 
routeContext.getCamelContext().getInterceptStrategies());
         addInterceptStrategies(routeContext, channel, 
routeContext.getInterceptStrategies());
-        if (routeContext.getManagedInterceptStrategy() != null) {
-            
channel.addInterceptStrategy(routeContext.getManagedInterceptStrategy());
-        }
         addInterceptStrategies(routeContext, channel, 
this.getInterceptStrategies());
 
         // must do this ugly cast to avoid compiler error on AIX/HP-UX

Copied: 
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsTest.java
 (from r988148, 
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsLevelOffTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsLevelOffTest.java&r1=988148&r2=988215&rev=988215&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsLevelOffTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsTest.java
 Mon Aug 23 17:20:53 2010
@@ -17,19 +17,17 @@
 package org.apache.camel.management;
 
 import java.util.Set;
-import javax.management.Attribute;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.ManagementStatisticsLevel;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
  * @version $Revision$
  */
-public class ManagedStatisticsLevelOffTest extends ContextTestSupport {
+public class ManagedStatisticsTest extends ContextTestSupport {
 
     @Override
     protected boolean useJmx() {
@@ -42,17 +40,11 @@ public class ManagedStatisticsLevelOffTe
         DefaultManagementNamingStrategy naming = 
(DefaultManagementNamingStrategy) 
context.getManagementStrategy().getManagementNamingStrategy();
         naming.setHostName("localhost");
         naming.setDomainName("org.apache.camel");
-
-        // disable it by default
-        
context.getManagementStrategy().setStatisticsLevel(ManagementStatisticsLevel.Off);
         return context;
     }
 
     @SuppressWarnings("unchecked")
-    public void testManageStatisticsLevelDisabled() throws Exception {
-        template.sendBody("direct:start", "Hello World");
-        template.sendBody("direct:start", "Bye World");
-
+    public void testManageStatistics() throws Exception {
         // get the stats for the route
         MBeanServer mbeanServer = 
context.getManagementStrategy().getManagementAgent().getMBeanServer();
 
@@ -65,15 +57,25 @@ public class ManagedStatisticsLevelOffTe
         Long completed = (Long) mbeanServer.getAttribute(on, 
"ExchangesCompleted");
         assertEquals(0, completed.longValue());
 
-        // disable statistics
-        mbeanServer.setAttribute(on, new Attribute("StatisticsEnabled", true));
+        // send in 5 messages
+        template.sendBody("direct:start", "A");
+        template.sendBody("direct:start", "B");
+        template.sendBody("direct:start", "C");
+        template.sendBody("direct:start", "D");
+        template.sendBody("direct:start", "E");
 
-        // send in another message
-        template.sendBody("direct:start", "Goodday World");
-
-        // should be 1
+        // should be 5 on the route
         completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
-        assertEquals(1, completed.longValue());
+        assertEquals(5, completed.longValue());
+
+        // should be 5 on the processors
+        ObjectName foo = 
ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"foo\"");
+        completed = (Long) mbeanServer.getAttribute(foo, "ExchangesCompleted");
+        assertEquals(5, completed.longValue());
+
+        ObjectName mock = 
ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"mock\"");
+        completed = (Long) mbeanServer.getAttribute(mock, 
"ExchangesCompleted");
+        assertEquals(5, completed.longValue());
     }
 
     @Override
@@ -81,7 +83,10 @@ public class ManagedStatisticsLevelOffTe
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").to("mock:result");
+                from("direct:start")
+                    .to("log:foo").id("foo")
+                    .to("log:bar").id("bar")
+                    .to("mock:result").id("mock");
             }
         };
     }

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsWithSplitterTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsWithSplitterTest.java?rev=988215&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsWithSplitterTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedStatisticsWithSplitterTest.java
 Mon Aug 23 17:20:53 2010
@@ -0,0 +1,104 @@
+/**
+ * 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.management;
+
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision: 926292 $
+ */
+public class ManagedStatisticsWithSplitterTest extends ContextTestSupport {
+
+    @Override
+    protected boolean useJmx() {
+        return true;
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        DefaultManagementNamingStrategy naming = 
(DefaultManagementNamingStrategy) 
context.getManagementStrategy().getManagementNamingStrategy();
+        naming.setHostName("localhost");
+        naming.setDomainName("org.apache.camel");
+        return context;
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testManageStatistics() throws Exception {
+        // get the stats for the route
+        MBeanServer mbeanServer = 
context.getManagementStrategy().getManagementAgent().getMBeanServer();
+
+        ObjectName on = 
ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=routes,name=\"route-a\"");
+
+        // use route to get the total time
+        Long completed = (Long) mbeanServer.getAttribute(on, 
"ExchangesCompleted");
+        assertEquals(0, completed.longValue());
+
+        // send in 2 messages
+        template.sendBody("direct:start", "A,B,C");
+        template.sendBody("direct:start", "D,E");
+
+        // should be 2 on the route
+        completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
+        assertEquals(2, completed.longValue());
+
+        // should be 2 on the foo
+        ObjectName foo = 
ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"foo\"");
+        completed = (Long) mbeanServer.getAttribute(foo, "ExchangesCompleted");
+        assertEquals(2, completed.longValue());
+
+        // should be 5 on the split sub route
+        ObjectName bar = 
ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"bar\"");
+        completed = (Long) mbeanServer.getAttribute(bar, "ExchangesCompleted");
+        assertEquals(5, completed.longValue());
+
+        // should be 2 on the mock
+        ObjectName mock = 
ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"mock\"");
+        completed = (Long) mbeanServer.getAttribute(mock, 
"ExchangesCompleted");
+        assertEquals(2, completed.longValue());
+
+        // should be 5 on route-b
+        on = 
ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=routes,name=\"route-b\"");
+        completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
+        assertEquals(5, completed.longValue());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").routeId("route-a")
+                    .to("log:foo").id("foo")
+                    .split(body().tokenize(","))
+                        .to("direct:split")
+                    .end()
+                    .to("mock:result").id("mock");
+
+                from("direct:split").routeId("route-b")
+                    .to("log:bar").id("bar");
+            }
+        };
+    }
+
+}
\ No newline at end of file


Reply via email to