1
/***************************************
3
* JBoss: The OpenSource J2EE WebOS *
5
* Distributable under LGPL license. *
6
* See terms of license at gnu.org. *
8
***************************************/
9
package org.jboss.test.remoting.transport.socket.deadlock;
11
import junit.framework.TestCase;
12
import org.jboss.remoting.Client;
13
import org.jboss.remoting.InvocationRequest;
14
import org.jboss.remoting.InvokerLocator;
15
import org.jboss.remoting.ServerInvocationHandler;
16
import org.jboss.remoting.ServerInvoker;
17
import org.jboss.remoting.callback.InvokerCallbackHandler;
18
import org.jboss.remoting.transport.Connector;
20
import javax.management.MBeanServer;
23
* This test case is for JBREM-576.
24
* Test trys to catch deadlock in shutdown where socket client
25
* invoker being use my multiple Clients. Need one client making
26
* invocations (which will cause sync on pool) and another to
27
* shutdown, which will cause disconnect on socket client invoker,
28
* thus causing it to sync on pool for clearing out the pool.
29
* Since this is an issue of multithreading, is certainly possible
30
* this test will pass even though the deadlock issue still exists.
31
* @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
33
public class ShutdownDeadlockTestCase extends TestCase
35
private String invokerLocatorUrl = getTransport() + "://localhost:" + getPort() + "/?" + InvokerLocator.FORCE_REMOTE + "=true";
37
private Client shutdownClient;
38
private Client invocationClient;
39
private Connector connector;
41
public void testDeadlock() throws Exception
49
public void xsetUP() throws Exception
51
connector = new Connector(invokerLocatorUrl);
53
connector.addInvocationHandler("test", new TestInvocationHandler());
57
shutdownClient = new Client(new InvokerLocator(invokerLocatorUrl));
58
shutdownClient.connect();
60
invocationClient = new Client(new InvokerLocator(invokerLocatorUrl));
61
invocationClient.connect();
64
public void xtestDeadlock() throws Exception
66
final Client aClient = invocationClient;
67
final StringBuffer aBuf = new StringBuffer();
68
final Client bClient = shutdownClient;
69
final StringBuffer bBuf = new StringBuffer();
70
Thread a = new Thread(new Runnable() {
73
for(int x = 0; x < 10000; x++)
77
aClient.invoke("foo");
79
catch (Throwable throwable)
81
throwable.printStackTrace();
85
System.out.println("invocation client done");
89
Thread b = new Thread(new Runnable() {
92
for(int i = 0; i < 100; i++)
96
bClient.invoke("bla");
98
catch (Throwable throwable)
100
throwable.printStackTrace();
103
bClient.disconnect();
105
System.out.println("shutdown client done");
112
Thread.currentThread().sleep(10000);
114
System.out.println("aBuf done = " + ("done".equals(aBuf.toString())));
115
System.out.println("bBuf done = " + ("done".equals(bBuf.toString())));
119
public void xtearDown()
121
if(connector != null)
128
public static void main(String[] args)
130
ShutdownDeadlockTestCase test = new ShutdownDeadlockTestCase();
141
protected String getTransport()
146
protected int getPort()
151
public class TestInvocationHandler implements ServerInvocationHandler
154
public void setMBeanServer(MBeanServer server)
156
//To change body of implemented methods use File | Settings | File Templates.
159
public void setInvoker(ServerInvoker invoker)
161
//To change body of implemented methods use File | Settings | File Templates.
164
public Object invoke(InvocationRequest invocation) throws Throwable
169
public void addListener(InvokerCallbackHandler callbackHandler)
171
//To change body of implemented methods use File | Settings | File Templates.
174
public void removeListener(InvokerCallbackHandler callbackHandler)
176
//To change body of implemented methods use File | Settings | File Templates.
b'\\ No newline at end of file'