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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/deploy/DualDeploymentTestCase.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20110909140103-o8ucrolqt5g25k57
Tags: upstream-2.5.3.SP1
ImportĀ upstreamĀ versionĀ 2.5.3.SP1

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.deploy;
24
 
 
25
 
import junit.framework.TestCase;
26
 
import org.jboss.remoting.Client;
27
 
import org.jboss.remoting.InvalidConfigurationException;
28
 
import org.jboss.remoting.InvocationRequest;
29
 
import org.jboss.remoting.InvokerLocator;
30
 
import org.jboss.remoting.ServerInvocationHandler;
31
 
import org.jboss.remoting.ServerInvoker;
32
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
33
 
import org.jboss.remoting.transport.Connector;
34
 
 
35
 
import javax.management.MBeanServer;
36
 
import javax.management.MBeanServerFactory;
37
 
import javax.management.ObjectName;
38
 
 
39
 
/**
40
 
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
41
 
 */
42
 
public class DualDeploymentTestCase extends TestCase
43
 
{
44
 
   private static int idCounter = 1;
45
 
 
46
 
   public DualDeploymentTestCase(String name)
47
 
   {
48
 
      super(name);
49
 
   }
50
 
 
51
 
   /**
52
 
    * This test checks to see if use the exact same locator uri, will get the
53
 
    * exact same server invoker (even though connectors are different).  If add handler to
54
 
    * each of the different connectors (with different subsystems), will really be two handlers in the same server invoker
55
 
    *
56
 
    * @throws Throwable
57
 
    */
58
 
   public void testSameLocator() throws Throwable
59
 
   {
60
 
      MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
61
 
 
62
 
      String locator1 = "socket://localhost:5701";
63
 
      String locator2 = "socket://localhost:5701";
64
 
 
65
 
      int id1 = 1;
66
 
      int id2 = 2;
67
 
 
68
 
      Connector connector1 = setupServer(locator1, mbeanServer);
69
 
      SampleInvocationHandler invocationHandler1 = new SampleInvocationHandler(id1);
70
 
      connector1.addInvocationHandler("sub1", invocationHandler1);
71
 
 
72
 
      Connector connector2 = null;
73
 
      try
74
 
      {
75
 
         connector2 = setupServer(locator2, mbeanServer);
76
 
         SampleInvocationHandler invocationHandler2 = new SampleInvocationHandler(id2);
77
 
         connector2.addInvocationHandler("sub2", invocationHandler2);
78
 
      }
79
 
      catch(InvalidConfigurationException e)
80
 
      {
81
 
         assertTrue("Got InvalidConfigurationException as expected.", true);
82
 
         return;
83
 
      }
84
 
      finally
85
 
      {
86
 
         connector1.stop();
87
 
         connector1.destroy();
88
 
         if(connector2 != null)
89
 
         {
90
 
            connector2.stop();
91
 
            connector2.destroy();
92
 
         }
93
 
      }
94
 
      assertTrue("Did not get InvalidConfigurationException as expected.", false);
95
 
 
96
 
   }
97
 
 
98
 
   /**
99
 
    * This checks to makes sure if you add a handler with the same subsystem value, it will return the existing
100
 
    * one.
101
 
    *
102
 
    * @throws Throwable
103
 
    */
104
 
   public void testSameSubsystem() throws Throwable
105
 
   {
106
 
      MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
107
 
 
108
 
      String locator1 = "socket://localhost:5703";
109
 
 
110
 
      int id1 = 1;
111
 
      int id2 = 2;
112
 
 
113
 
      Connector connector1 = setupServer(locator1, mbeanServer);
114
 
      SampleInvocationHandler invocationHandler1 = new SampleInvocationHandler(id1);
115
 
      ServerInvocationHandler previous = connector1.addInvocationHandler("sub1", invocationHandler1);
116
 
 
117
 
      assertNull(previous);
118
 
 
119
 
      SampleInvocationHandler invocationHandler2 = new SampleInvocationHandler(id2);
120
 
      previous = connector1.addInvocationHandler("sub1", invocationHandler2);
121
 
 
122
 
      assertEquals(invocationHandler1, previous);
123
 
 
124
 
      ServerInvocationHandler[] handlers1 = connector1.getInvocationHandlers();
125
 
 
126
 
      assertEquals(1, handlers1.length);
127
 
 
128
 
      connector1.stop();
129
 
      connector1.destroy();
130
 
 
131
 
   }
132
 
 
133
 
   /**
134
 
    * Disabling this test.  
135
 
    * 
136
 
    * org.jboss.remoting.ServerInvoker is not written to support
137
 
    * the assertion "should always use the last handler added" made below.  
138
 
    * 
139
 
    * There are two choices:
140
 
    * 
141
 
    * 1. Implement the feature, or
142
 
    * 2. Eliminate the test.
143
 
    * 
144
 
    * Since there is no provision in the Remoting Guide that supports this feature, and
145
 
    * it doesn't seem particularly useful, we'll leave the ServerInvoker code alone
146
 
    * and eliminate the test.  - Ron Sigal, 4/29/08
147
 
    * 
148
 
    * If multiple handlers added to connector (thus server invoker) and subsystem is NOT
149
 
    * specified in client, then will be processed by last handler added.
150
 
    *
151
 
    * @throws Throwable
152
 
    */
153
 
   public void xtestNoSubsystem() throws Throwable
154
 
   {
155
 
      MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
156
 
 
157
 
      String locator1 = "socket://localhost:5704";
158
 
      String locator2 = "socket://localhost:5705";
159
 
 
160
 
      int id1 = 1;
161
 
      int id2 = 2;
162
 
      int id3 = 3;
163
 
      int id4 = 4;
164
 
 
165
 
      Connector connector1 = setupServer(locator1, mbeanServer);
166
 
      SampleInvocationHandler invocationHandler1 = new SampleInvocationHandler(id1);
167
 
      connector1.addInvocationHandler("sub1", invocationHandler1);
168
 
 
169
 
      SampleInvocationHandler invocationHandler2 = new SampleInvocationHandler(id2);
170
 
      connector1.addInvocationHandler("sub2", invocationHandler2);
171
 
      SampleInvocationHandler invocationHandler3 = new SampleInvocationHandler(id3);
172
 
      connector1.addInvocationHandler("sub3", invocationHandler3);
173
 
 
174
 
      Connector connector2 = setupServer(locator2, mbeanServer);
175
 
      SampleInvocationHandler invocationHandler4 = new SampleInvocationHandler(id4);
176
 
      connector2.addInvocationHandler("sub4", invocationHandler4);
177
 
 
178
 
      Client client = new Client(new InvokerLocator(locator1));
179
 
      Client client2 = new Client(new InvokerLocator(locator2));
180
 
      client.connect();
181
 
      client2.connect();
182
 
 
183
 
      Object ret1 = client.invoke("Do something");
184
 
      Object ret2 = client2.invoke("Do something");
185
 
 
186
 
      // should always use the last handler added
187
 
      assertEquals("" + id3, ret1);
188
 
      assertEquals("" + id4, ret2);
189
 
 
190
 
      connector1.stop();
191
 
      connector1.destroy();
192
 
      connector2.stop();
193
 
      connector2.destroy();
194
 
 
195
 
   }
196
 
 
197
 
   public Connector setupServer(String locatorURI, MBeanServer mbeanServer) throws Exception
198
 
   {
199
 
      InvokerLocator locator = new InvokerLocator(locatorURI);
200
 
      System.out.println("Starting remoting server with locator uri of: " + locatorURI);
201
 
      Connector connector = new Connector();
202
 
      connector.setInvokerLocator(locator.getLocatorURI());
203
 
      int randomInt = idCounter++;
204
 
      ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + locator.getProtocol() + ",id=" + randomInt);
205
 
      mbeanServer.registerMBean(connector, obj);
206
 
      connector.start();
207
 
 
208
 
      return connector;
209
 
   }
