db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r631711 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management: JMXConnectionDecorator.java MBeanTest.java
Date Wed, 27 Feb 2008 20:37:30 GMT
Author: djd
Date: Wed Feb 27 12:37:28 2008
New Revision: 631711

URL: http://svn.apache.org/viewvc?rev=631711&view=rev
Log:
DERBY-3385 Switch the way a JMX connection is opened to be driven by a decorator, step towards
having a local mode for the MBeans as well.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java?rev=631711&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java
Wed Feb 27 12:37:28 2008
@@ -0,0 +1,96 @@
+/*
+
+ Derby - Class org.apache.derbyTesting.functionTests.tests.management.JMXConnectionGetter
+
+ 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.derbyTesting.functionTests.tests.management;
+
+import java.net.MalformedURLException;
+
+import javax.management.remote.JMXServiceURL;
+
+import junit.framework.Test;
+
+import org.apache.derbyTesting.junit.BaseTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Interface for MBeanTest to get a MBeanServerConnection connection
+ * from. A decorator will setup mbeanServerConnector to point to
+ * an implementation of this class to obtain JMX connections.
+ */
+class JMXConnectionDecorator extends BaseTestSetup {
+    
+    /**
+     * Decorate a test so to use JMX connections from the passed in url. 
+     */
+    static Test remoteNoSecurity(Test test)
+    {
+        return new JMXConnectionDecorator(test, true);
+    }
+    
+    // ignored for now
+    private final boolean remote;
+    private JMXConnectionGetter oldGetter;
+
+    private JMXConnectionDecorator(Test test, boolean remote) {
+        super(test);
+        this.remote = remote;
+    }
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        oldGetter =
+            JMXConnectionGetter.mbeanServerConnector.get();
+        JMXConnectionGetter.mbeanServerConnector.set(
+                new RemoteConnectionGetter( getJmxUrl()));
+    }
+    
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        JMXConnectionGetter.mbeanServerConnector.set(oldGetter);
+        oldGetter = null;
+    }
+    
+    /**
+     * Creates a URL for connecting to the platform MBean server on the host
+     * specified by the network server hostname of this test configuration.
+     * The JMX port number used is also retreived from the test configuration.
+     * @return a service URL for connecting to the platform MBean server
+     * @throws MalformedURLException if the URL is malformed
+     */
+    private JMXServiceURL getJmxUrl() throws MalformedURLException {
+        
+        // NOTE: This hostname is only valid in a client/server configuration
+        String hostname = TestConfiguration.getCurrent().getHostName();
+        //String hostname = TestConfiguration.DEFAULT_HOSTNAME; // for embedded?
+        int jmxPort = TestConfiguration.getCurrent().getJmxPort();
+                
+        /* "jmxrmi" is the name of the RMI server connector of the platform
+         * MBean server, which is used by Derby */
+        JMXServiceURL url = new JMXServiceURL(
+                "service:jmx:rmi:///jndi/rmi://" 
+                    + hostname
+                    + ":" + jmxPort + "/jmxrmi");
+        
+        return url;
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionDecorator.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=631711&r1=631710&r2=631711&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
Wed Feb 27 12:37:28 2008
@@ -42,6 +42,7 @@
 import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.BaseTestCase;
+import org.apache.derbyTesting.junit.BaseTestSetup;
 import org.apache.derbyTesting.junit.NetworkServerTestSetup;
 import org.apache.derbyTesting.junit.SecurityManagerSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -63,7 +64,10 @@
         // Older VMs will get UnsupportedClassVersionError anyway...
         
         // Create a suite of all "test..." methods in the class.
-        TestSuite suite = new TestSuite(testClass,  suiteName);
+        Test suite = new TestSuite(testClass,  suiteName);
+        
+        // Set up to get JMX connections using remote JMX
+        suite = JMXConnectionDecorator.remoteNoSecurity(suite);
 
         /* Connecting to an MBean server using a URL requires setting up remote
          * JMX in the JVM to which we want to connect. This is usually done by
@@ -139,45 +143,14 @@
     }
     
     /**
-     * Creates a URL for connecting to the platform MBean server on the host
-     * specified by the network server hostname of this test configuration.
-     * The JMX port number used is also retreived from the test configuration.
-     * @return a service URL for connecting to the platform MBean server
-     * @throws MalformedURLException if the URL is malformed
-     */
-    private JMXServiceURL getJmxUrl() throws MalformedURLException {
-        
-        // NOTE: This hostname is only valid in a client/server configuration
-        String hostname = TestConfiguration.getCurrent().getHostName();
-        //String hostname = TestConfiguration.DEFAULT_HOSTNAME; // for embedded?
-        int jmxPort = TestConfiguration.getCurrent().getJmxPort();
-                
-        /* "jmxrmi" is the name of the RMI server connector of the platform
-         * MBean server, which is used by Derby */
-        JMXServiceURL url = new JMXServiceURL(
-                "service:jmx:rmi:///jndi/rmi://" 
-                    + hostname
-                    + ":" + jmxPort + "/jmxrmi");
-        
-        return url;
-    }
-    
-    /**
-     * Creates a client connector for JMX and uses this to obtain a connection
-     * to an MBean server. This method assumes that JMX security has been
-     * disabled, meaning that authentication credentials and SSL configuration 
-     * details are not supplied to the MBeanServer.
+     * Obtains a connection to an MBean server. Assumes th
      * 
      * @return a plain connection to an MBean server
-     * @throws MalformedURLException if the JMX Service URL used is invalid
-     * @throws IOException if connecting to the MBean server fails
      */
     protected MBeanServerConnection getMBeanServerConnection() 
-            throws MalformedURLException, IOException {
-                
-        // assumes that JMX authentication and SSL is not required (hence null)
-        JMXConnector jmxc = JMXConnectorFactory.connect(getJmxUrl(), null);
-        return jmxc.getMBeanServerConnection();
+            throws Exception {
+        
+        return JMXConnectionGetter.mbeanServerConnector.get().getMBeanServerConnection();
     }
     
     /**



Mime
View raw message