~ubuntu-branches/ubuntu/wily/libjboss-remoting-java/wily

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/transport/socket/deadlock/ShutdownDeadlockTestCase.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************
2
 
 *                                     *
3
 
 *  JBoss: The OpenSource J2EE WebOS   *
4
 
 *                                     *
5
 
 *  Distributable under LGPL license.  *
6
 
 *  See terms of license at gnu.org.   *
7
 
 *                                     *
8
 
 ***************************************/
9
 
package org.jboss.test.remoting.transport.socket.deadlock;
10
 
 
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;
19
 
 
20
 
import javax.management.MBeanServer;
21
 
 
22
 
/**
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>
32
 
 */
33
 
public class ShutdownDeadlockTestCase extends TestCase
34
 
{
35
 
   private String invokerLocatorUrl = getTransport() + "://localhost:" + getPort() + "/?" + InvokerLocator.FORCE_REMOTE + "=true";
36
 
 
37
 
   private Client shutdownClient;
38
 
   private Client invocationClient;
39
 
   private Connector connector;
40
 
 
41
 
   public void testDeadlock() throws Exception
42
 
   {
43
 
      xsetUP();
44
 
      xtestDeadlock();
45
 
      xtearDown();
46
 
   }
47
 
 
48
 
 
49
 
   public void xsetUP() throws Exception
50
 
   {
51
 
      connector = new Connector(invokerLocatorUrl);
52
 
      connector.create();
53
 
      connector.addInvocationHandler("test", new TestInvocationHandler());
54
 
      connector.start();
55
 
 
56
 
 
57
 
      shutdownClient = new Client(new InvokerLocator(invokerLocatorUrl));
58
 
      shutdownClient.connect();
59
 
 
60
 
      invocationClient = new Client(new InvokerLocator(invokerLocatorUrl));
61
 
      invocationClient.connect();
62
 
   }
63
 
 
64
 
   public void xtestDeadlock() throws Exception
65
 
   {
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() {
71
 
         public void run()
72
 
         {
73
 
            for(int x = 0; x < 10000; x++)
74
 
            {
75
 
               try
76
 
               {
77
 
                  aClient.invoke("foo");
78
 
               }
79
 
               catch (Throwable throwable)
80
 
               {
81
 
                  throwable.printStackTrace();
82
 
               }
83
 
            }
84
 
            aBuf.append("done");
85
 
            System.out.println("invocation client done");
86
 
         }
87
 
      });
88
 
 
89
 
      Thread b = new Thread(new Runnable() {
90
 
         public void run()
91
 
         {
92
 
            for(int i = 0; i < 100; i++)
93
 
            {
94
 
               try
95
 
               {
96
 
                  bClient.invoke("bla");
97
 
               }
98
 
               catch (Throwable throwable)
99
 
               {
100
 
                  throwable.printStackTrace();
101
 
               }
102
 
            }
103
 
            bClient.disconnect();
104
 
            bBuf.append("done");
105
 
            System.out.println("shutdown client done");
106
 
         }
107
 
      });
108
 
 
109
 
      a.start();
110
 
      b.start();
111
 
 
112
 
      Thread.currentThread().sleep(10000);
113
 
 
114
 
      System.out.println("aBuf done = " + ("done".equals(aBuf.toString())));
115
 
      System.out.println("bBuf done = " + ("done".equals(bBuf.toString())));
116
 
 
117
 
   }
118
 
 
119
 
   public void xtearDown()
120
 
   {
121
 
      if(connector != null)
122
 
      {
123
 
         connector.stop();
124
 
         connector.destroy();
125
 
      }
126
 
   }
127
 
 
128
 
   public static void main(String[] args)
129
 
   {
130
 
      ShutdownDeadlockTestCase test = new ShutdownDeadlockTestCase();
131
 
      try
132
 
      {
133
 
         test.testDeadlock();
134
 
      }
135
 
      catch (Exception e)
136
 
      {
137
 
         e.printStackTrace();
138
 
      }
139
 
   }
140
 
 
141
 
   protected String getTransport()
142
 
   {
143
 
      return "socket";
144
 
   }
145
 
   
146
 
   protected int getPort()
147
 
   {
148
 
      return 7798;
149
 
   }
150
 
   
151
 
   public class TestInvocationHandler implements ServerInvocationHandler
152
 
   {
153
 
 
154
 
      public void setMBeanServer(MBeanServer server)
155
 
      {
156
 
         //To change body of implemented methods use File | Settings | File Templates.
157
 
      }
158
 
 
159
 
      public void setInvoker(ServerInvoker invoker)
160
 
      {
161
 
         //To change body of implemented methods use File | Settings | File Templates.
162
 
      }
163
 
 
164
 
      public Object invoke(InvocationRequest invocation) throws Throwable
165
 
      {
166
 
         return "bar";
167
 
      }
168
 
 
169
 
      public void addListener(InvokerCallbackHandler callbackHandler)
170
 
      {
171
 
         //To change body of implemented methods use File | Settings | File Templates.
172
 
      }
173
 
 
174
 
      public void removeListener(InvokerCallbackHandler callbackHandler)
175
 
      {
176
 
         //To change body of implemented methods use File | Settings | File Templates.
177
 
      }
178
 
   }
179
 
}
 
 
b'\\ No newline at end of file'