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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/concurrent/local/ConcurrentTestCase.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.concurrent.local;
 
2
 
 
3
import junit.framework.TestCase;
 
4
import org.jboss.remoting.Client;
 
5
import org.jboss.remoting.InvocationRequest;
 
6
import org.jboss.remoting.InvokerLocator;
 
7
import org.jboss.remoting.ServerInvocationHandler;
 
8
import org.jboss.remoting.ServerInvoker;
 
9
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
10
import org.jboss.remoting.transport.Connector;
 
11
 
 
12
import javax.management.MBeanServer;
 
13
 
 
14
/**
 
15
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
16
 */
 
17
public class ConcurrentTestCase extends TestCase
 
18
{
 
19
   private String locatorUri = "socket://localhost:8777";
 
20
   private boolean failure = false;
 
21
   private Client client = null;
 
22
   private Connector connector = null;
 
23
   private int numOfThreads = 100;
 
24
   private int numOfIterations = 100;
 
25
   private int[][] results = null;
 
26
 
 
27
   public void setUp() throws Exception
 
28
   {
 
29
      connector = new Connector(locatorUri);
 
30
      connector.create();
 
31
      connector.addInvocationHandler("test", new TestInvocationHandler());
 
32
      connector.start();
 
33
 
 
34
      client = new Client(new InvokerLocator(locatorUri));
 
35
      client.connect();
 
36
      results = new int[numOfThreads][numOfIterations];
 
37
   }
 
38
 
 
39
 
 
40
   public void testConcurrentInvocations() throws Exception
 
41
   {
 
42
 
 
43
      for(int x = 0; x < numOfThreads; x++)
 
44
      {
 
45
         final int num = x;
 
46
         new Thread(new Runnable() {
 
47
            public void run()
 
48
            {
 
49
               try
 
50
               {
 
51
                  runInvocations(num);
 
52
               }
 
53
               catch (Throwable throwable)
 
54
               {
 
55
                  throwable.printStackTrace();
 
56
               }
 
57
            }
 
58
         }, "" + x).start();
 
59
      }
 
60
 
 
61
      Thread.sleep(20000);
 
62
 
 
63
      assertFalse(failure);
 
64
 
 
65
      assertTrue(validateResults());
 
66
 
 
67
   }
 
68
 
 
69
   private boolean validateResults()
 
70
   {
 
71
      boolean failed = true;
 
72
 
 
73
      for(int z = 0; z < numOfThreads; z++)
 
74
      {
 
75
         for(int q = 1; q < numOfIterations; q++)
 
76
         {
 
77
            int a = results[z][q -1];
 
78
            int b = results[z][q];
 
79
            //System.out.println("a = " + a + ", b = " + b + ((b -1 != a) ? " - FAILED" : ""));
 
80
            if(b - 1 != a)
 
81
            {
 
82
               failed = false;
 
83
            }
 
84
         }
 
85
      }
 
86
      return failed;
 
87
   }
 
88
 
 
89
   private void runInvocations(int num) throws Throwable
 
90
   {
 
91
      for(int i = 0; i < numOfIterations; i++)
 
92
      {
 
93
         String param = num + "-" + i;
 
94
         Object result = client.invoke(param);
 
95
         //System.out.println(Thread.currentThread() + " - " + result);
 
96
         assertEquals(param, result);
 
97
         String subResult = ((String)result).substring(String.valueOf(num).length() + 1);
 
98
         //System.out.println(Thread.currentThread() + " - " + subResult);
 
99
         results[num][i] = Integer.parseInt(subResult);
 
100
      }
 
101
   }
 
102
 
 
103
   public void tearDown()
 
104
   {
 
105
      if(connector != null)
 
106
      {
 
107
         connector.stop();
 
108
         connector.destroy();
 
109
      }
 
110
 
 
111
      if(client != null)
 
112
      {
 
113
         client.disconnect();
 
114
      }
 
115
   }
 
116
 
 
117
   public class TestInvocationHandler implements ServerInvocationHandler
 
118
   {
 
119
 
 
120
      public void setMBeanServer(MBeanServer server)
 
121
      {
 
122
         //TODO: -TME Implement
 
123
      }
 
124
 
 
125
      public void setInvoker(ServerInvoker invoker)
 
126
      {
 
127
         //TODO: -TME Implement
 
128
      }
 
129
 
 
130
      public Object invoke(InvocationRequest invocation) throws Throwable
 
131
      {
 
132
         return invocation.getParameter();
 
133
      }
 
134
 
 
135
      public void addListener(InvokerCallbackHandler callbackHandler)
 
136
      {
 
137
         //TODO: -TME Implement
 
138
      }
 
139
 
 
140
      public void removeListener(InvokerCallbackHandler callbackHandler)
 
141
      {
 
142
         //TODO: -TME Implement
 
143
      }
 
144
   }
 
145
 
 
146
 
 
147
}