db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r633655 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management: JMXConnectionGetter.java MBeanTest.java PlatformConnectionGetter.java RemoteConnectionGetter.java
Date Tue, 04 Mar 2008 21:36:09 GMT
Author: djd
Date: Tue Mar  4 13:35:59 2008
New Revision: 633655

URL: http://svn.apache.org/viewvc?rev=633655&view=rev
Log:
DERBY-3385 Ensure the JMX remote connections opened by the MBean tests are closed, otherwise
warnings appear on the console.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionGetter.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/PlatformConnectionGetter.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/RemoteConnectionGetter.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionGetter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionGetter.java?rev=633655&r1=633654&r2=633655&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionGetter.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionGetter.java
Tue Mar  4 13:35:59 2008
@@ -41,4 +41,6 @@
      * Get a connection to the platform MBean Server.
      */
     MBeanServerConnection getMBeanServerConnection() throws Exception;
+    
+    void close(MBeanServerConnection jmxConnection) throws Exception;
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java?rev=633655&r1=633654&r2=633655&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
Tue Mar  4 13:35:59 2008
@@ -160,8 +160,10 @@
     protected void tearDown() throws Exception {
         super.tearDown();
         
-        // Does not appear to be a method to close!
-        jmxConnection = null;
+        if (jmxConnection != null) {
+           JMXConnectionGetter.mbeanServerConnector.get().close(jmxConnection);
+           jmxConnection = null;
+        }
     }
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/PlatformConnectionGetter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/PlatformConnectionGetter.java?rev=633655&r1=633654&r2=633655&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/PlatformConnectionGetter.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/PlatformConnectionGetter.java
Tue Mar  4 13:35:59 2008
@@ -25,9 +25,6 @@
 import java.security.PrivilegedAction;
 
 import javax.management.MBeanServerConnection;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
 
 /**
  * JMXConnectionGetter using the platform MBean server.
@@ -45,5 +42,9 @@
             public MBeanServerConnection run() {
                 return ManagementFactory.getPlatformMBeanServer(); 
             }});     
+    }
+
+    public void close(MBeanServerConnection jmxConnection)  {
+        // nothing to do.
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/RemoteConnectionGetter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/RemoteConnectionGetter.java?rev=633655&r1=633654&r2=633655&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/RemoteConnectionGetter.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/RemoteConnectionGetter.java
Tue Mar  4 13:35:59 2008
@@ -20,6 +20,9 @@
  */
 package org.apache.derbyTesting.functionTests.tests.management;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.management.MBeanServerConnection;
 import javax.management.remote.JMXConnector;
 import javax.management.remote.JMXConnectorFactory;
@@ -31,6 +34,9 @@
  *
  */
 class RemoteConnectionGetter implements JMXConnectionGetter {
+    
+    static final ThreadLocal<Map<MBeanServerConnection,JMXConnector>> connections
=
+        new ThreadLocal<Map<MBeanServerConnection,JMXConnector>>();
 
     private final JMXServiceURL url;
 
@@ -41,6 +47,22 @@
     public MBeanServerConnection getMBeanServerConnection() throws Exception {
         // assumes that JMX authentication and SSL is not required (hence null)
         JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
-        return jmxc.getMBeanServerConnection();
+        MBeanServerConnection jmxConn =  jmxc.getMBeanServerConnection();
+        
+        Map<MBeanServerConnection,JMXConnector> conns = connections.get();
+        if (conns == null) {
+            conns = new HashMap<MBeanServerConnection,JMXConnector>();
+            connections.set(conns);
+        }
+        
+        conns.put(jmxConn, jmxc);
+        
+        return jmxConn;
+    }
+
+    public void close(MBeanServerConnection jmxConnection) throws Exception {
+        Map<MBeanServerConnection,JMXConnector> conns = connections.get();
+        JMXConnector jmxc = conns.remove(jmxConnection);
+        jmxc.close();
     }
 }



Mime
View raw message