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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTest2.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
 
/*
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.detection.jndi;
24
 
 
25
 
import java.net.InetAddress;
26
 
import javax.management.MBeanServer;
27
 
import javax.management.MBeanServerFactory;
28
 
import javax.management.ObjectName;
29
 
import org.apache.log4j.Level;
30
 
import org.jboss.jrunit.extensions.ServerTestCase;
31
 
import org.jboss.logging.Logger;
32
 
import org.jboss.remoting.InvokerLocator;
33
 
import org.jboss.remoting.detection.jndi.JNDIDetector;
34
 
import org.jboss.remoting.network.NetworkInstance;
35
 
import org.jboss.remoting.network.NetworkRegistry;
36
 
import org.jboss.remoting.transport.Connector;
37
 
import org.jboss.test.remoting.TestUtil;
38
 
import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
39
 
 
40
 
/**
41
 
 * Just tests that detector A sees detector B when B comes online then off.
42
 
 *
43
 
 * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
44
 
 */
45
 
public class JNDIDetectorTest2 extends ServerTestCase
46
 
{
47
 
   private int detectorPort = 1099;
48
 
   private String contextFactory = "org.jnp.interfaces.NamingContextFactory";
49
 
   private String urlPackage = "org.jboss.naming:org.jnp.interfaces";
50
 
 
51
 
   private JNDIDetector detector;
52
 
   private Connector connector;
53
 
   private NetworkRegistry registry;
54
 
 
55
 
   private static final Logger log = Logger.getLogger(JNDIDetectorTest2.class);
56
 
 
57
 
   public void setUp() throws Exception
58
 
   {
59
 
      String detectorHost = InetAddress.getLocalHost().getHostName();
60
 
 
61
 
      detector = new JNDIDetector();
62
 
      detector.setCleanDetectionNumber(2);
63
 
 
64
 
      System.setProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
65
 
      System.out.println("jboss.identity = " + System.getProperty("jboss.identity"));
66
 
 
67
 
      MBeanServer server = MBeanServerFactory.createMBeanServer();
68
 
 
69
 
      //registry = NetworkRegistry.getInstance();
70
 
      registry = JNDIDetectorTest2.TestNetworkRegistry.createNetworkRegistry();
71
 
      server.registerMBean(registry, new ObjectName("remoting:type=NetworkRegistry"));
72
 
 
73
 
      int port = TestUtil.getRandomPort();
74
 
      System.out.println("port = " + port);
75
 
 
76
 
      String host = InetAddress.getLocalHost().getHostAddress();
77
 
      String bindAddr = System.getProperty("jrunit.bind_addr", host);
78
 
      InvokerLocator locator = new InvokerLocator("socket://" + bindAddr + ":" + port);
79
 
 
80
 
      System.out.println("Starting remoting server with locator uri of: " + locator.getLocatorURI());
81
 
      connector = new Connector();
82
 
      connector.setInvokerLocator(locator.getLocatorURI());
83
 
      connector.create();
84
 
 
85
 
      MockServerInvocationHandler handler = new MockServerInvocationHandler();
86
 
      connector.addInvocationHandler("mock", handler);
87
 
 
88
 
      ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + locator.getProtocol());
89
 
      server.registerMBean(connector, obj);
90
 
      //connector.create();
91
 
      connector.start();
92
 
 
93
 
      //Need to set new domain for identity
94
 
      server.registerMBean(detector, new ObjectName("remoting:type=JNDIDetector"));
95
 
 
96
 
      // set config info for detector and start it.
97
 
      detector.setPort(detectorPort);
98
 
      detector.setHost(detectorHost);
99
 
      detector.setContextFactory(contextFactory);
100
 
      detector.setURLPackage(urlPackage);
101
 
      detector.start();
102
 
 
103
 
   }
104
 
 
105
 
   public void testDetector2() throws Exception
106
 
   {
107
 
      Thread.currentThread().sleep(10000);
108
 
 
109
 
      NetworkInstance[] server = registry.getServers();
110
 
      if(server != null && server.length > 0)
111
 
      {
112
 
         System.out.println("PASS - got more than zero servers detected.");
113
 
         log.info("PASS - got more than zero servers detected.");
114
 
         assertTrue("Detected server.", true);
115
 
      }
116
 
      else
117
 
      {
118
 
         System.out.println("FAIL - did not detect any other server.");
119
 
         log.info("FAIL - did not detect any other server.");
120
 
         assertTrue("Did not detect any servers.", false);
121
 
      }
122
 
 
123
 
      if(connector != null)
124
 
      {
125
 
         connector.stop();
126
 
         connector.destroy();
127
 
         connector = null;
128
 
      }
129
 
      if(detector != null)
130
 
      {
131
 
         detector.stop();
132
 
         detector = null;
133
 
      }
134
 
   }
135
 
 
136
 
   public void tearDown() throws Exception
137
 
   {
138
 
      if(connector != null)
139
 
      {
140
 
         connector.stop();
141
 
         connector.destroy();
142
 
         connector = null;
143
 
      }
144
 
      if(detector != null)
145
 
      {
146
 
         detector.stop();
147
 
         detector = null;
148
 
      }
149
 
 
150
 
   }
151
 
 
152
 
   public static void main(String[] args)
153
 
   {
154
 
      org.apache.log4j.BasicConfigurator.configure();
155
 
      org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
156
 
 
157
 
      try
158
 
      {
159
 
         JNDIDetectorTest2 test = new JNDIDetectorTest2();
160
 
         test.setUp();
161
 
         test.testDetector2();
162
 
         test.tearDown();
163
 
      }
164
 
      catch(Exception e)
165
 
      {
166
 
         e.printStackTrace();
167
 
      }
168
 
 
169
 
   }
170
 
 
171
 
   private static class TestNetworkRegistry extends NetworkRegistry
172
 
   {
173
 
      public static NetworkRegistry createNetworkRegistry()
174
 
      {
175
 
         return new JNDIDetectorTest2.TestNetworkRegistry();
176
 
      }
177
 
   }
178
 
 
179
 
}
 
 
b'\\ No newline at end of file'