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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/transport/socket/stress/SocketInvokerClientTest.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.stress;
 
2
 
 
3
import org.jboss.remoting.Client;
 
4
import org.jboss.remoting.InvokerLocator;
 
5
 
 
6
/**
 
7
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
8
 */
 
9
public class SocketInvokerClientTest
 
10
{
 
11
   private int numOfThreads = 250;
 
12
//   private int numOfCalls = 1000;
 
13
   private int numOfCalls = 1000000;
 
14
 
 
15
//   private int maxClientPoolSize = 50;
 
16
   private int maxClientPoolSize = 250;
 
17
 
 
18
   private boolean[] finishedThreads = new boolean[numOfThreads];
 
19
 
 
20
   public String getTransport()
 
21
   {
 
22
      return "socket";
 
23
   }
 
24
 
 
25
   public void testClientCalls() throws Exception
 
26
   {
 
27
      Thread currentThread = null;
 
28
 
 
29
      for (int x = 0; x < numOfThreads; x++)
 
30
      {
 
31
         currentThread = new Thread(new Runnable()
 
32
         {
 
33
            public void run()
 
34
            {
 
35
 
 
36
               Client client = null;
 
37
               try
 
38
               {
 
39
                  InvokerLocator locator = new InvokerLocator(getTransport() + "://" + "localhost" + ":" + 6700 + "/?" +
 
40
                                                              "clientMaxPoolSize=" + maxClientPoolSize);
 
41
                  client = new Client(locator);
 
42
                  client.connect();
 
43
                  String threadName = Thread.currentThread().getName();
 
44
                  for (int i = 0; i < numOfCalls; i++)
 
45
                  {
 
46
                     Object ret = client.invoke(threadName);
 
47
                     if(!ret.equals(threadName))
 
48
                     {
 
49
                        System.out.println("ERROR - Should have returned " + threadName + " but returned " + ret);
 
50
                        System.exit(1);
 
51
                     }
 
52
                     if(i % 500 == 0 && i > 0)
 
53
                     {
 
54
                        System.out.println("Thread " + threadName + " has made " + i + " invocations.");
 
55
                     }
 
56
                  }
 
57
                  System.out.println(threadName + " -- done.");
 
58
                  int threadNum = Integer.parseInt(threadName);
 
59
                  finishedThreads[threadNum] = true;
 
60
               }
 
61
               catch (Throwable e)
 
62
               {
 
63
                  e.printStackTrace();
 
64
               }
 
65
               finally
 
66
               {
 
67
                  client.disconnect();
 
68
               }
 
69
            }
 
70
         }, "" + x);
 
71
         currentThread.start();
 
72
 
 
73
      }
 
74
 
 
75
//      Thread.currentThread().sleep(300000);
 
76
      Thread.currentThread().sleep(7200000);
 
77
 
 
78
      for (int r = 0; r < finishedThreads.length; r++)
 
79
      {
 
80
         if (!finishedThreads[r])
 
81
         {
 
82
            System.out.println("Failed - thread " + r + " never finished.");
 
83
         }
 
84
      }
 
85
   }
 
86
 
 
87
   public static void main(String[] args)
 
88
   {
 
89
      SocketInvokerClientTest client = new SocketInvokerClientTest();
 
90
      try
 
91
      {
 
92
         client.testClientCalls();
 
93
      }
 
94
      catch (Exception e)
 
95
      {
 
96
         e.printStackTrace();
 
97
      }
 
98
   }
 
99
}