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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/detection/multicast/deadlock/MulticastDetectorClient.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
package org.jboss.test.remoting.detection.multicast.deadlock;
 
2
 
 
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;
 
15
 
 
16
import javax.management.MBeanServer;
 
17
import javax.management.MBeanServerFactory;
 
18
import javax.management.ObjectName;
 
19
 
 
20
import java.net.InetAddress;
 
21
import java.util.HashMap;
 
22
import java.util.Map;
 
23
 
 
24
/**
 
25
 * Test for JBREM-553
 
26
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
27
 */
 
28
public class MulticastDetectorClient extends TestCase
 
29
{
 
30
   private MulticastDetector detector;
 
31
   private NetworkRegistry registry;
 
32
   private Connector connector;
 
33
 
 
34
   private Client remotingClient = null;
 
35
 
 
36
   public void setUp() throws Exception
 
37
   {
 
38
      detector = new MulticastDetector();
 
39
 
 
40
      System.setProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
 
41
      System.out.println("jboss.identity = " + System.getProperty("jboss.identity"));
 
42
 
 
43
      MBeanServer server = MBeanServerFactory.createMBeanServer();
 
44
 
 
45
      registry = NetworkRegistry.getInstance();
 
46
      server.registerMBean(registry, new ObjectName("remoting:type=NetworkRegistry"));
 
47
 
 
48
      //Need to set new domain for identity
 
49
      server.registerMBean(detector, new ObjectName("remoting:type=JNDIDetector"));
 
50
   }
 
51
 
 
52
   public void testDetection() throws Exception
 
53
   {
 
54
      detector.start();
 
55
      long start = System.currentTimeMillis();
 
56
      NetworkInstance[] instances = detector.forceDetection();
 
57
      long end = System.currentTimeMillis();
 
58
 
 
59
      System.out.println("instance = " + instances);
 
60
      System.out.println("force detection took " + (end - start) + " milliseconds.");
 
61
 
 
62
      String host = InetAddress.getLocalHost().getHostAddress();
 
63
      String bindAddr = System.getProperty("jrunit.bind_addr", host);
 
64
      
 
65
//      assertEquals(1, instances.length);
 
66
 
 
67
      // now create a client
 
68
      InvokerLocator serverLocator = null;
 
69
      for (int i = 0; i < instances.length; i++)
 
70
      {     
 
71
         NetworkInstance ni = instances[i];
 
72
         InvokerLocator[] locator = ni.getLocators();
 
73
         for (int j = 0; j < locator.length; j++)
 
74
         {
 
75
            if (locator[j].getHost().equals(bindAddr))
 
76
            {
 
77
               serverLocator = locator[j];
 
78
               break;
 
79
            }
 
80
         }
 
81
      }
 
82
 
 
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);
 
93
 
 
94
      remotingClient = new Client(serverLocator, config);
 
95
      remotingClient.connect();
 
96
 
 
97
      String invokerLocatorurl = "sslsocket://" + bindAddr + ":8700";
 
98
      connector = new Connector(invokerLocatorurl, config);
 
99
      connector.create();
 
100
 
 
101
      connector.addInvocationHandler("test", new LocalHandler());
 
102
      connector.start();
 
103
 
 
104
      try
 
105
      {
 
106
         Object ret = remotingClient.invoke(invokerLocatorurl);
 
107
         System.out.println("return from calling server is " + ret);
 
108
      }
 
109
      catch (Throwable throwable)
 
110
      {
 
111
         throwable.printStackTrace();
 
112
         throw new Exception(throwable.getMessage());
 
113
      }
 
114
 
 
115
//      Thread.currentThread().sleep(20000);
 
116
//
 
117
//      System.out.println("Disconnecting.");
 
118
//
 
119
//      remotingClient.disconnect();
 
120
//
 
121
//      System.out.println("Disconnected.");
 
122
   }
 
123
 
 
124
   public void disconnect() throws InterruptedException
 
125
   {
 
126
      Thread.currentThread().sleep(30000);
 
127
 
 
128
      System.out.println("Disconnecting.");
 
129
 
 
130
      remotingClient.disconnect();
 
131
 
 
132
      System.out.println("Disconnected.");
 
133
 
 
134
      remotingClient = null;
 
135
 
 
136
   }
 
137
 
 
138
   public void tearDown() throws Exception
 
139
   {
 
140
      if (remotingClient != null)
 
141
      {
 
142
         remotingClient.disconnect();
 
143
      }
 
144
      if (detector != null)
 
145
      {
 
146
         detector.stop();
 
147
      }
 
148
      if(connector != null)
 
149
      {
 
150
         connector.stop();
 
151
         connector.destroy();
 
152
      }
 
153
   }
 
154
 
 
155
   public static void main(String[] args)
 
156
   {
 
157
      MulticastDetectorClient client = new MulticastDetectorClient();
 
158
      try
 
159
      {
 
160
         client.setUp();
 
161
         client.testDetection();
 
162
         client.disconnect();
 
163
         Thread.sleep(5000);
 
164
         System.out.println("done testing.");
 
165
      }
 
166
      catch(Throwable t)
 
167
      {
 
168
         t.printStackTrace();
 
169
      }
 
170
      finally
 
171
      {
 
172
         try
 
173
         {
 
174
            client.tearDown();
 
175
         }
 
176
         catch (Exception e)
 
177
         {
 
178
            e.printStackTrace();
 
179
         }
 
180
      }
 
181
   }
 
182
 
 
183
 
 
184
   public class LocalHandler implements ServerInvocationHandler
 
185
   {
 
186
 
 
187
      public void setMBeanServer(MBeanServer server)
 
188
      {
 
189
         //TODO: -TME Implement
 
190
      }
 
191
 
 
192
      public void setInvoker(ServerInvoker invoker)
 
193
      {
 
194
         //TODO: -TME Implement
 
195
      }
 
196
 
 
197
      public Object invoke(InvocationRequest invocation) throws Throwable
 
198
      {
 
199
         return "foo";
 
200
      }
 
201
 
 
202
      public void addListener(InvokerCallbackHandler callbackHandler)
 
203
      {
 
204
         //TODO: -TME Implement
 
205
      }
 
206
 
 
207
      public void removeListener(InvokerCallbackHandler callbackHandler)
 
208
      {
 
209
         //TODO: -TME Implement
 
210
      }
 
211
   }
 
212
 
 
213
 
 
214
}