KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > proxool > admin > jmx > MultipleAgentsConnectionPoolMBeanTest


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.proxool.admin.jmx;
7
8 import org.logicalcobwebs.proxool.ProxoolConstants;
9 import org.logicalcobwebs.proxool.ProxoolDriver;
10 import org.logicalcobwebs.proxool.TestConstants;
11 import org.logicalcobwebs.proxool.TestHelper;
12 import org.logicalcobwebs.proxool.ProxoolFacade;
13
14 import javax.management.MBeanServer JavaDoc;
15 import javax.management.MBeanServerFactory JavaDoc;
16 import javax.management.ObjectName JavaDoc;
17
18 import java.sql.DriverManager JavaDoc;
19 import java.sql.SQLException JavaDoc;
20 import java.util.Properties JavaDoc;
21
22
23 /**
24  * Test {@link org.logicalcobwebs.proxool.admin.jmx.ConnectionPoolMBean} when JMX is configured for multiple agents.
25  *
26  * @version $Revision: 1.1 $, $Date: 2003/10/20 07:40:44 $
27  * @author Christian Nedregaard (christian_nedregaard@email.com)
28  * @author $Author: chr32 $ (current maintainer)
29  * @since Proxool 0.8
30  */

31 public class MultipleAgentsConnectionPoolMBeanTest extends AbstractJMXTest {
32     private static final String JavaDoc AGENT1_DOMAIN = "testAgent1";
33     private static final String JavaDoc AGENT2_DOMAIN = "testAgent2";
34     private MBeanServer JavaDoc mBeanServer1;
35     private MBeanServer JavaDoc mBeanServer2;
36     private String JavaDoc mBeanServer1Id;
37     private String JavaDoc mBeanServer2Id;
38
39     /**
40      * @see junit.framework.TestCase#TestCase(java.lang.String)
41      */

42     public MultipleAgentsConnectionPoolMBeanTest(String JavaDoc s) {
43         super(s);
44     }
45
46
47     /**
48      * Test that pools can be regisered for multiple agents.
49      * @throws Exception if the test fails in an unexpected way.
50      */

51     public void testMultipleAgents() throws Exception JavaDoc {
52         final String JavaDoc alias = "testMultipleAgents";
53         createMutipleAgentBasicPool(alias);
54         final ObjectName JavaDoc objectName = ProxoolJMXHelper.getObjectName(alias);
55         final String JavaDoc fatalSQLAttributeName = ProxoolJMXHelper.getValidIdentifier(ProxoolConstants.FATAL_SQL_EXCEPTION);
56         String JavaDoc fatalSQLAttribtueValue = (String JavaDoc) mBeanServer1.getAttribute(objectName, fatalSQLAttributeName);
57         assertTrue("Agent " + AGENT1_DOMAIN + " could not find " + fatalSQLAttribtueValue
58                 + " attribute.", fatalSQLAttribtueValue != null && fatalSQLAttribtueValue.trim().length() > 0);
59         fatalSQLAttribtueValue = (String JavaDoc) mBeanServer2.getAttribute(objectName, fatalSQLAttributeName);
60         assertTrue("Agent " + AGENT2_DOMAIN + " could not find " + fatalSQLAttribtueValue
61                 + " attribute.", fatalSQLAttribtueValue != null && fatalSQLAttribtueValue.trim().length() > 0);
62         ProxoolFacade.removeConnectionPool(alias);
63     }
64
65     private Properties JavaDoc createMutipleAgentBasicPool(String JavaDoc alias) throws SQLException JavaDoc {
66         final String JavaDoc url = TestHelper.buildProxoolUrl(alias,
67                 TestConstants.HYPERSONIC_DRIVER,
68                 TestConstants.HYPERSONIC_TEST_URL);
69         final Properties JavaDoc info = createBasicProperties(alias);
70         info.setProperty(ProxoolConstants.JMX_AGENT_PROPERTY, mBeanServer1Id + ", " + mBeanServer2Id);
71         DriverManager.getConnection(url, info).close();
72         return info;
73     }
74
75     /**
76      * Calls {@link org.logicalcobwebs.proxool.AbstractProxoolTest#setUp}
77      * @see junit.framework.TestCase#setUp
78      */

79     protected void setUp() throws Exception JavaDoc {
80         Class.forName(ProxoolDriver.class.getName());
81         this.mBeanServer1 = MBeanServerFactory.createMBeanServer(AGENT1_DOMAIN);
82         this.mBeanServer1Id = this.mBeanServer1.getAttribute(
83             new ObjectName JavaDoc("JMImplementation:type=MBeanServerDelegate"), "MBeanServerId").toString();
84         this.mBeanServer2 = MBeanServerFactory.createMBeanServer(AGENT2_DOMAIN);
85         this.mBeanServer2Id = this.mBeanServer2.getAttribute(
86             new ObjectName JavaDoc("JMImplementation:type=MBeanServerDelegate"), "MBeanServerId").toString();
87         super.setUp();
88     }
89
90     /**
91      * Calls {@link org.logicalcobwebs.proxool.AbstractProxoolTest#tearDown}
92      * @see junit.framework.TestCase#setUp
93      */

94     protected void tearDown() throws Exception JavaDoc {
95         MBeanServerFactory.releaseMBeanServer(this.mBeanServer1);
96         MBeanServerFactory.releaseMBeanServer(this.mBeanServer2);
97         this.mBeanServer1 = null;
98         this.mBeanServer2 = null;
99         super.tearDown();
100     }
101 }
102
103 /*
104  Revision history:
105  $Log: MultipleAgentsConnectionPoolMBeanTest.java,v $
106  Revision 1.1 2003/10/20 07:40:44 chr32
107  Improved tests.
108
109  */

110
Popular Tags