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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/callback/pull/CallbackTestClient.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.callback.pull;
2
 
 
3
 
import junit.framework.TestCase;
4
 
import org.jboss.remoting.Client;
5
 
import org.jboss.remoting.InvokerLocator;
6
 
import org.jboss.remoting.callback.Callback;
7
 
import org.jboss.remoting.callback.HandleCallbackException;
8
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
9
 
 
10
 
import java.util.List;
11
 
 
12
 
/**
13
 
 * Tests that two separate clients with separate callback listeners
14
 
 * can be distinguished on the server and given different callback messages.
15
 
 *
16
 
 * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
17
 
 */
18
 
public class CallbackTestClient extends TestCase
19
 
{
20
 
   // Default locator values
21
 
   private static String transport = "socket";
22
 
   private static String host = "localhost";
23
 
   private static int port = 5411;
24
 
 
25
 
   private String locatorURI = transport + "://" + host + ":" + port;
26
 
 
27
 
   private Client remotingClient;
28
 
   private CallbackHandler pullCallbackHandler;
29
 
 
30
 
   private Client remotingClient2;
31
 
   private CallbackHandler pullCallbackHandler2;
32
 
 
33
 
   public void createRemotingClient() throws Exception
34
 
   {
35
 
      InvokerLocator locator = new InvokerLocator(locatorURI);
36
 
      System.out.println("Calling remoting server with locator uri of: " + locatorURI);
37
 
 
38
 
      remotingClient = new Client(locator);
39
 
      remotingClient.connect();
40
 
 
41
 
      remotingClient2 = new Client(locator);
42
 
      remotingClient2.connect();
43
 
 
44
 
   }
45
 
 
46
 
   public void setUp() throws Exception
47
 
   {
48
 
      createRemotingClient();
49
 
   }
50
 
 
51
 
   public void tearDown() throws Exception
52
 
   {
53
 
      if(remotingClient != null)
54
 
      {
55
 
         if(pullCallbackHandler != null)
56
 
         {
57
 
            try
58
 
            {
59
 
               remotingClient.removeListener(pullCallbackHandler);
60
 
            }
61
 
            catch(Throwable throwable)
62
 
            {
63
 
               throw new Exception(throwable);
64
 
            }
65
 
         }
66
 
         remotingClient.disconnect();
67
 
      }
68
 
      if(remotingClient2 != null)
69
 
      {
70
 
         if(pullCallbackHandler2 != null)
71
 
         {
72
 
            try
73
 
            {
74
 
               remotingClient2.removeListener(pullCallbackHandler2);
75
 
            }
76
 
            catch(Throwable throwable)
77
 
            {
78
 
               throw new Exception(throwable);
79
 
            }
80
 
         }
81
 
         remotingClient2.disconnect();
82
 
      }
83
 
   }
84
 
 
85
 
   public void testPullCallback() throws Throwable
86
 
   {
87
 
      pullCallbackHandler = new CallbackHandler();
88
 
      pullCallbackHandler2 = new CallbackHandler();
89
 
      // by passing only the callback handler, will indicate pull callbacks
90
 
      remotingClient.addListener(pullCallbackHandler);
91
 
      remotingClient2.addListener(pullCallbackHandler2);
92
 
 
93
 
      // now make invocation on server, which should cause a callback to happen
94
 
      remotingClient.invoke("Do something");
95
 
      remotingClient2.invoke("Do something");
96
 
 
97
 
      Thread.sleep(5000);
98
 
 
99
 
      List callbacks = remotingClient.getCallbacks(pullCallbackHandler);
100
 
      List callbacks2 = remotingClient2.getCallbacks(pullCallbackHandler2);
101
 
 
102
 
      boolean callbackWorked = false;
103
 
 
104
 
      if(callbacks != null && callbacks.size() > 0)
105
 
      {
106
 
         for(int x = 0; x < callbacks.size(); x++)
107
 
         {
108
 
            Callback c = (Callback)callbacks.get(x);
109
 
            callbackWorked = c.getCallbackObject().equals(remotingClient.getSessionId());
110
 
            if(!callbackWorked)
111
 
            {
112
 
               break;
113
 
            }
114
 
         }
115
 
      }
116
 
 
117
 
      assertTrue(callbackWorked);
118
 
 
119
 
      boolean callbackWorked2 = false;
120
 
 
121
 
      if(callbacks2 != null && callbacks2.size() > 0)
122
 
      {
123
 
         for(int x = 0; x < callbacks2.size(); x++)
124
 
         {
125
 
            Callback c = (Callback)callbacks2.get(x);
126
 
            callbackWorked2 = c.getCallbackObject().equals(remotingClient2.getSessionId());
127
 
            if(!callbackWorked2)
128
 
            {
129
 
               break;
130
 
            }
131
 
         }
132
 
      }
133
 
 
134
 
      assertTrue(callbackWorked2);
135
 
 
136
 
   }
137
 
 
138
 
   public class CallbackHandler implements InvokerCallbackHandler
139
 
   {
140
 
      public void handleCallback(Callback callback) throws HandleCallbackException
141
 
      {
142
 
      }
143
 
 
144
 
   }
145
 
 
146
 
}