Author: djd Date: Tue Mar 4 13:09:36 2008 New Revision: 633643 URL: http://svn.apache.org/viewvc?rev=633643&view=rev Log: DERBY-3424 DERBY-3385 Add test for the ManagementMBean when Derby is not running. Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/InactiveManagementMBeanTest.java (with props) Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.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/_Suite.java Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java?rev=633643&r1=633642&r2=633643&view=diff ============================================================================== --- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java (original) +++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java Tue Mar 4 13:09:36 2008 @@ -150,6 +150,7 @@ registeredMbeans = null; myManagementServer = null; + systemIdentifier = null; } /** @@ -384,7 +385,7 @@ */ } - public String getSystemIdentifier() { + public synchronized String getSystemIdentifier() { return systemIdentifier; } } Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/InactiveManagementMBeanTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/InactiveManagementMBeanTest.java?rev=633643&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/InactiveManagementMBeanTest.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/InactiveManagementMBeanTest.java Tue Mar 4 13:09:36 2008 @@ -0,0 +1,90 @@ +/* + + Derby - Class org.apache.derbyTesting.functionTests.tests.management.InactiveManagementMBeanTest + + 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.util.Set; + +import javax.management.ObjectName; + +import org.apache.derbyTesting.junit.TestConfiguration; + +import junit.framework.Test; + + +/** + * Test the ManagementMBean interface provided by Derby + * and installed by the application when Derby is not running. + */ +public class InactiveManagementMBeanTest extends MBeanTest { + + public InactiveManagementMBeanTest(String name) { + super(name); + } + + public static Test suite() { + + return MBeanTest.suite(InactiveManagementMBeanTest.class, + "InactiveManagementMBeanTest"); + } + + /** + * Test that the MBean created by the application can + * successfully start and stop Derby's JMX management. + */ + public void testStartStopManagementFromApplication() + throws Exception + { + ObjectName appMgmtBean = getApplicationManagementMBean(); + + // Derby should be running. + assertBooleanAttribute(true, appMgmtBean, "ManagementActive"); + + assertNotNull(getAttribute(appMgmtBean, "SystemIdentifier")); + + // now shutdown Derby. + if (isPlatformJMXClient()) + { + // Derby is running embedded within the same virtual machine + getTestConfiguration().shutdownEngine(); + } + else + { + // TODO: Need to stop derby running on the remote + // machine but leave the vm up. How to do that? + return; + } + + // Ensure that the state of Derby's management cannot change + // since Derby is not running and that the application's MBean + // continues to work. + assertBooleanAttribute(false, appMgmtBean, "ManagementActive"); + assertNull(getAttribute(appMgmtBean, "SystemIdentifier")); + + invokeOperation(appMgmtBean, "startManagement"); + assertBooleanAttribute(false, appMgmtBean, "ManagementActive"); + assertNull(getAttribute(appMgmtBean, "SystemIdentifier")); + + invokeOperation(appMgmtBean, "stopManagement"); + assertBooleanAttribute(false, appMgmtBean, "ManagementActive"); + assertNull(getAttribute(appMgmtBean, "SystemIdentifier")); + } +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/InactiveManagementMBeanTest.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=633643&r1=633642&r2=633643&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:09:36 2008 @@ -43,6 +43,11 @@ */ abstract class MBeanTest extends BaseTestCase { + /** + * JMX connection to use throughout the instance. + */ + private MBeanServerConnection jmxConnection; + public MBeanTest(String name) { super(name); } @@ -151,6 +156,14 @@ enableManagement(); } + @Override + protected void tearDown() throws Exception { + super.tearDown(); + + // Does not appear to be a method to close! + jmxConnection = null; + } + /** * Obtains a connection to an MBean server. Assumes th * @@ -159,7 +172,19 @@ protected MBeanServerConnection getMBeanServerConnection() throws Exception { - return JMXConnectionGetter.mbeanServerConnector.get().getMBeanServerConnection(); + if (jmxConnection == null) + jmxConnection = + JMXConnectionGetter.mbeanServerConnector.get().getMBeanServerConnection(); + return jmxConnection; + } + + /** + * Is the JMX connecting using platform JMX. + * @return True jmx connections via the platform server, false remote connections. + */ + protected boolean isPlatformJMXClient() { + return JMXConnectionGetter.mbeanServerConnector.get() + instanceof PlatformConnectionGetter; } /** 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=633643&r1=633642&r2=633643&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 Mar 4 13:09:36 2008 @@ -53,6 +53,7 @@ suite.addTest(JMXTest.suite()); suite.addTest(ManagementMBeanTest.suite()); + suite.addTest(InactiveManagementMBeanTest.suite()); suite.addTest(VersionMBeanTest.suite()); return suite;