1
package org.jboss.test.remoting.detection.multicast.deadlock;
3
import junit.framework.TestCase;
4
import org.jboss.remoting.Client;
5
import org.jboss.remoting.InvocationRequest;
6
import org.jboss.remoting.InvokerLocator;
7
import org.jboss.remoting.ServerInvocationHandler;
8
import org.jboss.remoting.ServerInvoker;
9
import org.jboss.remoting.callback.InvokerCallbackHandler;
10
import org.jboss.remoting.detection.multicast.MulticastDetector;
11
import org.jboss.remoting.network.NetworkInstance;
12
import org.jboss.remoting.network.NetworkRegistry;
13
import org.jboss.remoting.security.SSLSocketBuilder;
14
import org.jboss.remoting.transport.Connector;
16
import javax.management.MBeanServer;
17
import javax.management.MBeanServerFactory;
18
import javax.management.ObjectName;
20
import java.net.InetAddress;
21
import java.util.HashMap;
26
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
28
public class MulticastDetectorClient extends TestCase
30
private MulticastDetector detector;
31
private NetworkRegistry registry;
32
private Connector connector;
34
private Client remotingClient = null;
36
public void setUp() throws Exception
38
detector = new MulticastDetector();
40
System.setProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
41
System.out.println("jboss.identity = " + System.getProperty("jboss.identity"));
43
MBeanServer server = MBeanServerFactory.createMBeanServer();
45
registry = NetworkRegistry.getInstance();
46
server.registerMBean(registry, new ObjectName("remoting:type=NetworkRegistry"));
48
//Need to set new domain for identity
49
server.registerMBean(detector, new ObjectName("remoting:type=JNDIDetector"));
52
public void testDetection() throws Exception
55
long start = System.currentTimeMillis();
56
NetworkInstance[] instances = detector.forceDetection();
57
long end = System.currentTimeMillis();
59
System.out.println("instance = " + instances);
60
System.out.println("force detection took " + (end - start) + " milliseconds.");
62
String host = InetAddress.getLocalHost().getHostAddress();
63
String bindAddr = System.getProperty("jrunit.bind_addr", host);
65
// assertEquals(1, instances.length);
67
// now create a client
68
InvokerLocator serverLocator = null;
69
for (int i = 0; i < instances.length; i++)
71
NetworkInstance ni = instances[i];
72
InvokerLocator[] locator = ni.getLocators();
73
for (int j = 0; j < locator.length; j++)
75
if (locator[j].getHost().equals(bindAddr))
77
serverLocator = locator[j];
83
System.out.println("client connecting to " + serverLocator);
84
Map config = new HashMap();
85
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
86
String trustStoreFilePath = this.getClass().getResource("ssl/.truststore").getFile();
87
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
88
config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
89
String keyStoreFilePath = this.getClass().getResource("ssl/.keystore").getFile();
90
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
91
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
92
config.put(SSLSocketBuilder.REMOTING_CLIENT_AUTH_MODE, SSLSocketBuilder.CLIENT_AUTH_MODE_WANT);
94
remotingClient = new Client(serverLocator, config);
95
remotingClient.connect();
97
String invokerLocatorurl = "sslsocket://" + bindAddr + ":8700";
98
connector = new Connector(invokerLocatorurl, config);
101
connector.addInvocationHandler("test", new LocalHandler());
106
Object ret = remotingClient.invoke(invokerLocatorurl);
107
System.out.println("return from calling server is " + ret);
109
catch (Throwable throwable)
111
throwable.printStackTrace();
112
throw new Exception(throwable.getMessage());
115
// Thread.currentThread().sleep(20000);
117
// System.out.println("Disconnecting.");
119
// remotingClient.disconnect();
121
// System.out.println("Disconnected.");
124
public void disconnect() throws InterruptedException
126
Thread.currentThread().sleep(30000);
128
System.out.println("Disconnecting.");
130
remotingClient.disconnect();
132
System.out.println("Disconnected.");
134
remotingClient = null;
138
public void tearDown() throws Exception
140
if (remotingClient != null)
142
remotingClient.disconnect();
144
if (detector != null)
148
if(connector != null)
155
public static void main(String[] args)
157
MulticastDetectorClient client = new MulticastDetectorClient();
161
client.testDetection();
164
System.out.println("done testing.");
184
public class LocalHandler implements ServerInvocationHandler
187
public void setMBeanServer(MBeanServer server)
189
//TODO: -TME Implement
192
public void setInvoker(ServerInvoker invoker)
194
//TODO: -TME Implement
197
public Object invoke(InvocationRequest invocation) throws Throwable
202
public void addListener(InvokerCallbackHandler callbackHandler)
204
//TODO: -TME Implement
207
public void removeListener(InvokerCallbackHandler callbackHandler)
209
//TODO: -TME Implement