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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/detection/multicast/deadlock/MulticastDetectorServer.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 org.apache.log4j.Level;
 
4
import org.jboss.jrunit.extensions.ServerTestCase;
 
5
import org.jboss.remoting.Client;
 
6
import org.jboss.remoting.InvocationRequest;
 
7
import org.jboss.remoting.InvokerLocator;
 
8
import org.jboss.remoting.ServerInvocationHandler;
 
9
import org.jboss.remoting.ServerInvoker;
 
10
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
11
import org.jboss.remoting.detection.multicast.MulticastDetector;
 
12
import org.jboss.remoting.network.NetworkRegistry;
 
13
import org.jboss.remoting.security.SSLSocketBuilder;
 
14
import org.jboss.remoting.transport.Connector;
 
15
import org.jboss.test.remoting.TestUtil;
 
16
 
 
17
import javax.management.MBeanServer;
 
18
import javax.management.MBeanServerFactory;
 
19
import javax.management.ObjectName;
 
20
 
 
21
import java.net.InetAddress;
 
22
import java.security.AccessController;
 
23
import java.security.PrivilegedActionException;
 
24
import java.security.PrivilegedExceptionAction;
 
25
import java.util.HashMap;
 
26
import java.util.Map;
 
27
 
 
28
/**
 
29
 * Test for JBREM-553
 
30
 *
 
31
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
32
 */
 
33
public class MulticastDetectorServer extends ServerTestCase
 
34
{
 
35
   private MulticastDetector detector;
 
36
   private Connector connector;
 
37
   private NetworkRegistry registry;
 
38
   private Map config = new HashMap();
 
39
 
 
40
   public void setUp() throws Exception
 
41
   {
 
42
      detector = new MulticastDetector();
 
43
 
 
44
      System.setProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
 
45
      System.out.println("jboss.identity = " + System.getProperty("jboss.identity"));
 
46
 
 
47
      MBeanServer server = null;
 
48
      
 
49
      try
 
50
      {
 
51
          server = (MBeanServer) AccessController.doPrivileged( new PrivilegedExceptionAction()
 
52
          {
 
53
             public Object run() throws Exception
 
54
             {
 
55
                 return MBeanServerFactory.createMBeanServer();
 
56
             }
 
57
          });
 
58
      }
 
59
      catch (PrivilegedActionException e)
 
60
      {
 
61
          throw (Exception) e.getCause();
 
62
      }
 
63
 
 
64
      registry = NetworkRegistry.getInstance();
 
65
      server.registerMBean(registry, new ObjectName("remoting:type=NetworkRegistry"));
 
66
 
 
67
      int port = TestUtil.getRandomPort();
 
68
      System.out.println("port = " + port);
 
69
 
 
70
      String host = InetAddress.getLocalHost().getHostAddress();
 
71
      String bindAddr = System.getProperty("jrunit.bind_addr", host);
 
72
      InvokerLocator locator = new InvokerLocator("sslsocket://" + bindAddr + ":" + port);
 
73
 
 
74
      System.out.println("Starting remoting server with locator uri of: " + locator.getLocatorURI());
 
75
 
 
76
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
 
77
      String trustStoreFilePath = this.getClass().getResource("ssl/.truststore").getFile();
 
78
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
 
79
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
 
80
      String keyStoreFilePath = this.getClass().getResource("ssl/.keystore").getFile();
 
81
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
 
82
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
 
83
      config.put(SSLSocketBuilder.REMOTING_CLIENT_AUTH_MODE, SSLSocketBuilder.CLIENT_AUTH_MODE_WANT);
 
84
 
 
85
      connector = new Connector(config);
 
86
      connector.setInvokerLocator(locator.getLocatorURI());
 
87
 
 
88
      ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + locator.getProtocol());
 
89
      server.registerMBean(connector, obj);
 
90
      connector.create();
 
91
 
 
92
      TestHandler handler = new TestHandler();
 
93
      connector.addInvocationHandler("mock", handler);
 
94
      connector.start();
 
95
 
 
96
      //Need to set new domain for identity
 
97
      server.registerMBean(detector, new ObjectName("remoting:type=MulticastDetector"));
 
98
 
 
99
      detector.start();
 
100
 
 
101
   }
 
102
 
 
103
   public void tearDown() throws Exception
 
104
   {
 
105
      if (detector != null)
 
106
      {
 
107
         detector.stop();
 
108
      }
 
109
      if (connector != null)
 
110
      {
 
111
         connector.stop();
 
112
         connector.destroy();
 
113
      }
 
114
   }
 
115
 
 
116
   public static void main(String[] args)
 
117
   {
 
118
      org.apache.log4j.BasicConfigurator.configure();
 
119
      org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
 
120
 
 
121
      try
 
122
      {
 
123
         MulticastDetectorServer test = new MulticastDetectorServer();
 
124
         test.setUp();
 
125
         Thread.currentThread().sleep(10000);
 
126
         test.tearDown();
 
127
      }
 
128
      catch (Exception e)
 
129
      {
 
130
         e.printStackTrace();
 
131
      }
 
132
 
 
133
   }
 
134
 
 
135
   public class TestHandler implements ServerInvocationHandler
 
136
   {
 
137
 
 
138
      public void setMBeanServer(MBeanServer server)
 
139
      {
 
140
         //TODO: -TME Implement
 
141
      }
 
142
 
 
143
      public void setInvoker(ServerInvoker invoker)
 
144
      {
 
145
         //TODO: -TME Implement
 
146
      }
 
147
 
 
148
      public Object invoke(InvocationRequest invocation) throws Throwable
 
149
      {
 
150
         Object obj = invocation.getParameter();
 
151
         if (obj instanceof String)
 
152
         {
 
153
            String locator = (String) obj;
 
154
            ServerClient client = new ServerClient(locator);
 
155
            Thread t = new Thread(client, "server_client_thread");
 
156
            //t.setDaemon(false);
 
157
            t.setDaemon(true);
 
158
            t.start();
 
159
         }
 
160
 
 
161
 
 
162
         return "foobar";
 
163
      }
 
164
 
 
165
      public void addListener(InvokerCallbackHandler callbackHandler)
 
166
      {
 
167
         //TODO: -TME Implement
 
168
      }
 
169
 
 
170
      public void removeListener(InvokerCallbackHandler callbackHandler)
 
171
      {
 
172
         //TODO: -TME Implement
 
173
      }
 
174
   }
 
175
 
 
176
   public class ServerClient implements Runnable
 
177
   {
 
178
      private String locatorUrl = null;
 
179
 
 
180
      public ServerClient(String locator)
 
181
      {
 
182
         this.locatorUrl = locator;
 
183
      }
 
184
 
 
185
      public void run()
 
186
      {
 
187
 
 
188
         try
 
189
         {
 
190
            Client remotingClient = null;
 
191
            for (int x = 0; x < 2; x++)
 
192
            {
 
193
               remotingClient = new Client(new InvokerLocator(locatorUrl), config);
 
194
               remotingClient.connect();
 
195
               Object ret = remotingClient.invoke("bar");
 
196
               System.out.println("client returned " + ret);
 
197
               Thread.currentThread().sleep(3000);
 
198
            }
 
199
            remotingClient.disconnect();
 
200
            System.out.println("server client disconnected.");
 
201
 
 
202
         }
 
203
         catch (Exception e)
 
204
         {
 
205
            e.printStackTrace();
 
206
         }
 
207
         catch (Throwable throwable)
 
208
         {
 
209
            throwable.printStackTrace();
 
210
         }
 
211
 
 
212
      }
 
213
   }
 
214
 
 
215
 
 
216
}