46
48
private static final String contextName = "/foo";
50
private static final String ADDRESS;
55
address = InetAddress.getByName("localhost").getHostAddress();
56
} catch (UnknownHostException e) {
57
address = "INIT_FAILED";
48
63
private static String[] basicMBeanNames() {
49
64
return new String[] {
50
65
"Tomcat:type=Engine",
66
"Tomcat:type=Realm,realmPath=/realm0",
51
67
"Tomcat:type=MBeanFactory",
52
68
"Tomcat:type=NamingResources",
53
69
"Tomcat:type=Server",
96
112
private static String[] connectorMBeanNames(String port, String type) {
97
113
return new String[] {
98
"Tomcat:type=Connector,port=" + port,
99
"Tomcat:type=GlobalRequestProcessor,name=\"http-" + type + "-" + port + "\"",
100
"Tomcat:type=Mapper,port=" + port,
101
"Tomcat:type=ProtocolHandler,port=" + port,
102
"Tomcat:type=ThreadPool,name=\"http-" + type + "-" + port + "\"",
114
"Tomcat:type=Connector,port=" + port + ",address="
115
+ ObjectName.quote(ADDRESS),
116
"Tomcat:type=GlobalRequestProcessor,name="
117
+ ObjectName.quote("http-" + type + "-" + ADDRESS + "-" + port),
118
"Tomcat:type=Mapper,port=" + port + ",address="
119
+ ObjectName.quote(ADDRESS),
120
"Tomcat:type=ProtocolHandler,port=" + port + ",address="
121
+ ObjectName.quote(ADDRESS),
122
"Tomcat:type=ThreadPool,name="
123
+ ObjectName.quote("http-" + type + "-" + ADDRESS + "-" + port),
112
133
public void testMBeanDeregistration() throws Exception {
113
134
final MBeanServer mbeanServer = Registry.getRegistry(null, null).getMBeanServer();
135
// Verify there are no Catalina or Tomcat MBeans
114
136
Set<ObjectName> onames = mbeanServer.queryNames(new ObjectName("Catalina:*"), null);
115
assertEquals("Remaining: " + onames, 0, onames.size());
137
log.info(MBeanDumper.dumpBeans(mbeanServer, onames));
138
assertEquals("Unexpected: " + onames, 0, onames.size());
139
onames = mbeanServer.queryNames(new ObjectName("Tomcat:*"), null);
140
log.info(MBeanDumper.dumpBeans(mbeanServer, onames));
141
assertEquals("Unexpected: " + onames, 0, onames.size());
117
143
final Tomcat tomcat = getTomcatInstance();
118
144
final File contextDir = new File(getTemporaryDirectory(), "webappFoo");
126
152
// Verify there are no Catalina MBeans
127
153
onames = mbeanServer.queryNames(new ObjectName("Catalina:*"), null);
154
log.info(MBeanDumper.dumpBeans(mbeanServer, onames));
128
155
assertEquals("Found: " + onames, 0, onames.size());
130
157
// Verify there are the correct Tomcat MBeans
147
174
ArrayList<String> expected = new ArrayList<String>(Arrays.asList(basicMBeanNames()));
148
175
expected.addAll(Arrays.asList(hostMBeanNames("localhost")));
149
176
expected.addAll(Arrays.asList(contextMBeanNames("localhost", contextName)));
150
expected.addAll(Arrays.asList(connectorMBeanNames(Integer.toString(getPort()), protocol)));
177
expected.addAll(Arrays.asList(connectorMBeanNames("auto-1", protocol)));
151
178
expected.addAll(Arrays.asList(optionalMBeanNames("localhost")));
153
180
// Did we find all expected MBeans?
185
212
// There should be no Catalina MBeans and no Tomcat MBeans
186
213
onames = mbeanServer.queryNames(new ObjectName("Catalina:*"), null);
214
log.info(MBeanDumper.dumpBeans(mbeanServer, onames));
187
215
assertEquals("Remaining: " + onames, 0, onames.size());
188
216
onames = mbeanServer.queryNames(new ObjectName("Tomcat:*"), null);
217
log.info(MBeanDumper.dumpBeans(mbeanServer, onames));
189
218
assertEquals("Remaining: " + onames, 0, onames.size());