[jboss-cvs] JBossRemoting/src/tests/org/jboss/test/remoting/detection/multicast/deadlock ...
Tom Elrod
tom.elrod at jboss.com
Fri Jul 21 16:02:22 EDT 2006
User: telrod
Date: 06/07/21 16:02:22
Added: src/tests/org/jboss/test/remoting/detection/multicast/deadlock
DeadlockTestCase.java MulticastDetectorClient.java
MulticastDetectorServer.java
Log:
JBREM-553 - adding test case to try to reproduce.
Revision Changes Path
1.1 date: 2006/07/21 20:02:22; author: telrod; state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/detection/multicast/deadlock/DeadlockTestCase.java
Index: DeadlockTestCase.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.remoting.detection.multicast.deadlock;
import junit.framework.TestCase;
/**
* Test for JBREM-553
* @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
*/
public class DeadlockTestCase extends TestCase
{
public static void main(String[] args)
{
DeadlockTestCase test = new DeadlockTestCase();
try
{
test.testForDeadlock();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void testForDeadlock() throws Exception
{
MulticastDetectorServer server = new MulticastDetectorServer();
MulticastDetectorClient client = new MulticastDetectorClient();
try
{
server.setUp();
client.setUp();
client.testDetection();
}
finally
{
client.tearDown();
server.tearDown();
}
}
}
1.1 date: 2006/07/21 20:02:22; author: telrod; state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/detection/multicast/deadlock/MulticastDetectorClient.java
Index: MulticastDetectorClient.java
===================================================================
package org.jboss.test.remoting.detection.multicast.deadlock;
import junit.framework.TestCase;
import org.jboss.remoting.Client;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.detection.multicast.MulticastDetector;
import org.jboss.remoting.network.NetworkInstance;
import org.jboss.remoting.network.NetworkRegistry;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
/**
* Test for JBREM-553
* @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
*/
public class MulticastDetectorClient extends TestCase
{
private MulticastDetector detector;
private NetworkRegistry registry;
public void setUp() throws Exception
{
detector = new MulticastDetector();
System.setProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
System.out.println("jboss.identity = " + System.getProperty("jboss.identity"));
MBeanServer server = MBeanServerFactory.createMBeanServer();
registry = NetworkRegistry.getInstance();
server.registerMBean(registry, new ObjectName("remoting:type=NetworkRegistry"));
//Need to set new domain for identity
server.registerMBean(detector, new ObjectName("remoting:type=JNDIDetector"));
}
public void testDetection() throws Exception
{
detector.start();
long start = System.currentTimeMillis();
NetworkInstance[] instances = detector.forceDetection();
long end = System.currentTimeMillis();
System.out.println("instance = " + instances);
System.out.println("force detection took " + (end - start) + " milliseconds.");
// assertEquals(1, instances.length);
// now create a client
NetworkInstance ni = instances[0];
InvokerLocator[] locator = ni.getLocators();
InvokerLocator serverLocator = locator[0];
Client remotingClient = new Client(serverLocator);
remotingClient.connect();
try
{
Object ret = remotingClient.invoke("foobar");
System.out.println("return from calling server is " + ret);
}
catch (Throwable throwable)
{
throwable.printStackTrace();
throw new Exception(throwable.getMessage());
}
Thread.currentThread().sleep(10000);
System.out.println("Disconnecting.");
remotingClient.disconnect();
System.out.println("Disconnected.");
}
public void tearDown() throws Exception
{
if (detector != null)
{
detector.stop();
}
}
}
1.1 date: 2006/07/21 20:02:22; author: telrod; state: Exp;JBossRemoting/src/tests/org/jboss/test/remoting/detection/multicast/deadlock/MulticastDetectorServer.java
Index: MulticastDetectorServer.java
===================================================================
package org.jboss.test.remoting.detection.multicast.deadlock;
import org.apache.log4j.Level;
import org.jboss.jrunit.extensions.ServerTestCase;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.detection.multicast.MulticastDetector;
import org.jboss.remoting.network.NetworkRegistry;
import org.jboss.remoting.transport.Connector;
import org.jboss.test.remoting.TestUtil;
import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
/**
* Test for JBREM-553
* @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
*/
public class MulticastDetectorServer extends ServerTestCase
{
private MulticastDetector detector;
private Connector connector;
private NetworkRegistry registry;
public void setUp() throws Exception
{
detector = new MulticastDetector();
System.setProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
System.out.println("jboss.identity = " + System.getProperty("jboss.identity"));
MBeanServer server = MBeanServerFactory.createMBeanServer();
registry = NetworkRegistry.getInstance();
server.registerMBean(registry, new ObjectName("remoting:type=NetworkRegistry"));
int port = TestUtil.getRandomPort();
System.out.println("port = " + port);
InvokerLocator locator = new InvokerLocator("socket://localhost:" + port);
System.out.println("Starting remoting server with locator uri of: " + locator.getLocatorURI());
connector = new Connector();
connector.setInvokerLocator(locator.getLocatorURI());
connector.create();
MockServerInvocationHandler handler = new MockServerInvocationHandler();
connector.addInvocationHandler("mock", handler);
ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + locator.getProtocol());
server.registerMBean(connector, obj);
connector.start();
//Need to set new domain for identity
server.registerMBean(detector, new ObjectName("remoting:type=MulticastDetector"));
detector.start();
}
public void tearDown() throws Exception
{
if (detector != null)
{
detector.stop();
}
if (connector != null)
{
connector.stop();
connector.destroy();
}
}
public static void main(String[] args)
{
org.apache.log4j.BasicConfigurator.configure();
org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
try
{
MulticastDetectorServer test = new MulticastDetectorServer();
test.setUp();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
More information about the jboss-cvs-commits
mailing list