camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r680911 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/management/ camel-core/src/test/java/org/apache/camel/management/ components/camel-spring/src/main/java/org/apache/camel/spring/ components/camel-spring/src/test/...
Date Wed, 30 Jul 2008 05:09:35 GMT
Author: davsclaus
Date: Tue Jul 29 22:09:35 2008
New Revision: 680911

URL: http://svn.apache.org/viewvc?rev=680911&view=rev
Log:
CAMEL-768. Applied patch with thanks to William Tam.

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultInstrumentationAgent.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationDisableTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPropertiesTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationWithConnectorTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DisableJmxAgentTest.java
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DisableJmxAgentTheOldWayTest.java
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultInstrumentationAgent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultInstrumentationAgent.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultInstrumentationAgent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultInstrumentationAgent.java
Tue Jul 29 22:09:35 2008
@@ -26,7 +26,6 @@
 import java.util.List;
 import java.util.Set;
 
-import javax.management.InstanceAlreadyExistsException;
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.MBeanServerFactory;
@@ -69,7 +68,7 @@
     private String mBeanServerDefaultDomain;
     private String mBeanObjectDomainName;
     private String serviceUrlPath;
-    private Boolean usePlatformMBeanServer;
+    private Boolean usePlatformMBeanServer = true;
     private Boolean createConnector;
 
     protected void finalizeSettings() {
@@ -103,9 +102,9 @@
             createConnector = Boolean.getBoolean(JmxSystemPropertyKeys.CREATE_CONNECTOR);
         }
 
-        if (usePlatformMBeanServer == null) {
-            usePlatformMBeanServer =
-                Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS);
+        // "Use platform mbean server" is true by default
+        if (System.getProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS) != null) {
+            usePlatformMBeanServer = Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS);
         }
     }
 
@@ -294,7 +293,7 @@
     protected MBeanServer findOrCreateMBeanServer() {
 
         // return platform mbean server if the option is specified.
-        if (Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS) || usePlatformMBeanServer)
{
+        if (usePlatformMBeanServer) {
             return ManagementFactory.getPlatformMBeanServer();
         }
 

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationDisableTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationDisableTest.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationDisableTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationDisableTest.java
Tue Jul 29 22:09:35 2008
@@ -16,6 +16,13 @@
  */
 package org.apache.camel.management;
 
+import java.util.Set;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import org.apache.camel.component.mock.MockEndpoint;
+
 /**
  * A unit test which verifies disabling of JMX instrumentation.
  *
@@ -34,20 +41,39 @@
         System.clearProperty(JmxSystemPropertyKeys.DISABLED);
         super.tearDown();
     }
+
     
     @Override
     public void testMBeansRegistered() throws Exception {
-        assertNull(mbsc);
+        if (System.getProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS) != null &&
+                !Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS)) {
+            assertEquals(domainName, mbsc.getDefaultDomain());
+        }
+
+        resolveMandatoryEndpoint("mock:end", MockEndpoint.class);
+
+        Set s = mbsc.queryNames(
+                new ObjectName(domainName + ":type=endpoint,*"), null);
+        assertEquals("Could not find 0 endpoints: " + s, 0, s.size());
+
+        s = mbsc.queryNames(
+                new ObjectName(domainName + ":type=context,*"), null);
+        assertEquals("Could not find 0 context: " + s, 0, s.size());
+
+        s = mbsc.queryNames(
+                new ObjectName(domainName + ":type=processor,*"), null);
+        assertEquals("Could not find 0 processor: " + s, 0, s.size());
+
+        s = mbsc.queryNames(
+                new ObjectName(domainName + ":type=route,*"), null);
+        assertEquals("Could not find 0 route: " + s, 0, s.size());
+
     }
-    
+
     @Override
-    public void testCounters() throws Exception {
-        assertNull(mbsc);
+    protected void verifyCounter(MBeanServerConnection beanServer, ObjectName name) throws
Exception {
+        Set s = beanServer.queryNames(name, null);
+        assertEquals("Found mbeans: " + s, 0, s.size());
     }
-    
-    @Override
-    public void testMBeanServerType() throws Exception {
-        assertNull(mbsc);
 
-    }
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingDefaultsTest.java
Tue Jul 29 22:09:35 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.management;
 
+import java.lang.management.ManagementFactory;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -43,7 +44,8 @@
     protected long sleepForConnection;
 
     public void testMBeansRegistered() throws Exception {
-        if (!Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS)) {
+        if (System.getProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS) != null &&
+                !Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS)) {
             assertEquals(domainName, mbsc.getDefaultDomain());
         }
 
@@ -165,19 +167,10 @@
         mbsc = getMBeanConnection();
     }
 
-    @SuppressWarnings("unchecked")
+
     protected MBeanServerConnection getMBeanConnection() throws Exception {
         if (mbsc == null) {
-            List<MBeanServer> servers =
-                    (List<MBeanServer>)MBeanServerFactory.findMBeanServer(null);
-
-            for (MBeanServer server : servers) {
-                if (domainName.equals(server.getDefaultDomain())) {
-
-                    mbsc = server;
-                    break;
-                }
-            }
+            mbsc = ManagementFactory.getPlatformMBeanServer();
         }
         return mbsc;
     }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
Tue Jul 29 22:09:35 2008
@@ -16,13 +16,16 @@
  */
 package org.apache.camel.management;
 
-import java.lang.management.ManagementFactory;
+import java.util.List;
 
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
 import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerFactory;
 import javax.management.ObjectName;
 
 /**
- * This test verifies the system property to select platform mbean server.
+ * This test verifies the system property to un-select platform mbean server.
  * 
  * @version $Revision$
  */
@@ -30,7 +33,7 @@
 
     @Override
     protected void setUp() throws Exception {
-        System.setProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS, "True");
+        System.setProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS, "False");
         super.setUp();
     }
 
