diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java index 11b663b74e59a..303718a296372 100644 --- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java +++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java @@ -61,7 +61,7 @@ public class DefaultManagementStrategy extends ServiceSupport implements Managem private boolean onlyManageProcessorWithCustomId; private ManagementAgent managementAgent; private ManagementStatisticsLevel statisticsLevel = ManagementStatisticsLevel.All; - private boolean loadStatisticsEnabled = true; + private boolean loadStatisticsEnabled; private CamelContext camelContext; public DefaultManagementStrategy() { diff --git a/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java b/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java index 5486d778ad95b..b863d35f5887a 100644 --- a/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java +++ b/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java @@ -50,9 +50,8 @@ public void testMultipleLifecycleStrategies() throws Exception { context.removeComponent("log"); context.stop(); - List expectedEvents = Arrays.asList("onContextStart", "onServiceAdd", "onServiceAdd", "onServiceAdd", - "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", - "onThreadPoolAdd", "onComponentAdd", "onEndpointAdd", "onComponentRemove", "onContextStop", "onThreadPoolRemove"); + List expectedEvents = Arrays.asList("onContextStart", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", + "onServiceAdd", "onComponentAdd", "onEndpointAdd", "onComponentRemove", "onContextStop"); assertEquals(expectedEvents, dummy1.getEvents()); assertEquals(expectedEvents, dummy2.getEvents()); diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java index ed1bc296e1bc2..a58fdbf0b35ee 100644 --- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java +++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; + import javax.management.MBeanServer; import javax.management.ObjectName; @@ -58,7 +59,7 @@ public void testRouteAddRemoteRouteWithTo() throws Exception { // number of services Set names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Adding 2nd route"); @@ -78,7 +79,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Removing 2nd route"); @@ -89,7 +90,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Shutting down..."); } @@ -105,7 +106,7 @@ public void testRouteAddRemoteRouteWithRecipientList() throws Exception { // number of services Set names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Adding 2nd route"); @@ -125,7 +126,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Removing 2nd route"); @@ -136,7 +137,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Shutting down..."); } @@ -152,7 +153,7 @@ public void testRouteAddRemoteRouteWithRoutingSlip() throws Exception { // number of services Set names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Adding 2nd route"); @@ -172,7 +173,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Removing 2nd route"); @@ -183,7 +184,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Shutting down..."); } @@ -199,7 +200,7 @@ public void testRouteAddRemoteRouteWithRecipientListAndRouteScopedOnException() // number of services Set names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Adding 2nd route"); @@ -229,7 +230,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); // now stop and remove the 2nd route log.info("Stopping 2nd route"); @@ -241,7 +242,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Shutting down..."); } @@ -257,7 +258,7 @@ public void testRouteAddRemoteRouteWithRecipientListAndContextScopedOnException( // number of services Set names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Adding 2nd route"); @@ -288,7 +289,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); // now stop and remove the 2nd route log.info("Stopping 2nd route"); @@ -300,7 +301,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Shutting down..."); } @@ -316,7 +317,7 @@ public void testRouteAddRemoteRouteWithRecipientListAndRouteScopedOnCompletion() // number of services Set names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Adding 2nd route"); @@ -345,7 +346,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); // now stop and remove the 2nd route log.info("Stopping 2nd route"); @@ -357,7 +358,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Shutting down..."); } @@ -373,7 +374,7 @@ public void testRouteAddRemoteRouteWithRecipientListAndContextScopedOnCompletion // number of services Set names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Adding 2nd route"); @@ -403,7 +404,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); // now stop and remove the 2nd route log.info("Stopping 2nd route"); @@ -415,7 +416,7 @@ public void configure() throws Exception { // there should still be the same number of services names = mbeanServer.queryNames(on, null); - assertEquals(8, names.size()); + assertEquals(7, names.size()); log.info("Shutting down..."); } diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteLoadstatisticsTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteLoadstatisticsTest.java new file mode 100644 index 0000000000000..0f689d913aa8e --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteLoadstatisticsTest.java @@ -0,0 +1,93 @@ +/** + * 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 javax.management.MBeanServer; +import javax.management.ObjectName; + +import org.apache.camel.builder.RouteBuilder; + +/** + * @version + */ +public class ManagedRouteLoadstatisticsTest extends ManagementTestSupport { + + public void testLoadstatisticsAreDisabledByDefault() throws Exception { + // JMX tests dont work well on AIX CI servers (hangs them) + if (isPlatform("aix")) { + return; + } + + assertFalse(context.getManagementStrategy().isLoadStatisticsEnabled()); + // get the stats for the route + MBeanServer mbeanServer = getMBeanServer(); + ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route1\""); + getMockEndpoint("mock:result").expectedMessageCount(1); + + template.asyncSendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + + String load01 = (String)mbeanServer.getAttribute(on, "Load01"); + String load05 = (String)mbeanServer.getAttribute(on, "Load05"); + String load15 = (String)mbeanServer.getAttribute(on, "Load15"); + assertEquals("NaN", load01); + assertEquals("NaN", load05); + assertEquals("NaN", load15); + } + + public void testEnableLoadstatisticsd() throws Exception { + // JMX tests dont work well on AIX CI servers (hangs them) + if (isPlatform("aix")) { + return; + } + context.getManagementStrategy().setLoadStatisticsEnabled(true); + context.stop(); + context.start(); + // get the stats for the route + MBeanServer mbeanServer = getMBeanServer(); + ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route1\""); + + getMockEndpoint("mock:result").expectedMessageCount(1); + + template.asyncSendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + Thread.sleep(2000); + String load01 = (String)mbeanServer.getAttribute(on, "Load01"); + String load05 = (String)mbeanServer.getAttribute(on, "Load05"); + String load15 = (String)mbeanServer.getAttribute(on, "Load15"); + assertNotNull(load01); + assertNotNull(load05); + assertNotNull(load15); + assertTrue(Double.parseDouble(load01.replace(',', '.')) >= 0); + assertTrue(Double.parseDouble(load05.replace(',', '.')) >= 0); + assertTrue(Double.parseDouble(load15.replace(',', '.')) >= 0); + + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start").to("log:foo").delay(2000).to("mock:result"); + } + }; + } + +}