[Proxool-cvs] proxool/src/java-test/org/logicalcobwebs/proxool/admin/jmx AbstractJMXTest.java,NONE,1
UNMAINTAINED!
Brought to you by:
billhorsman
Update of /cvsroot/proxool/proxool/src/java-test/org/logicalcobwebs/proxool/admin/jmx In directory sc8-pr-cvs1:/tmp/cvs-serv9984 Modified Files: AllTests.java ConnectionPoolMBeanTest.java Added Files: AbstractJMXTest.java MultipleAgentsConnectionPoolMBeanTest.java Log Message: Improved tests. --- NEW FILE: AbstractJMXTest.java --- package org.logicalcobwebs.proxool.admin.jmx; import java.util.Properties; import java.sql.SQLException; import java.sql.DriverManager; import org.logicalcobwebs.proxool.AbstractProxoolTest; import org.logicalcobwebs.proxool.TestHelper; import org.logicalcobwebs.proxool.TestConstants; import org.logicalcobwebs.proxool.ProxoolConstants; /** * Parent class for the JMX tests. * * @version $Revision: 1.1 $, $Date: 2003/10/20 07:40:44 $ * @author Christian Nedregaard (chr...@em...) * @author $Author: chr32 $ (current maintainer) * @since Proxool 0.8 */ public class AbstractJMXTest extends AbstractProxoolTest { /** * @see junit.framework.TestCase#TestCase(java.lang.String) */ public AbstractJMXTest(String alias) { super(alias); } /** * Create a very basic Proxool pool. * @param alias the alias of the pool * @return the properties used to create the pool. * @throws SQLException if the pool creation fails. */ protected Properties createBasicPool(String alias) throws SQLException { final String url = TestHelper.buildProxoolUrl(alias, TestConstants.HYPERSONIC_DRIVER, TestConstants.HYPERSONIC_TEST_URL); final Properties info = createBasicProperties(alias); DriverManager.getConnection(url, info).close(); return info; } /** * Create some very basic Proxool configuration. * @param alias the alias of the pool to be configured. * @return the created properties. */ protected Properties createBasicProperties(String alias) { final Properties info = new Properties(); info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); info.setProperty(ProxoolConstants.JMX_PROPERTY, Boolean.TRUE.toString()); info.setProperty(ProxoolConstants.FATAL_SQL_EXCEPTION_PROPERTY, alias); return info; } } --- NEW FILE: MultipleAgentsConnectionPoolMBeanTest.java --- /* * This software is released under a licence similar to the Apache Software Licence. * See org.logicalcobwebs.proxool.package.html for details. * The latest version is available at http://proxool.sourceforge.net */ package org.logicalcobwebs.proxool.admin.jmx; import org.logicalcobwebs.proxool.ProxoolConstants; import org.logicalcobwebs.proxool.ProxoolDriver; import org.logicalcobwebs.proxool.TestConstants; import org.logicalcobwebs.proxool.TestHelper; import org.logicalcobwebs.proxool.ProxoolFacade; import javax.management.MBeanServer; import javax.management.MBeanServerFactory; import javax.management.ObjectName; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; /** * Test {@link org.logicalcobwebs.proxool.admin.jmx.ConnectionPoolMBean} when JMX is configured for multiple agents. * * @version $Revision: 1.1 $, $Date: 2003/10/20 07:40:44 $ * @author Christian Nedregaard (chr...@em...) * @author $Author: chr32 $ (current maintainer) * @since Proxool 0.8 */ public class MultipleAgentsConnectionPoolMBeanTest extends AbstractJMXTest { private static final String AGENT1_DOMAIN = "testAgent1"; private static final String AGENT2_DOMAIN = "testAgent2"; private MBeanServer mBeanServer1; private MBeanServer mBeanServer2; private String mBeanServer1Id; private String mBeanServer2Id; /** * @see junit.framework.TestCase#TestCase(java.lang.String) */ public MultipleAgentsConnectionPoolMBeanTest(String s) { super(s); } /** * Test that pools can be regisered for multiple agents. * @throws Exception if the test fails in an unexpected way. */ public void testMultipleAgents() throws Exception { final String alias = "testMultipleAgents"; createMutipleAgentBasicPool(alias); final ObjectName objectName = ProxoolJMXHelper.getObjectName(alias); final String fatalSQLAttributeName = ProxoolJMXHelper.getValidIdentifier(ProxoolConstants.FATAL_SQL_EXCEPTION); String fatalSQLAttribtueValue = (String) mBeanServer1.getAttribute(objectName, fatalSQLAttributeName); assertTrue("Agent " + AGENT1_DOMAIN + " could not find " + fatalSQLAttribtueValue + " attribute.", fatalSQLAttribtueValue != null && fatalSQLAttribtueValue.trim().length() > 0); fatalSQLAttribtueValue = (String) mBeanServer2.getAttribute(objectName, fatalSQLAttributeName); assertTrue("Agent " + AGENT2_DOMAIN + " could not find " + fatalSQLAttribtueValue + " attribute.", fatalSQLAttribtueValue != null && fatalSQLAttribtueValue.trim().length() > 0); ProxoolFacade.removeConnectionPool(alias); } private Properties createMutipleAgentBasicPool(String alias) throws SQLException { final String url = TestHelper.buildProxoolUrl(alias, TestConstants.HYPERSONIC_DRIVER, TestConstants.HYPERSONIC_TEST_URL); final Properties info = createBasicProperties(alias); info.setProperty(ProxoolConstants.JMX_AGENT_PROPERTY, mBeanServer1Id + ", " + mBeanServer2Id); DriverManager.getConnection(url, info).close(); return info; } /** * Calls {@link org.logicalcobwebs.proxool.AbstractProxoolTest#setUp} * @see junit.framework.TestCase#setUp */ protected void setUp() throws Exception { Class.forName(ProxoolDriver.class.getName()); this.mBeanServer1 = MBeanServerFactory.createMBeanServer(AGENT1_DOMAIN); this.mBeanServer1Id = this.mBeanServer1.getAttribute( new ObjectName("JMImplementation:type=MBeanServerDelegate"), "MBeanServerId").toString(); this.mBeanServer2 = MBeanServerFactory.createMBeanServer(AGENT2_DOMAIN); this.mBeanServer2Id = this.mBeanServer2.getAttribute( new ObjectName("JMImplementation:type=MBeanServerDelegate"), "MBeanServerId").toString(); super.setUp(); } /** * Calls {@link org.logicalcobwebs.proxool.AbstractProxoolTest#tearDown} * @see junit.framework.TestCase#setUp */ protected void tearDown() throws Exception { MBeanServerFactory.releaseMBeanServer(this.mBeanServer1); MBeanServerFactory.releaseMBeanServer(this.mBeanServer2); this.mBeanServer1 = null; this.mBeanServer2 = null; super.tearDown(); } } /* Revision history: $Log: MultipleAgentsConnectionPoolMBeanTest.java,v $ Revision 1.1 2003/10/20 07:40:44 chr32 Improved tests. */ Index: AllTests.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java-test/org/logicalcobwebs/proxool/admin/jmx/AllTests.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AllTests.java 6 May 2003 23:17:12 -0000 1.4 --- AllTests.java 20 Oct 2003 07:40:44 -0000 1.5 *************** *** 28,31 **** --- 28,32 ---- TestSuite suite = new TestSuite(); suite.addTestSuite(ConnectionPoolMBeanTest.class); + suite.addTestSuite(MultipleAgentsConnectionPoolMBeanTest.class); // create a wrapper for global initialization code. *************** *** 43,46 **** --- 44,50 ---- Revision history: $Log$ + Revision 1.5 2003/10/20 07:40:44 chr32 + Improved tests. + Revision 1.4 2003/05/06 23:17:12 chr32 Moving JMX tests back in from sandbox. Index: ConnectionPoolMBeanTest.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java-test/org/logicalcobwebs/proxool/admin/jmx/ConnectionPoolMBeanTest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ConnectionPoolMBeanTest.java 6 May 2003 23:17:12 -0000 1.9 --- ConnectionPoolMBeanTest.java 20 Oct 2003 07:40:44 -0000 1.10 *************** *** 6,16 **** package org.logicalcobwebs.proxool.admin.jmx; - import org.logicalcobwebs.proxool.AbstractProxoolTest; import org.logicalcobwebs.proxool.ProxoolConstants; import org.logicalcobwebs.proxool.ProxoolDriver; import org.logicalcobwebs.proxool.ProxoolException; import org.logicalcobwebs.proxool.ProxoolFacade; - import org.logicalcobwebs.proxool.TestConstants; - import org.logicalcobwebs.proxool.TestHelper; import javax.management.Attribute; --- 6,13 ---- *************** *** 23,28 **** import javax.management.NotificationListener; import javax.management.ObjectName; - import java.sql.DriverManager; - import java.sql.SQLException; import java.util.Iterator; import java.util.Properties; --- 20,23 ---- *************** *** 37,41 **** * @since Proxool 0.8 */ ! public class ConnectionPoolMBeanTest extends AbstractProxoolTest { private MBeanServer mBeanServer; private boolean notified; --- 32,36 ---- * @since Proxool 0.8 */ ! public class ConnectionPoolMBeanTest extends AbstractJMXTest { private MBeanServer mBeanServer; private boolean notified; *************** *** 109,113 **** this.mBeanServer.setAttribute(objectName, new Attribute(fatalSQLAttributeName, newValue)); ! final String fatalSQLAttribtueValue = (String) mBeanServer.getAttribute(objectName, fatalSQLAttributeName); // check that value vas registered by the bean. assertTrue("Expexted fatalSQLException JMX attribtue to have value '" + newValue + "' but the value was '" --- 104,108 ---- this.mBeanServer.setAttribute(objectName, new Attribute(fatalSQLAttributeName, newValue)); ! String fatalSQLAttribtueValue = (String) mBeanServer.getAttribute(objectName, fatalSQLAttributeName); // check that value vas registered by the bean. assertTrue("Expexted fatalSQLException JMX attribtue to have value '" + newValue + "' but the value was '" *************** *** 120,123 **** --- 115,124 ---- + newValue + "' but the value was '" + proxoolProopertyValue + "'.", proxoolProopertyValue.equals(newValue)); + // check that string properites can be deleted. + this.mBeanServer.setAttribute(objectName, + new Attribute(fatalSQLAttributeName, "")); + fatalSQLAttribtueValue = (String) mBeanServer.getAttribute(objectName, fatalSQLAttributeName); + assertTrue("Expexted fatal-sql-exception Proxool property to be empty " + + " but the value was '" + fatalSQLAttribtueValue + "'.", "".equals(fatalSQLAttribtueValue)); ProxoolFacade.removeConnectionPool(alias); } *************** *** 165,169 **** try { ProxoolFacade.removeConnectionPool(alias); ! fail("Removal of pool alias should have failed, because it should have allready be removed."); } catch (ProxoolException e) { // we want this --- 166,170 ---- try { ProxoolFacade.removeConnectionPool(alias); ! fail("Removal of pool alias should have failed, because it should have already be removed."); } catch (ProxoolException e) { // we want this *************** *** 179,183 **** // test when updated through JMX. this.mBeanServer.setAttribute(objectName, ! new Attribute(ProxoolJMXHelper.getValidIdentifier(ProxoolConstants.FATAL_SQL_EXCEPTION), alias)); assertTrue("We did not get notified when updating through JMX.", this.notified); this.notified = false; --- 180,184 ---- // test when updated through JMX. this.mBeanServer.setAttribute(objectName, ! new Attribute(ProxoolJMXHelper.getValidIdentifier(ProxoolConstants.FATAL_SQL_EXCEPTION), "dingo")); assertTrue("We did not get notified when updating through JMX.", this.notified); this.notified = false; *************** *** 206,222 **** } - private Properties createBasicPool(String alias) throws SQLException { - String url = TestHelper.buildProxoolUrl(alias, - TestConstants.HYPERSONIC_DRIVER, - TestConstants.HYPERSONIC_TEST_URL); - Properties info = new Properties(); - info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); - info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); - info.setProperty(ProxoolConstants.JMX_PROPERTY, Boolean.TRUE.toString()); - info.setProperty(ProxoolConstants.FATAL_SQL_EXCEPTION_PROPERTY, alias); - DriverManager.getConnection(url, info).close(); - return info; - } - /** * Calls {@link org.logicalcobwebs.proxool.AbstractProxoolTest#setUp} --- 207,210 ---- *************** *** 244,247 **** --- 232,238 ---- Revision history: $Log$ + Revision 1.10 2003/10/20 07:40:44 chr32 + Improved tests. + Revision 1.9 2003/05/06 23:17:12 chr32 Moving JMX tests back in from sandbox. |