~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/connection/SocketConnectionCheckTestClient.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.connection;
 
2
 
 
3
import junit.framework.TestCase;
 
4
import org.jboss.remoting.Client;
 
5
import org.jboss.remoting.InvokerLocator;
 
6
import org.jboss.remoting.transport.socket.SocketServerInvoker;
 
7
 
 
8
/**
 
9
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
10
 */
 
11
public class SocketConnectionCheckTestClient extends TestCase
 
12
{
 
13
   // Default locator values
 
14
   private static String transport = "socket";
 
15
   private static String host = "localhost";
 
16
   private static int port = 5400;
 
17
 
 
18
   public void testInvocations() throws Throwable
 
19
   {
 
20
      Client remotingClient = null;
 
21
 
 
22
      try
 
23
      {
 
24
 
 
25
 
 
26
         String locatorURI = getTransport() + "://" + host + ":" + getPort() + "/?" + SocketServerInvoker.CHECK_CONNECTION_KEY + "=" + Boolean.TRUE;
 
27
 
 
28
         // create InvokerLocator with the url type string
 
29
         // indicating the target remoting server to call upon.
 
30
         InvokerLocator locator = new InvokerLocator(locatorURI);
 
31
         System.out.println("Calling remoting server with locator uri of: " + locatorURI);
 
32
 
 
33
         remotingClient = new Client(locator);
 
34
         remotingClient.connect();
 
35
         String request = "Do something";
 
36
         System.out.println("Invoking server with request of '" + request + "'");
 
37
 
 
38
         long startTime = System.currentTimeMillis();
 
39
 
 
40
         int numOfCalls = 10000;
 
41
         Object response = null;
 
42
         for(int x = 0; x < numOfCalls; x++)
 
43
         {
 
44
            response = remotingClient.invoke(request);
 
45
//            System.out.println("Invocation response: " + response);
 
46
         }
 
47
 
 
48
         long endTime = System.currentTimeMillis();
 
49
         System.out.println("Time to make " + numOfCalls + " was " + (endTime -startTime) + " milliseconds.");
 
50
 
 
51
         int callValue = 0;
 
52
         if(response instanceof Integer)
 
53
         {
 
54
            callValue = ((Integer) response).intValue();
 
55
         }
 
56
         assertEquals(numOfCalls, callValue);
 
57
 
 
58
      }
 
59
      finally
 
60
      {
 
61
         if(remotingClient != null)
 
62
         {
 
63
            remotingClient.disconnect();
 
64
         }
 
65
      }
 
66
 
 
67
   }
 
68
   
 
69
   protected String getTransport()
 
70
   {
 
71
      return transport;
 
72
   }
 
73
   
 
74
   protected int getPort()
 
75
   {
 
76
      return port;
 
77
   }
 
78
 
 
79
   /**
 
80
    * Can pass transport and port to be used as parameters.
 
81
    * Valid transports are 'rmi' and 'socket'.
 
82
    *
 
83
    * @param args
 
84
    */
 
85
   public static void main(String[] args)
 
86
   {
 
87
      if(args != null && args.length == 3)
 
88
      {
 
89
         transport = args[0];
 
90
         host = args[1];
 
91
         port = Integer.parseInt(args[2]);
 
92
      }
 
93
      SocketConnectionCheckTestClient client = new SocketConnectionCheckTestClient();
 
94
      try
 
95
      {
 
96
         client.testInvocations();
 
97
      }
 
98
      catch(Throwable e)
 
99
      {
 
100
         e.printStackTrace();
 
101
      }
 
102
   }
 
103
 
 
104
 
 
105
}