Author: ron.sigal(a)jboss.com
Date: 2008-04-29 03:21:54 -0400 (Tue, 29 Apr 2008)
New Revision: 4092
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/metadata/MetadataTestCase.java
Log:
JBREM-930: Account for possibility that extraneous servers might be discovered.
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-29
06:37:37 UTC (rev 4091)
+++
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/metadata/MetadataTestCase.java 2008-04-29
07:21:54 UTC (rev 4092)
@@ -25,9 +25,15 @@
import junit.framework.TestCase;
import org.apache.log4j.Level;
import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
import org.jboss.remoting.detection.ServerInvokerMetadata;
import org.jboss.remoting.detection.multicast.MulticastDetector;
+import org.jboss.remoting.network.NetworkInstance;
import org.jboss.remoting.network.NetworkNotification;
import org.jboss.remoting.network.NetworkRegistry;
import org.jboss.remoting.transport.Connector;
@@ -45,6 +51,7 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.List;
+import java.util.Random;
/**
* Just tests that detector A sees detector B when B comes online then off.
@@ -54,6 +61,8 @@
*/
public class MetadataTestCase extends TestCase implements NotificationListener
{
+ private static int secret = Math.abs(new Random().nextInt(2000));
+
private String subSystem = null;
public MetadataTestCase(String name)
@@ -98,10 +107,12 @@
//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("registry 1: " + reg1Count);
+ System.out.println("registry 2: " + reg2Count);
+
+ if(reg1Count >= 1 && reg2Count >= 1)
{
- System.out.println("PASSED - both registries have found the
detectors.");
+ System.out.println("PASSED - both registries have found
detectors.");
}
else
{
@@ -109,7 +120,11 @@
}
// Actual junit test
- assertTrue(reg1Count == 1 && reg2Count == 1);
+ assertTrue(reg1Count >= 1 && reg2Count >= 1);
+
+ // Verify the Connectors created by this test have been detected.
+ checkForConnector(reg1);
+ checkForConnector(reg2);
// now check to make sure got the subsystem as expected
assertEquals("MOCK", subSystem);
@@ -162,7 +177,7 @@
StringBuffer buf = new StringBuffer();
buf.append("<?xml version=\"1.0\"?>\n");
buf.append("<handlers>\n");
- buf.append(" <handler
subsystem=\"mock\">org.jboss.test.remoting.transport.mock.MockServerInvocationHandler</handler>\n");
+ buf.append(" <handler subsystem=\"mock\">" +
TestInvocationHandler.class.getName() + "</handler>\n");
buf.append("</handlers>\n");
Document xml =
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new
ByteArrayInputStream(buf.toString().getBytes()));
connector.setInvokerLocator(locator.getLocatorURI());
@@ -198,6 +213,36 @@
}
}
+ private boolean checkForConnector(NetworkRegistry registry)
+ {
+ boolean found = false;
+ NetworkInstance[] servers1 = registry.getServers();
+ for (int i = 0; i < servers1.length; i++)
+ {
+ InvokerLocator[] locators = servers1[i].getLocators();
+ for (int j = 0; j < locators.length; j++)
+ {
+ try
+ {
+ Client client = new Client(locators[j]);
+ client.connect();
+ if (secret == ((Integer) client.invoke("abc")).intValue())
+ {
+ found = true;
+ System.out.println("FOUND: " + locators[j]);
+ break;
+ }
+ }
+ catch (Throwable t)
+ {
+ continue;
+ }
+ }
+ }
+
+ return found;
+ }
+
private static class TestNetworkRegistry extends NetworkRegistry
{
public static NetworkRegistry createNetworkRegistry()
@@ -206,4 +251,15 @@
}
}
+ public static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return new Integer(secret);
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
}
Show replies by date