210
 
 
211
 
   /**
212
 
    * Simple invocation handler implementation.
213
 
    */
214
 
   public static class SampleInvocationHandler implements ServerInvocationHandler
215
 
   {
216
 
      private int id = 0;
217
 
 
218
 
      public SampleInvocationHandler(int id)
219
 
      {
220
 
         this.id = id;
221
 
      }
222
 
 
223
 
      public int getId()
224
 
      {
225
 
         return id;
226
 
      }
227
 
 
228
 
      /**
229
 
       * called to handle a specific invocation
230
 
       *
231
 
       * @param invocation
232
 
       * @return
233
 
       * @throws Throwable
234
 
       */
235
 
      public Object invoke(InvocationRequest invocation) throws Throwable
236
 
      {
237
 
         // Print out the invocation request
238
 
         System.out.println("Invocation request is: " + invocation.getParameter());
239
 
 
240
 
         // Just going to return static string as this is just simple example code.
241
 
         return "" + id;
242
 
      }
243
 
 
244
 
      /**
245
 
       * Adds a callback handler that will listen for callbacks from
246
 
       * the server invoker handler.
247
 
       *
248
 
       * @param callbackHandler
249
 
       */
250
 
      public void addListener(InvokerCallbackHandler callbackHandler)
251
 
      {
252
 
         // NO OP as do not handling callback listeners in this example
253
 
      }
254
 
 
255
 
      /**
256
 
       * Removes the callback handler that was listening for callbacks
257
 
       * from the server invoker handler.
258
 
       *
259
 
       * @param callbackHandler
260
 
       */
261
 
      public void removeListener(InvokerCallbackHandler callbackHandler)
262
 
      {
263
 
         // NO OP as do not handling callback listeners in this example
264
 
      }
265
 
 
266
 
      /**
267
 
       * set the mbean server that the handler can reference
268
 
       *
269
 
       * @param server
270
 
       */
271
 
      public void setMBeanServer(MBeanServer server)
272
 
      {
273
 
         // NO OP as do not need reference to MBeanServer for this handler
274
 
      }
275
 
 
276
 
      /**
277
 
       * set the invoker that owns this handler
278
 
       *
279
 
       * @param invoker
280
 
       */
281
 
      public void setInvoker(ServerInvoker invoker)
282
 
      {
283
 
         // NO OP as do not need reference back to the server invoker
284
 
      }
285
 
 
286
 
   }
287
 
 
288
 
 
289
 
}
 
 
b'\\ No newline at end of file'