Author: ron.sigal(a)jboss.com
Date: 2008-04-24 00:16:56 -0400 (Thu, 24 Apr 2008)
New Revision: 4051
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/metadata/MetadataTestCase.java
Log:
JBREM-930: Stop Connectors in finally clause.
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/metadata/MetadataTestCase.java
===================================================================
---
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/metadata/MetadataTestCase.java 2008-04-24
04:09:15 UTC (rev 4050)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/metadata/MetadataTestCase.java 2008-04-24
04:16:56 UTC (rev 4051)
@@ -24,6 +24,7 @@
import junit.framework.TestCase;
import org.apache.log4j.Level;
+import org.jboss.logging.XLevel;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.detection.ServerInvokerMetadata;
import org.jboss.remoting.detection.multicast.MulticastDetector;
@@ -43,8 +44,6 @@
import java.net.InetAddress;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.util.List;
/**
@@ -66,7 +65,7 @@
{
org.apache.log4j.BasicConfigurator.configure();
org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
-
org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG);
+
org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(XLevel.TRACE);
org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.FATAL);
MulticastDetector detector1 = new MulticastDetector();
@@ -74,55 +73,65 @@
Connector connector1 = new Connector();
Connector connector2 = new Connector();
-
- NetworkRegistry reg1 = setupServers(detector1, connector1);
- // need to register with the mbean server for notifications
- List mbeanServers
- = (List) AccessController.doPrivileged( new PrivilegedAction()
- {
- public Object run()
- {
- return MBeanServerFactory.findMBeanServer(null);
- }
- });
- MBeanServer mbeanSvr = (MBeanServer) mbeanServers.get(0);
- mbeanSvr.addNotificationListener(new
ObjectName("remoting:type=NetworkRegistry"),
- this, null, null);
+ try
+ {
+ NetworkRegistry reg1 = setupServers(detector1, connector1);
+ // need to register with the mbean server for notifications
+ List mbeanServers = (List) AccessController.doPrivileged( new
PrivilegedAction()
+ {
+ public Object run()
+ {
+ return MBeanServerFactory.findMBeanServer(null);
+ }
+ });
- NetworkRegistry reg2 = setupServers(detector2, connector2);
+ MBeanServer mbeanSvr = (MBeanServer) mbeanServers.get(0);
+ mbeanSvr.addNotificationListener(new
ObjectName("remoting:type=NetworkRegistry"),
+ this, null, null);
- // Need to allow heartbeat so have detection
- Thread.currentThread().sleep(2000);
+ NetworkRegistry reg2 = setupServers(detector2, connector2);
- //Should now have an entry for both of the registries
- int reg1Count = reg1.getServers().length;
- int reg2Count = reg2.getServers().length;
+ // Need to allow heartbeat so have detection
+ Thread.currentThread().sleep(2000);
- // Actual junit test
- assertTrue(reg1Count == 1 && reg2Count == 1);
+ //Should now have an entry for both of the registries
+ int reg1Count = reg1.getServers().length;
+ int reg2Count = reg2.getServers().length;
- if(reg1Count == 1 && reg2Count == 1)
- {
- System.out.println("PASSED - both registries have found the
detectors.");
+ if(reg1Count == 1 && reg2Count == 1)
+ {
+ System.out.println("PASSED - both registries have found the
detectors.");
+ }
+ else
+ {
+ System.out.println("FAILED - registries not populated with remote
detectors.");
+ }
+
+ // Actual junit test
+ assertTrue(reg1Count == 1 && reg2Count == 1);
+
+ // now check to make sure got the subsystem as expected
+ assertEquals("MOCK", subSystem);
}
- else
+ finally
{
- System.out.println("FAILED - registries not populated with remote
detectors.");
+ // stop the 2nd detector, so see if 1st one detects it is missing
+ if (connector1 != null)
+ {
+ connector1.stop();
+ connector1.destroy();
+ connector1 = null;
+ }
+ if (connector2 != null)
+ {
+ connector2.stop();
+ connector2.destroy();
+ connector2 = null;
+ }
+ if (detector1 != null) detector1.stop();
+ if (detector2 != null) detector2.stop();
}
-
- // now check to make sure got the subsystem as expected
- assertEquals("MOCK", subSystem);
-
- // stop the 2nd detector, so see if 1st one detects it is missing
- connector1.stop();
- connector1.destroy();
- connector1 = null;
- connector2.stop();
- connector2.destroy();
- connector2 = null;
- detector1.stop();
- detector2.stop();
//connector2.stop();
//connector2.destroy();
}
Show replies by date