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

« back to all changes in this revision

Viewing changes to .pc/0001-convert-to-official-Java-concurrent-packages.patch/src/tests/org/jboss/test/remoting/transport/socket/timeout/idle/IdleTimeoutClientTest.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
package org.jboss.test.remoting.transport.socket.timeout.idle;
 
2
 
 
3
import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
 
4
import junit.framework.TestCase;
 
5
import org.apache.log4j.Logger;
 
6
import org.jboss.remoting.Client;
 
7
import org.jboss.remoting.InvokerLocator;
 
8
 
 
9
/**
 
10
 * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
 
11
 */
 
12
public class IdleTimeoutClientTest extends TestCase
 
13
{
 
14
 
 
15
//   private static int numOfRunnerThreads = 10;
 
16
   private static int numOfRunnerThreads = 2;
 
17
   private static SynchronizedInt responseCount = new SynchronizedInt(0);
 
18
 
 
19
   private Logger logger = Logger.getRootLogger();
 
20
   
 
21
   protected String getTransport()
 
22
   {
 
23
      return "socket";
 
24
   }
 
25
 
 
26
   public static void main(String[] args) throws Throwable
 
27
   {
 
28
      IdleTimeoutClientTest rt = new IdleTimeoutClientTest();
 
29
//      rt.runMultipleClients(Integer.parseInt(args[1]));
 
30
      rt.runMultipleClients(numOfRunnerThreads);
 
31
   }
 
32
 
 
33
   public void testRunClients() throws Throwable
 
34
   {
 
35
      String locatorURI = getTransport() + "://localhost:54000/?clientMaxPoolSize=50&timeout=10000";
 
36
      InvokerLocator locator = new InvokerLocator(locatorURI);
 
37
      Client client = new Client(locator);
 
38
      client.connect();
 
39
      Object resp = client.invoke(Boolean.TRUE);
 
40
      Boolean isFirst = (Boolean)resp;
 
41
      System.out.println("client is first = " + isFirst);
 
42
 
 
43
      Thread.currentThread().sleep(10000);
 
44
 
 
45
      if(isFirst.booleanValue())
 
46
      {
 
47
          Thread.currentThread().sleep(10000);
 
48
      }
 
49
 
 
50
      runMultipleClients(numOfRunnerThreads);
 
51
      Thread.currentThread().sleep(30000);
 
52
      System.out.println("done with first timeout.");
 
53
      runMultipleClients(numOfRunnerThreads);
 
54
      Thread.currentThread().sleep(12000);
 
55
 
 
56
      System.out.println("response count = " + responseCount.get());
 
57
      assertEquals(4, responseCount.get());
 
58
   }
 
59
 
 
60
   public void runClient(String clientId) throws Throwable
 
61
   {
 
62
      String locatorURI = "socket://localhost:54000/?clientMaxPoolSize=50&timeout=10000";
 
63
      InvokerLocator locator = new InvokerLocator(locatorURI);
 
64
      Client client = new Client(locator);
 
65
      client.connect();
 
66
      String req = clientId;
 
67
      Object resp = client.invoke(req);
 
68
      responseCount.increment();
 
69
      System.out.println("Received response of: " + resp + ".  Response count = " + responseCount);
 
70
   }
 
71
 
 
72
      public void runMultipleClients(int cnt) throws Throwable {
 
73
      for (int i = 0; i < cnt; i++) {
 
74
         Thread t = new Thread(new Runnable() {
 
75
            public void run() {
 
76
               try {
 
77
                  Thread.sleep(1000);
 
78
                  runClient(Thread.currentThread().getName());
 
79
               } catch (Throwable e) {
 
80
                  logger.error(e);
 
81
                  e.printStackTrace();
 
82
               }
 
83
            }
 
84
         }, Integer.toString(i));
 
85
         t.start();
 
86
      }
 
87
   }
 
88
}