KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > oneway > OnewayInvokerClientTest


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.remoting.oneway;
8
9 import java.rmi.server.UID JavaDoc;
10 import org.jboss.logging.Logger;
11 import org.jboss.remoting.Client;
12 import org.jboss.remoting.InvokerLocator;
13 import org.jboss.remoting.invocation.NameBasedInvocation;
14
15 import junit.framework.TestCase;
16
17 /**
18  * This is the actual concrete test for the invoker client to test oneway calls (client and server based).
19  *
20  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
21  */

22 public class OnewayInvokerClientTest extends TestCase
23 {
24    private static final Logger log = Logger.getLogger(OnewayInvokerClientTest.class);
25
26    private String JavaDoc transport = "socket";
27    private int port = 8081;
28
29    private String JavaDoc sessionId = new UID JavaDoc().toString();
30
31    private Client client;
32
33    public void init()
34    {
35       try
36       {
37          InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port);
38          client = new Client(locator, "test");
39          client.connect();
40       }
41       catch(Exception JavaDoc e)
42       {
43          log.error(e.getMessage(), e);
44       }
45    }
46
47    public void setUp() throws Exception JavaDoc
48    {
49       init();
50    }
51
52    public void tearDown() throws Exception JavaDoc
53    {
54       if(client != null)
55       {
56          client.disconnect();
57       }
58    }
59
60    /**
61     * Test simple oneway client invocation
62     *
63     * @throws Throwable
64     */

65    public void testOnewayServerInvocation() throws Throwable JavaDoc
66    {
67       log.debug("running testOnewayClientCallback()");
68
69       sessionId = client.getSessionId();
70
71       log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
72
73       // simple invoke
74
String JavaDoc param = "bar";
75       makeServerOnewayInvocation("saveInvocationParameter", param);
76       Thread.currentThread().sleep(1000);
77       Object JavaDoc obj = makeInvocation("getLastInvocationParameter", null);
78
79       checkAssertion(param, obj);
80    }
81
82    protected void checkAssertion(String JavaDoc param, Object JavaDoc obj)
83    {
84       assertEquals(param, obj);
85    }
86
87    protected void makeServerOnewayInvocation(String JavaDoc method, String JavaDoc param) throws Throwable JavaDoc
88    {
89       client.invokeOneway(new NameBasedInvocation(method,
90                                                   new Object JavaDoc[]{param},
91                                                   new String JavaDoc[]{String JavaDoc.class.getName()}),
92                           null,
93                           false);
94
95    }
96
97    /**
98     * Test simple oneway client invocation
99     *
100     * @throws Throwable
101     */

102    public void testOnewayClientInvocation() throws Throwable JavaDoc
103    {
104       log.debug("running testOnewayClientCallback()");
105
106       sessionId = client.getSessionId();
107
108       log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
109
110
111       // simple invoke
112
String JavaDoc param = "bar";
113       makeClientOnewayInvocation("saveInvocationParameter", param);
114       Thread.currentThread().sleep(1000);
115       Object JavaDoc obj = makeInvocation("getLastInvocationParameter", null);
116
117       checkAssertion(param, obj);
118
119    }
120
121    /**
122     * Test simple oneway client invocation
123     *
124     * @throws Throwable
125     */

126    public void testClientInvocation() throws Throwable JavaDoc
127    {
128       log.debug("running testInvocation()");
129
130       sessionId = client.getSessionId();
131
132       log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator());
133
134       // simple invoke
135
String JavaDoc param = "bar";
136       Object JavaDoc resp = makeClientInvocation("saveInvocationParameter", param);
137
138       Object JavaDoc obj = makeInvocation("getLastInvocationParameter", null);
139       Thread.currentThread().sleep(1000);
140       checkAssertion(param, obj);
141
142    }
143
144    protected void makeClientOnewayInvocation(String JavaDoc method, String JavaDoc param) throws Throwable JavaDoc
145    {
146       client.invokeOneway(new NameBasedInvocation(method,
147                                                   new Object JavaDoc[]{param},
148                                                   new String JavaDoc[]{String JavaDoc.class.getName()}),
149                           null,
150                           true);
151
152    }
153
154    protected Object JavaDoc makeClientInvocation(String JavaDoc method, String JavaDoc param) throws Throwable JavaDoc
155    {
156       Object JavaDoc ret = client.invoke(new NameBasedInvocation(method,
157                                                          new Object JavaDoc[]{param},
158                                                          new String JavaDoc[]{String JavaDoc.class.getName()}),
159                                  null);
160
161       return ret;
162    }
163
164
165    protected Object JavaDoc makeInvocation(String JavaDoc method, String JavaDoc param) throws Throwable JavaDoc
166    {
167       Object JavaDoc ret = client.invoke(new NameBasedInvocation(method,
168                                                          new Object JavaDoc[]{param},
169                                                          new String JavaDoc[]{String JavaDoc.class.getName()}),
170                                  null);
171
172       return ret;
173    }
174
175
176 }
177
Popular Tags