You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2010/07/08 08:32:04 UTC

svn commit: r961588 - in /camel/trunk/camel-core: pom.xml src/test/java/org/apache/camel/TestSupport.java src/test/java/org/apache/camel/TestSupportJmxCleanup.java

Author: hadrian
Date: Thu Jul  8 06:32:04 2010
New Revision: 961588

URL: http://svn.apache.org/viewvc?rev=961588&view=rev
Log:
CAMEL-2716. Cleanup platform mbean server between tests to avoid side effects in other tests

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupportJmxCleanup.java
Modified:
    camel/trunk/camel-core/pom.xml
    camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java

Modified: camel/trunk/camel-core/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/pom.xml?rev=961588&r1=961587&r2=961588&view=diff
==============================================================================
--- camel/trunk/camel-core/pom.xml (original)
+++ camel/trunk/camel-core/pom.xml Thu Jul  8 06:32:04 2010
@@ -149,7 +149,7 @@
       <plugin>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
-          <forkMode>pertest</forkMode>
+          <forkMode>once</forkMode>
           <excludes>
             <!-- TODO FIXME ASAP -->
             <exclude>**/XXXTest.*</exclude>            

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java?rev=961588&r1=961587&r2=961588&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java Thu Jul  8 06:32:04 2010
@@ -60,6 +60,8 @@ public abstract class TestSupport extend
             DefaultCamelContext.setContextCounter(0);
             TestSupportNodeIdFactory.resetCounters();
             super.runBare();
+            // make sure we cleanup the platform mbean server
+            TestSupportJmxCleanup.removeMBeans(null);
         }
     }
 

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupportJmxCleanup.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupportJmxCleanup.java?rev=961588&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupportJmxCleanup.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupportJmxCleanup.java Thu Jul  8 06:32:04 2010
@@ -0,0 +1,61 @@
+/**
+ * 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;
+
+import java.lang.management.ManagementFactory;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.management.DefaultManagementAgent;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public final class TestSupportJmxCleanup {
+    private static final transient Log LOG = LogFactory.getLog(TestSupportJmxCleanup.class);
+
+    public static void removeMBeans(String domain) throws Exception {
+        MBeanServer mbsc =  ManagementFactory.getPlatformMBeanServer();
+        Set<ObjectName> s = mbsc.queryNames(new ObjectName(getDomainName(domain) + ":*"), null);
+        for (ObjectName on : s) {
+            mbsc.unregisterMBean(on);
+        }
+    }
+
+    // useful helper to invoke in TestSupport to figure out what test leave junk behind
+    public static void traceMBeans(String domain) throws Exception {
+        MBeanServer mbsc =  ManagementFactory.getPlatformMBeanServer();
+        String d = getDomainName(domain);
+        Set<ObjectName> s = mbsc.queryNames(new ObjectName(d + ":*"), null);
+        if (s.size() > 0) {
+            LOG.warn(" + " + s.size() + " ObjectNames registered in domain \"" + d + "\"");
+            for (ObjectName on : s) {
+                LOG.warn(" |  " + on);
+            }
+        }
+    }
+
+    private static String getDomainName(String domain) {
+        return domain == null ? DefaultManagementAgent.DEFAULT_DOMAIN : domain;
+    }
+
+    private TestSupportJmxCleanup() {
+        // no instances
+    }
+}