@@ -42,16 +45,31 @@
 
     @Override
     public void testMBeanServerType() throws Exception {
-        assertNotNull(mbsc.getMBeanInfo(
-                new ObjectName("java.lang:type=OperatingSystem")));
+        try {
+            mbsc.getMBeanInfo(new ObjectName("java.lang:type=OperatingSystem"));
+            assertFalse(true); // should not get here
+        } catch (InstanceNotFoundException e) {
+            // expected
+        }
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     protected MBeanServerConnection getMBeanConnection() throws Exception {
         if (mbsc == null) {
-            mbsc = ManagementFactory.getPlatformMBeanServer();
+            List<MBeanServer> servers =
+                    (List<MBeanServer>)MBeanServerFactory.findMBeanServer(null);
+
+            for (MBeanServer server : servers) {
+                if (domainName.equals(server.getDefaultDomain())) {
+
+                    mbsc = server;
+                    break;
+                }
+            }
         }
         return mbsc;
     }
 
+
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPropertiesTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPropertiesTest.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPropertiesTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPropertiesTest.java
Tue Jul 29 22:09:35 2008
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.management;
 
-import javax.management.InstanceNotFoundException;
 import javax.management.ObjectName;
 
 /**
@@ -44,12 +43,9 @@
     }
 
     public void testMBeanServerType() throws Exception {
-        try {
-            mbsc.getMBeanInfo(new ObjectName("java.lang:type=OperatingSystem"));
-            assertTrue(false);  // should not get here
-        } catch (InstanceNotFoundException e) {
-            // expect exception since this is not a platform mbean server
-        }
+        // default is platform mbs
+        assertNotNull(mbsc.getMBeanInfo(new ObjectName("java.lang:type=OperatingSystem")));
+        
     }
 
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationWithConnectorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationWithConnectorTest.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationWithConnectorTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationWithConnectorTest.java
Tue Jul 29 22:09:35 2008
@@ -38,6 +38,8 @@
     protected void setUp() throws Exception {
         sleepForConnection = 2000;
         System.setProperty(JmxSystemPropertyKeys.CREATE_CONNECTOR, "True");
+        // need to explicit set it to false to use non-platform mbs
+        System.setProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS, "False");
         System.setProperty(JmxSystemPropertyKeys.REGISTRY_PORT, "2000");
         super.setUp();
     }
@@ -46,6 +48,7 @@
     protected void tearDown() throws Exception {
         System.clearProperty(JmxSystemPropertyKeys.REGISTRY_PORT);
         System.clearProperty(JmxSystemPropertyKeys.CREATE_CONNECTOR);
+        System.clearProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS);
 
         if (clientConnector != null) {
             try {

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/MultiInstanceProcessorTest.java
Tue Jul 29 22:09:35 2008
@@ -44,7 +44,8 @@
      */
     @Override
     public void testMBeansRegistered() throws Exception {
-        if (!Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS)) {
+        if (System.getProperty(JmxSystemPropertyKeys.USE_PLATFORM_MBS) != null &&
+                !Boolean.getBoolean(JmxSystemPropertyKeys.USE_PLATFORM_MBS)) {
             assertEquals(domainName, mbsc.getDefaultDomain());
         }
 

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelJMXAgentType.java
Tue Jul 29 22:09:35 2008
@@ -79,7 +79,7 @@
      * A flag that indicates whether the platform mbean server should be used
      */
     @XmlAttribute(required = false)
-    private Boolean usePlatformMBeanServer;
+    private Boolean usePlatformMBeanServer = Boolean.TRUE;
 
     public Integer getConnectorPort() {
         return connectorPort;

Modified: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DefaultJMXAgentTest.java
Tue Jul 29 22:09:35 2008
@@ -16,13 +16,14 @@
  */
 package org.apache.camel.spring;
 
+import java.lang.management.ManagementFactory;
 import java.util.List;
 
 import javax.management.MBeanServer;
 import javax.management.MBeanServerConnection;
 import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
 
-import org.apache.camel.management.DefaultInstrumentationAgent;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
@@ -51,10 +52,6 @@
         super.tearDown();
     }
 
-    protected String getDomainName() {
-        return DefaultInstrumentationAgent.DEFAULT_DOMAIN;
-    }
-
     @SuppressWarnings("unchecked")
     protected void releaseMBeanServers() {
         List<MBeanServer> servers =
@@ -65,8 +62,9 @@
         }
     }
 
-    public void testGetJMXConnector() throws Exception {
-        assertEquals("Get the wrong domain name", mbsc.getDefaultDomain(), getDomainName());
+    public void testQueryMbeans() throws Exception {
+        assertEquals(1, mbsc.queryNames(new ObjectName("org.apache.camel" + ":type=route,*"),
null).size());
+        assertEquals(1, mbsc.queryNames(new ObjectName("org.apache.camel" + ":type=processor,*"),
null).size());
     }
 
     @Override
@@ -74,19 +72,11 @@
         return new ClassPathXmlApplicationContext("org/apache/camel/spring/defaultJmxConfig.xml");
     }
 
-    @SuppressWarnings("unchecked")
     protected MBeanServerConnection getMBeanConnection() throws Exception {
         if (mbsc == null) {
-            List<MBeanServer> servers =
-                    (List<MBeanServer>)MBeanServerFactory.findMBeanServer(null);
-
-            for (MBeanServer server : servers) {
-                if (getDomainName().equals(server.getDefaultDomain())) {
-                    mbsc = server;
-                    break;
-                }
-            }
+            mbsc = ManagementFactory.getPlatformMBeanServer();
         }
         return mbsc;
     }
+    
 }

