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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/oneway/OnewayInvokerClientTest.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
 
/*
2
 
* JBoss, Home of Professional Open Source
3
 
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
 
* by the @authors tag. See the copyright.txt in the distribution for a
5
 
* full listing of individual contributors.
6
 
*
7
 
* This is free software; you can redistribute it and/or modify it
8
 
* under the terms of the GNU Lesser General Public License as
9
 
* published by the Free Software Foundation; either version 2.1 of
10
 
* the License, or (at your option) any later version.
11
 
*
12
 
* This software is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
 
* Lesser General Public License for more details.
16
 
*
17
 
* You should have received a copy of the GNU Lesser General Public
18
 
* License along with this software; if not, write to the Free
19
 
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
 
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21
 
*/
22
 
 
23
 
package org.jboss.test.remoting.oneway;
24
 
 
25
 
import java.rmi.server.UID;
26
 
import org.jboss.logging.Logger;
27
 
import org.jboss.remoting.Client;
28
 
import org.jboss.remoting.InvokerLocator;
29
 
import org.jboss.remoting.invocation.NameBasedInvocation;
30
 
 
31
 
import junit.framework.TestCase;
32
 
 
33
 
/**
34
 
 * This is the actual concrete test for the invoker client to test oneway calls (client and server based).
35
 
 *
36
 
 * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
37
 
 */
38
 
public class OnewayInvokerClientTest extends TestCase
39
 
{
40
 
   private static final Logger log = Logger.getLogger(OnewayInvokerClientTest.class);
41
 
 
42
 
   private String transport = "socket";
43
 
   private int port = 8081;
44
 
 
45
 
   private String sessionId = new UID().toString();
46
 
 
47
 
   private Client client;
48
 
 
49
 
   public void init()
50
 
   {
51
 
      try
52
 
      {
53
 
         InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port);
54
 
         client = new Client(locator, "test");
55
 
         client.connect();
56
 
      }
57
 
      catch(Exception e)
58
 
      {
59
 
         log.error(e.getMessage(), e);
60
 
      }
61
 
   }
62
 
 
63
 
   public void setUp() throws Exception
64
 
   {
65
 
      init();
66
 
   }
67
 
 
68
 
   public void tearDown() throws Exception
69
 
   {
70
 
      if(client != null)
71
 
      {
72
 
         client.disconnect();
73
 
      }
74
 
   }
75
 
 
76
 
   /**
77
 
    * Test simple oneway client invocation
78
 
    *
79
 
    * @throws Throwable
80
 
    */
81
 
   public void testOnewayServerInvocation() throws Throwable
82
 
   {
83
 
      log.debug("running testOnewayClientCallback()");
84
 
 
85
 
      sessionId = client.getSessionId();
86
 
 
87
 
      log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
88
 
 
89
 
      // simple invoke
90
 
      String param = "bar";
91
 
      makeServerOnewayInvocation("saveInvocationParameter", param);
92
 
      Thread.currentThread().sleep(4000);
93
 
      Object obj = makeInvocation("getLastInvocationParameter", null);
94
 
 
95
 
      checkAssertion(param, obj);
96
 
   }
97
 
 
98
 
   protected void checkAssertion(String param, Object obj)
99
 
   {
100
 
      assertEquals(param, obj);
101
 
   }
102
 
 
103
 
   protected void makeServerOnewayInvocation(String method, String param) throws Throwable
104
 
   {
105
 
      client.invokeOneway(new NameBasedInvocation(method,
106
 
                                                  new Object[]{param},
107
 
                                                  new String[]{String.class.getName()}),
108
 
                          null,
109
 
                          false);
110
 
 
111
 
   }
112
 
 
113
 
   /**
114
 
    * Test simple oneway client invocation
115
 
    *
116
 
    * @throws Throwable
117
 
    */
118
 
   public void testOnewayClientInvocation() throws Throwable
119
 
   {
120
 
      log.debug("running testOnewayClientCallback()");
121
 
 
122
 
      sessionId = client.getSessionId();
123
 
 
124
 
      log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
125
 
 
126
 
      // simple invoke
127
 
      String param = "bar";
128
 
      makeClientOnewayInvocation("saveInvocationParameter", param);
129
 
      Thread.currentThread().sleep(1000);
130
 
      Object obj = makeInvocation("getLastInvocationParameter", null);
131
 
 
132
 
      checkAssertion(param, obj);
133
 
 
134
 
   }
135
 
 
136
 
   /**
137
 
    * Test simple oneway client invocation
138
 
    *
139
 
    * @throws Throwable
140
 
    */
141
 
   public void testClientInvocation() throws Throwable
142
 
   {
143
 
      log.debug("running testInvocation()");
144
 
 
145
 
      sessionId = client.getSessionId();
146
 
 
147
 
      log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
148
 
 
149
 
      // simple invoke
150
 
      String param = "bar";
151
 
      Object resp = makeClientInvocation("saveInvocationParameter", param);
152
 
 
153
 
      Object obj = makeInvocation("getLastInvocationParameter", null);
154
 
      Thread.currentThread().sleep(1000);
155
 
      checkAssertion(param, obj);
156
 
 
157
 
   }
158
 
 
159
 
   protected void makeClientOnewayInvocation(String method, String param) throws Throwable
160
 
   {
161
 
      client.invokeOneway(new NameBasedInvocation(method,
162
 
                                                  new Object[]{param},
163
 
                                                  new String[]{String.class.getName()}),
164
 
                          null,
165
 
                          true);
166
 
 
167
 
   }
168
 
 
169
 
   protected Object makeClientInvocation(String method, String param) throws Throwable
170
 
   {
171
 
      Object ret = client.invoke(new NameBasedInvocation(method,
172
 
                                                         new Object[]{param},
173
 
                                                         new String[]{String.class.getName()}),
174
 
                                 null);
175
 
 
176
 
      return ret;
177
 
   }
178
 
 
179
 
 
180
 
   protected Object makeInvocation(String method, String param) throws Throwable
181
 
   {
182
 
      Object ret = client.invoke(new NameBasedInvocation(method,
183
 
                                                         new Object[]{param},
184
 
                                                         new String[]{String.class.getName()}),
185
 
                                 null);
186
 
 
187
 
      return ret;
188
 
   }
189
 
 
190
 
 
191
 
}