1 8 9 package test.mx4j.tools.remote; 10 11 import java.io.IOException ; 12 import java.util.Set ; 13 import javax.management.MBeanServerConnection ; 14 import javax.management.remote.JMXConnector ; 15 import javax.management.remote.JMXConnectorFactory ; 16 import javax.management.remote.JMXConnectorServer ; 17 import javax.management.remote.JMXConnectorServerFactory ; 18 import javax.management.remote.JMXServiceURL ; 19 20 import test.javax.management.remote.JMXConnectorServerTestCase; 21 22 25 public abstract class HTTPConnectorServerTestCase extends JMXConnectorServerTestCase 26 { 27 public HTTPConnectorServerTestCase(String name) 28 { 29 super(name); 30 } 31 32 public void testTwoConnectorServersOneHTTPServerStart1Start2Invoke1Invoke2Stop1Stop2() throws Exception 33 { 34 JMXServiceURL temp = createJMXConnectorServerAddress(); 35 JMXServiceURL url1 = new JMXServiceURL (temp.getProtocol(), temp.getHost(), temp.getPort(), "one"); 36 JMXServiceURL url2 = new JMXServiceURL (temp.getProtocol(), temp.getHost(), temp.getPort(), "two"); 37 38 JMXConnectorServer cntorServer1 = null; 39 JMXConnectorServer cntorServer2 = null; 40 41 try 42 { 43 cntorServer1 = JMXConnectorServerFactory.newJMXConnectorServer(url1, getEnvironment(), newMBeanServer()); 44 cntorServer2 = JMXConnectorServerFactory.newJMXConnectorServer(url2, getEnvironment(), newMBeanServer()); 45 46 cntorServer1.start(); 47 sleep(5000); 48 cntorServer2.start(); 49 sleep(5000); 50 51 JMXConnector cntor1 = null; 53 JMXConnector cntor2 = null; 54 try 55 { 56 cntor1 = JMXConnectorFactory.connect(cntorServer1.getAddress(), getEnvironment()); 57 cntor2 = JMXConnectorFactory.connect(cntorServer2.getAddress(), getEnvironment()); 58 59 Set names = cntor1.getMBeanServerConnection().queryNames(null, null); 60 assertNotNull(names); 61 assertTrue(names.size() > 0); 62 63 names = cntor2.getMBeanServerConnection().queryNames(null, null); 64 assertNotNull(names); 65 assertTrue(names.size() > 0); 66 } 67 finally 68 { 69 if (cntor2 != null) cntor2.close(); 70 if (cntor1 != null) cntor1.close(); 71 } 72 } 73 finally 74 { 75 if (cntorServer2 != null) cntorServer2.stop(); 76 if (cntorServer1 != null) cntorServer1.stop(); 77 } 78 } 79 80 public void testTwoConnectorServersOneHTTPServerStart1Start2Stop1Invoke1Invoke2Stop2() throws Exception 81 { 82 JMXServiceURL temp = createJMXConnectorServerAddress(); 83 JMXServiceURL url1 = new JMXServiceURL (temp.getProtocol(), temp.getHost(), temp.getPort(), "one"); 84 JMXServiceURL url2 = new JMXServiceURL (temp.getProtocol(), temp.getHost(), temp.getPort(), "two"); 85 86 JMXConnectorServer cntorServer1 = null; 87 JMXConnectorServer cntorServer2 = null; 88 89 try 90 { 91 cntorServer1 = JMXConnectorServerFactory.newJMXConnectorServer(url1, getEnvironment(), newMBeanServer()); 92 cntorServer2 = JMXConnectorServerFactory.newJMXConnectorServer(url2, getEnvironment(), newMBeanServer()); 93 94 cntorServer1.start(); 95 sleep(5000); 96 cntorServer2.start(); 97 sleep(5000); 98 99 JMXConnector cntor1 = null; 101 JMXConnector cntor2 = null; 102 try 103 { 104 cntor1 = JMXConnectorFactory.connect(cntorServer1.getAddress(), getEnvironment()); 105 cntor2 = JMXConnectorFactory.connect(cntorServer2.getAddress(), getEnvironment()); 106 107 MBeanServerConnection conn1 = cntor1.getMBeanServerConnection(); 108 Set names = conn1.queryNames(null, null); 109 assertNotNull(names); 110 assertTrue(names.size() > 0); 111 112 MBeanServerConnection conn2 = cntor2.getMBeanServerConnection(); 113 names = conn2.queryNames(null, null); 114 assertNotNull(names); 115 assertTrue(names.size() > 0); 116 117 cntorServer1.stop(); 118 119 try 120 { 121 conn1.queryNames(null, null); 122 fail(); 123 } 124 catch (IOException ignored) 125 { 126 } 127 128 names = conn2.queryNames(null, null); 129 assertNotNull(names); 130 assertTrue(names.size() > 0); 131 } 132 catch (Exception x) 133 { 134 x.printStackTrace(); 135 throw x; 136 } 137 finally 138 { 139 if (cntor2 != null) cntor2.close(); 140 } 141 } 142 finally 143 { 144 if (cntorServer2 != null) cntorServer2.stop(); 145 } 146 } 147 148 public void testConnectorServerOnDefaultHTTPPort() throws Exception 149 { 150 JMXServiceURL temp = createJMXConnectorServerAddress(); 151 JMXServiceURL url = new JMXServiceURL (temp.getProtocol(), temp.getHost(), 80, temp.getURLPath()); 152 JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), newMBeanServer()); 153 154 try 155 { 156 cntorServer.start(); 157 sleep(5000); 158 JMXConnector cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment()); 159 try 160 { 161 MBeanServerConnection server = cntor.getMBeanServerConnection(); 162 Set names = server.queryNames(null, null); 163 assertNotNull(names); 164 assertTrue(names.size() > 0); 165 assertEquals(names.size(), server.getMBeanCount().intValue()); 166 } 167 finally 168 { 169 cntor.close(); 170 } 171 } 172 finally 173 { 174 cntorServer.stop(); 175 } 176 } 177 178 public void testStartWithProviderClassLoader() throws Exception 179 { 180 } 182 } 183 | Popular Tags |