Modified: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DisableJmxAgentTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DisableJmxAgentTest.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DisableJmxAgentTest.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DisableJmxAgentTest.java
Tue Jul 29 22:09:35 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.spring;
 
+import javax.management.ObjectName;
+
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
@@ -30,9 +32,11 @@
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext("org/apache/camel/spring/disableJmxConfig.xml");
           
     }
-    
-    public void testGetJMXConnector() throws Exception {
-        assertNull(mbsc);
+   
+    @Override
+    public void testQueryMbeans() throws Exception {
+        assertEquals(0, mbsc.queryNames(new ObjectName("org.apache.camel" + ":type=route,*"),
null).size());
+        assertEquals(0, mbsc.queryNames(new ObjectName("org.apache.camel" + ":type=processor,*"),
null).size());
     }
 
 }

Modified: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DisableJmxAgentTheOldWayTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DisableJmxAgentTheOldWayTest.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DisableJmxAgentTheOldWayTest.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/DisableJmxAgentTheOldWayTest.java
Tue Jul 29 22:09:35 2008
@@ -24,15 +24,11 @@
  * @version $Revision$
  *
  */
-public class DisableJmxAgentTheOldWayTest extends DefaultJMXAgentTest {
+public class DisableJmxAgentTheOldWayTest extends DisableJmxAgentTest {
     
     @Override
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext("org/apache/camel/spring/disableJmxTheOldWayConfig.xml");
           
     }
-    
-    public void testGetJMXConnector() throws Exception {
-        assertNull(mbsc);
-    }
 
 }

Modified: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/JMXAgentTest.java
Tue Jul 29 22:09:35 2008
@@ -57,11 +57,6 @@
     }
 
     @Override
-    protected String getDomainName() {
-        return "org.apache.camel.test";
-    }
-
-    @Override
     protected ClassPathXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext("org/apache/camel/spring/jmxConfig.xml");
     }

Modified: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml?rev=680911&r1=680910&r2=680911&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/jmxConfig.xml
Tue Jul 29 22:09:35 2008
@@ -25,7 +25,7 @@
   <!-- START SNIPPET: example -->
   <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
     <jmxAgent id="agent" registryPort="20008" 
-        mbeanServerDefaultDomain="org.apache.camel.test"
+        usePlatformMBeanServer="false"
         createConnector="true"
      />
       



Mime
View raw message