1 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 ; 15 import javax.management.MBeanServerFactory ; 16 import javax.management.ObjectName ; 17 18 import java.sql.DriverManager ; 19 import java.sql.SQLException ; 20 import java.util.Properties ; 21 22 23 31 public class MultipleAgentsConnectionPoolMBeanTest extends AbstractJMXTest { 32 private static final String AGENT1_DOMAIN = "testAgent1"; 33 private static final String AGENT2_DOMAIN = "testAgent2"; 34 private MBeanServer mBeanServer1; 35 private MBeanServer mBeanServer2; 36 private String mBeanServer1Id; 37 private String mBeanServer2Id; 38 39 42 public MultipleAgentsConnectionPoolMBeanTest(String s) { 43 super(s); 44 } 45 46 47 51 public void testMultipleAgents() throws Exception { 52 final String alias = "testMultipleAgents"; 53 createMutipleAgentBasicPool(alias); 54 final ObjectName objectName = ProxoolJMXHelper.getObjectName(alias); 55 final String fatalSQLAttributeName = ProxoolJMXHelper.getValidIdentifier(ProxoolConstants.FATAL_SQL_EXCEPTION); 56 String fatalSQLAttribtueValue = (String ) mBeanServer1.getAttribute(objectName, fatalSQLAttributeName); 57 assertTrue("Agent " + AGENT1_DOMAIN + " could not find " + fatalSQLAttribtueValue 58 + " attribute.", fatalSQLAttribtueValue != null && fatalSQLAttribtueValue.trim().length() > 0); 59 fatalSQLAttribtueValue = (String ) 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 createMutipleAgentBasicPool(String alias) throws SQLException { 66 final String url = TestHelper.buildProxoolUrl(alias, 67 TestConstants.HYPERSONIC_DRIVER, 68 TestConstants.HYPERSONIC_TEST_URL); 69 final Properties info = createBasicProperties(alias); 70 info.setProperty(ProxoolConstants.JMX_AGENT_PROPERTY, mBeanServer1Id + ", " + mBeanServer2Id); 71 DriverManager.getConnection(url, info).close(); 72 return info; 73 } 74 75 79 protected void setUp() throws Exception { 80 Class.forName(ProxoolDriver.class.getName()); 81 this.mBeanServer1 = MBeanServerFactory.createMBeanServer(AGENT1_DOMAIN); 82 this.mBeanServer1Id = this.mBeanServer1.getAttribute( 83 new ObjectName ("JMImplementation:type=MBeanServerDelegate"), "MBeanServerId").toString(); 84 this.mBeanServer2 = MBeanServerFactory.createMBeanServer(AGENT2_DOMAIN); 85 this.mBeanServer2Id = this.mBeanServer2.getAttribute( 86 new ObjectName ("JMImplementation:type=MBeanServerDelegate"), "MBeanServerId").toString(); 87 super.setUp(); 88 } 89 90 94 protected void tearDown() throws Exception { 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 110 | Popular Tags |