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.
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.
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.
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.
23
package org.jboss.test.remoting.deploy;
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;
35
import javax.management.MBeanServer;
36
import javax.management.MBeanServerFactory;
37
import javax.management.ObjectName;
40
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
42
public class DualDeploymentTestCase extends TestCase
44
private static int idCounter = 1;
46
public DualDeploymentTestCase(String name)
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
58
public void testSameLocator() throws Throwable
60
MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
62
String locator1 = "socket://localhost:5701";
63
String locator2 = "socket://localhost:5701";
68
Connector connector1 = setupServer(locator1, mbeanServer);
69
SampleInvocationHandler invocationHandler1 = new SampleInvocationHandler(id1);
70
connector1.addInvocationHandler("sub1", invocationHandler1);
72
Connector connector2 = null;
75
connector2 = setupServer(locator2, mbeanServer);
76
SampleInvocationHandler invocationHandler2 = new SampleInvocationHandler(id2);
77
connector2.addInvocationHandler("sub2", invocationHandler2);
79
catch(InvalidConfigurationException e)
81
assertTrue("Got InvalidConfigurationException as expected.", true);
88
if(connector2 != null)
94
assertTrue("Did not get InvalidConfigurationException as expected.", false);
99
* This checks to makes sure if you add a handler with the same subsystem value, it will return the existing
104
public void testSameSubsystem() throws Throwable
106
MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
108
String locator1 = "socket://localhost:5703";
113
Connector connector1 = setupServer(locator1, mbeanServer);
114
SampleInvocationHandler invocationHandler1 = new SampleInvocationHandler(id1);
115
ServerInvocationHandler previous = connector1.addInvocationHandler("sub1", invocationHandler1);
117
assertNull(previous);
119
SampleInvocationHandler invocationHandler2 = new SampleInvocationHandler(id2);
120
previous = connector1.addInvocationHandler("sub1", invocationHandler2);
122
assertEquals(invocationHandler1, previous);
124
ServerInvocationHandler[] handlers1 = connector1.getInvocationHandlers();
126
assertEquals(1, handlers1.length);
129
connector1.destroy();
134
* Disabling this test.
136
* org.jboss.remoting.ServerInvoker is not written to support
137
* the assertion "should always use the last handler added" made below.
139
* There are two choices:
141
* 1. Implement the feature, or
142
* 2. Eliminate the test.
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
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.
153
public void xtestNoSubsystem() throws Throwable
155
MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
157
String locator1 = "socket://localhost:5704";
158
String locator2 = "socket://localhost:5705";
165
Connector connector1 = setupServer(locator1, mbeanServer);
166
SampleInvocationHandler invocationHandler1 = new SampleInvocationHandler(id1);
167
connector1.addInvocationHandler("sub1", invocationHandler1);
169
SampleInvocationHandler invocationHandler2 = new SampleInvocationHandler(id2);
170
connector1.addInvocationHandler("sub2", invocationHandler2);
171
SampleInvocationHandler invocationHandler3 = new SampleInvocationHandler(id3);
172
connector1.addInvocationHandler("sub3", invocationHandler3);
174
Connector connector2 = setupServer(locator2, mbeanServer);
175
SampleInvocationHandler invocationHandler4 = new SampleInvocationHandler(id4);
176
connector2.addInvocationHandler("sub4", invocationHandler4);
178
Client client = new Client(new InvokerLocator(locator1));
179
Client client2 = new Client(new InvokerLocator(locator2));
183
Object ret1 = client.invoke("Do something");
184
Object ret2 = client2.invoke("Do something");
186
// should always use the last handler added
187
assertEquals("" + id3, ret1);
188
assertEquals("" + id4, ret2);
191
connector1.destroy();
193
connector2.destroy();
197
public Connector setupServer(String locatorURI, MBeanServer mbeanServer) throws Exception
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);
212
* Simple invocation handler implementation.
214
public static class SampleInvocationHandler implements ServerInvocationHandler
218
public SampleInvocationHandler(int id)
229
* called to handle a specific invocation
235
public Object invoke(InvocationRequest invocation) throws Throwable
237
// Print out the invocation request
238
System.out.println("Invocation request is: " + invocation.getParameter());
240
// Just going to return static string as this is just simple example code.
245
* Adds a callback handler that will listen for callbacks from
246
* the server invoker handler.
248
* @param callbackHandler
250
public void addListener(InvokerCallbackHandler callbackHandler)
252
// NO OP as do not handling callback listeners in this example
256
* Removes the callback handler that was listening for callbacks
257
* from the server invoker handler.
259
* @param callbackHandler
261
public void removeListener(InvokerCallbackHandler callbackHandler)
263
// NO OP as do not handling callback listeners in this example
267
* set the mbean server that the handler can reference
271
public void setMBeanServer(MBeanServer server)
273
// NO OP as do not need reference to MBeanServer for this handler
277
* set the invoker that owns this handler
281
public void setInvoker(ServerInvoker invoker)
283
// NO OP as do not need reference back to the server invoker
b'\\ No newline at end of file'