db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r631372 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/services/info/ engine/org/apache/derby/mbeans/ testing/org/apache/derbyTesting/functionTests/tests/management/
Date Tue, 26 Feb 2008 20:55:06 GMT
Author: djd
Date: Tue Feb 26 12:54:56 2008
New Revision: 631372

URL: http://svn.apache.org/viewvc?rev=631372&view=rev
Log:
DERBY-1387, DERBY-3385, DERBY-3435 Add a ManagementMBeanTest which requires some refactoring
of the MBeanTest to have the JMX setup moved from VersionMBeanTest. Fix VersionMBean not to
have the BuildNumberAsInt attribute and rename MaintananceVersion to match the spec and the
tests.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/ManagementMBeanTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/Version.java
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.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/VersionMBeanTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/_Suite.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/Version.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/Version.java?rev=631372&r1=631371&r2=631372&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/Version.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/info/Version.java Tue Feb
26 12:54:56 2008
@@ -63,16 +63,12 @@
         return versionInfo.getMinorVersion();
     }
     
-    public int getMaintVersion(){
+    public int getMaintenanceVersion(){
         return versionInfo.getMaintVersion();
     }
     
     public String getBuildNumber(){
         return versionInfo.getBuildNumber();
-    }
-    
-    public int getBuildNumberAsInt(){
-        return versionInfo.getBuildNumberAsInt();
     }
     
     public boolean isBeta(){

Modified: db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java?rev=631372&r1=631371&r2=631372&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java Tue Feb 26 12:54:56
2008
@@ -45,7 +45,7 @@
     
     public int getMajorVersion();
     public int getMinorVersion();
-    public int getMaintVersion();
+    public int getMaintenanceVersion();
     
     /**
      * Return the full version string.
@@ -54,7 +54,6 @@
     public String getVersionString();
     
     public String getBuildNumber();
-    public int getBuildNumberAsInt();
     
     public boolean isBeta();
     public boolean isAlpha();

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=631372&r1=631371&r2=631372&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 Feb 26 12:54:56 2008
@@ -22,16 +22,27 @@
 package org.apache.derbyTesting.functionTests.tests.management;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.MalformedURLException;
+import java.util.ArrayList;
 
 import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.JMException;
+import javax.management.MBeanException;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
+import javax.management.ReflectionException;
 import javax.management.remote.JMXConnector;
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
 import org.apache.derbyTesting.junit.BaseTestCase;
+import org.apache.derbyTesting.junit.NetworkServerTestSetup;
+import org.apache.derbyTesting.junit.SecurityManagerSetup;
 import org.apache.derbyTesting.junit.TestConfiguration;
 
 /**
@@ -44,6 +55,74 @@
         super(name);
     }
     
+    protected static Test suite(Class testClass, String suiteName) {
+        
+        // TODO -
+        // Check for J2SE 5.0 or better? Or java.lang.management.ManagementFactory?
+        // Older VMs will get UnsupportedClassVersionError anyway...
+        
+        // Create a suite of all "test..." methods in the class.
+        TestSuite suite = new TestSuite(testClass,  suiteName);
+
+        /* 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
+         * setting a few system properties at JVM startup.
+         * A quick solution is to set up a new network server JVM with
+         * the required jmx properties.
+         * A future improvement could be to fork a new JVM for embedded (?).
+         *
+         * This requires that the default security policy of the network server
+         * includes the permissions required to perform the actions of these 
+         * tests. Otherwise, we'd probably have to supply a custom policy file
+         * and specify this using additional command line properties at server 
+         * startup.
+         */
+        NetworkServerTestSetup networkServerTestSetup = 
+                new NetworkServerTestSetup (
+                        suite, // run all tests in this class in the same setup
+                        getCommandLineProperties(), // need to set up JMX in JVM
+                        new String[0], // no server arguments needed
+                        true,   // wait for the server to start properly
+                        new InputStream[1] // no need to check server output
+                );
+
+        /* Since the server will be started in a new process we need "execute" 
+         * FilePermission on all files (at least Java executables)...
+         * Will run without SecurityManager for now, but could probably add a 
+         * JMX specific policy file later. Or use the property trick reported
+         * on derby-dev 2008-02-26 and add the permission to the generic 
+         * policy.
+         */
+        Test testSetup = 
+                SecurityManagerSetup.noSecurityManager(networkServerTestSetup);
+        // this decorator makes sure the suite is empty if this configration
+        // does not support the network server:
+        return TestConfiguration.defaultServerDecorator(testSetup);
+    }
+    
+    // ---------- UTILITY METHODS ------------
+    
+    /**
+     * Returns a set of startup properties suitable for VersionMBeanTest.
+     * These properties are used to configure JMX in a different JVM.
+     * Will set up remote JMX using the port 9999 (TODO: make this 
+     * configurable), and with JMX security (authentication & SSL) disabled.
+     * 
+     * @return a set of Java system properties to be set on the command line
+     *         when starting a new JVM in order to enable remote JMX.
+     */
+    private static String[] getCommandLineProperties()
+    {
+        ArrayList<String> list = new ArrayList<String>();
+        list.add("com.sun.management.jmxremote.port=" 
+                + TestConfiguration.getCurrent().getJmxPort());
+        list.add("com.sun.management.jmxremote.authenticate=false");
+        list.add("com.sun.management.jmxremote.ssl=false");
+        String[] result = new String[list.size()];
+        list.toArray(result);
+        return result;
+    }
+    
   
     /**
      * Setup code to be run before each test fixture. This method will make
@@ -109,21 +188,11 @@
      * @throws Exception JMX-related exceptions if an unexpected error occurs.
      */
     protected void enableManagement() throws Exception {
-        // prepare the Management mbean. Use the same ObjectName that Derby uses
-        // by default, to avoid creating multiple instances of the same bean
-        ObjectName mgmtObjName 
-                = new ObjectName("org.apache.derby", "type", "Management");
-        // create/register the MBean. If the same MBean has already been
-        // registered with the MBeanServer, that MBean will be referenced.
-        //ObjectInstance mgmtObj = 
-        MBeanServerConnection serverConn = getMBeanServerConnection();
         
-        try {
-            serverConn.createMBean("org.apache.derby.mbeans.Management", 
-                    mgmtObjName);
-        } catch (InstanceAlreadyExistsException e) {
-            // Derby's ManagementMBean has already been created
-        }
+        ObjectName mgmtObjName = getApplicationManagementMBean();
+        
+        MBeanServerConnection serverConn = getMBeanServerConnection();
+
         // check the status of the management service
         Boolean active = (Boolean) 
                 serverConn.getAttribute(mgmtObjName, "ManagementActive");
@@ -143,6 +212,49 @@
     }
     
     /**
+     * Get the ObjectName for the application
+     * created ManagementMBean. The MBean will be
+     * created if it is not already registered.
+     * @return
+     * @throws Exception
+     */
+    protected ObjectName getApplicationManagementMBean() throws Exception
+    {
+        // prepare the Management mbean. Use the same ObjectName that Derby uses
+        // by default, to avoid creating multiple instances of the same bean
+        ObjectName mgmtObjName 
+                = new ObjectName("org.apache.derby", "type", "Management");
+        // create/register the MBean. If the same MBean has already been
+        // registered with the MBeanServer, that MBean will be referenced.
+        //ObjectInstance mgmtObj = 
+        MBeanServerConnection serverConn = getMBeanServerConnection();
+        
+        if (!serverConn.isRegistered(mgmtObjName))
+        {
+        
+            serverConn.createMBean(
+                    "org.apache.derby.mbeans.Management", 
+                    mgmtObjName);
+        }
+        
+        return mgmtObjName;
+    }
+    
+    /**
+     * Invoke an operation with no arguments.
+     * @param objName MBean to operate on
+     * @param name Operation name.
+     */
+    protected void invokeOperation(ObjectName objName, String name)
+        throws Exception
+    {
+        getMBeanServerConnection().invoke(
+                objName, 
+                name, 
+                new Object[0], new String[0]); // no arguments
+    }
+    
+    /**
      * Gets the value of a given attribute that is exposed by the MBean 
      * represented by the given object name.
      * @param objName the object name defining a specific MBean instance
@@ -154,6 +266,14 @@
             throws Exception {
         
         return getMBeanServerConnection().getAttribute(objName, name);
+    }
+    
+    protected void assertBooleanAttribute(boolean expected,
+            ObjectName objName, String name) throws Exception
+    {
+        Boolean bool = (Boolean) getAttribute(objName, name);
+        assertNotNull(bool);
+        assertEquals(expected, bool.booleanValue());
     }
     
     /**

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/ManagementMBeanTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/ManagementMBeanTest.java?rev=631372&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/ManagementMBeanTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/ManagementMBeanTest.java
Tue Feb 26 12:54:56 2008
@@ -0,0 +1,71 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.management.ManagementMBeanTest
+
+   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 javax.management.ObjectName;
+
+import junit.framework.Test;
+
+
+/**
+ * Test the ManagementMBean interface provided by Derby
+ * which has two implementations. A built in one and
+ * one that can be created by a user.
+ */
+public class ManagementMBeanTest extends MBeanTest {
+    
+    public ManagementMBeanTest(String name) {
+        super(name);
+    }
+    
+    public static Test suite() {
+        
+        return MBeanTest.suite(ManagementMBeanTest.class, 
+                                        "ManagementMBeanTest:client");
+    }
+    
+    public void testStartStopManagementFromApplication()
+        throws Exception
+    {
+        ObjectName appMgmtBean = getApplicationManagementMBean();
+        startStopManagement(appMgmtBean);
+    }
+    
+    private void startStopManagement(ObjectName mbean) throws Exception
+    {
+        // Test fixtures start off active
+        assertBooleanAttribute(true, mbean, "ManagementActive");
+        
+        // Should be a no-op
+        invokeOperation(mbean, "startManagement");
+        assertBooleanAttribute(true, mbean, "ManagementActive");
+        
+        // now stop management
+        invokeOperation(mbean, "stopManagement");
+        assertBooleanAttribute(false, mbean, "ManagementActive");
+        
+        // now start management again
+        invokeOperation(mbean, "startManagement");
+        assertBooleanAttribute(true, mbean, "ManagementActive");
+
+    }
+}

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/VersionMBeanTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/VersionMBeanTest.java?rev=631372&r1=631371&r2=631372&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/VersionMBeanTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/VersionMBeanTest.java
Tue Feb 26 12:54:56 2008
@@ -57,75 +57,11 @@
     }
     
     public static Test suite() {
-                
-        // TODO -
-        // Check for J2SE 5.0 or better? Or java.lang.management.ManagementFactory?
-        // Older VMs will get UnsupportedClassVersionError anyway...
         
-        // Create a suite of all "test..." methods in this class.
-        TestSuite suite = new TestSuite(VersionMBeanTest.class, 
+        return MBeanTest.suite(VersionMBeanTest.class, 
                                         "VersionMBeanTest:client");
-
-        /* 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
-         * setting a few system properties at JVM startup.
-         * A quick solution is to set up a new network server JVM with
-         * the required jmx properties.
-         * A future improvement could be to fork a new JVM for embedded (?).
-         *
-         * This requires that the default security policy of the network server
-         * includes the permissions required to perform the actions of these 
-         * tests. Otherwise, we'd probably have to supply a custom policy file
-         * and specify this using additional command line properties at server 
-         * startup.
-         */
-        NetworkServerTestSetup networkServerTestSetup = 
-                new NetworkServerTestSetup (
-                        suite, // run all tests in this class in the same setup
-                        getCommandLineProperties(), // need to set up JMX in JVM
-                        new String[0], // no server arguments needed
-                        true,   // wait for the server to start properly
-                        new InputStream[1] // no need to check server output
-                );
-
-        /* Since the server will be started in a new process we need "execute" 
-         * FilePermission on all files (at least Java executables)...
-         * Will run without SecurityManager for now, but could probably add a 
-         * JMX specific policy file later. Or use the property trick reported
-         * on derby-dev 2008-02-26 and add the permission to the generic 
-         * policy.
-         */
-        Test testSetup = 
-                SecurityManagerSetup.noSecurityManager(networkServerTestSetup);
-        // this decorator makes sure the suite is empty if this configration
-        // does not support the network server:
-        return TestConfiguration.defaultServerDecorator(testSetup);
     }
     
-    // ---------- UTILITY METHODS ------------
-    
-    /**
-     * Returns a set of startup properties suitable for VersionMBeanTest.
-     * These properties are used to configure JMX in a different JVM.
-     * Will set up remote JMX using the port 9999 (TODO: make this 
-     * configurable), and with JMX security (authentication & SSL) disabled.
-     * 
-     * @return a set of Java system properties to be set on the command line
-     *         when starting a new JVM in order to enable remote JMX.
-     */
-    private static String[] getCommandLineProperties()
-    {
-        ArrayList<String> list = new ArrayList<String>();
-        list.add("com.sun.management.jmxremote.port=" 
-                + TestConfiguration.getCurrent().getJmxPort());
-        list.add("com.sun.management.jmxremote.authenticate=false");
-        list.add("com.sun.management.jmxremote.ssl=false");
-        String[] result = new String[list.size()];
-        list.toArray(result);
-        return result;
-    }
-    
-
     /**
      * <p>
      * Creates an object name instance for the MBean whose object name's textual

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/_Suite.java?rev=631372&r1=631371&r2=631372&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/_Suite.java
Tue Feb 26 12:54:56 2008
@@ -51,6 +51,7 @@
 
         TestSuite suite = new TestSuite("management");
 
+        suite.addTest(ManagementMBeanTest.suite());
         suite.addTest(VersionMBeanTest.suite());
         
         return suite;



Mime
View raw message