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.detection.jndi;
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;
41
* Just tests that detector A sees detector B when B comes online then off.
43
* @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
45
public class JNDIDetectorTest2 extends ServerTestCase
47
private int detectorPort = 1099;
48
private String contextFactory = "org.jnp.interfaces.NamingContextFactory";
49
private String urlPackage = "org.jboss.naming:org.jnp.interfaces";
51
private JNDIDetector detector;
52
private Connector connector;
53
private NetworkRegistry registry;
55
private static final Logger log = Logger.getLogger(JNDIDetectorTest2.class);
57
public void setUp() throws Exception
59
String detectorHost = InetAddress.getLocalHost().getHostName();
61
detector = new JNDIDetector();
62
detector.setCleanDetectionNumber(2);
64
System.setProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
65
System.out.println("jboss.identity = " + System.getProperty("jboss.identity"));
67
MBeanServer server = MBeanServerFactory.createMBeanServer();
69
//registry = NetworkRegistry.getInstance();
70
registry = JNDIDetectorTest2.TestNetworkRegistry.createNetworkRegistry();
71
server.registerMBean(registry, new ObjectName("remoting:type=NetworkRegistry"));
73
int port = TestUtil.getRandomPort();
74
System.out.println("port = " + port);
76
String host = InetAddress.getLocalHost().getHostAddress();
77
String bindAddr = System.getProperty("jrunit.bind_addr", host);
78
InvokerLocator locator = new InvokerLocator("socket://" + bindAddr + ":" + port);
80
System.out.println("Starting remoting server with locator uri of: " + locator.getLocatorURI());
81
connector = new Connector();
82
connector.setInvokerLocator(locator.getLocatorURI());
85
MockServerInvocationHandler handler = new MockServerInvocationHandler();
86
connector.addInvocationHandler("mock", handler);
88
ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + locator.getProtocol());
89
server.registerMBean(connector, obj);
93
//Need to set new domain for identity
94
server.registerMBean(detector, new ObjectName("remoting:type=JNDIDetector"));
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);
105
public void testDetector2() throws Exception
107
Thread.currentThread().sleep(10000);
109
NetworkInstance[] server = registry.getServers();
110
if(server != null && server.length > 0)
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);
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);
123
if(connector != null)
136
public void tearDown() throws Exception
138
if(connector != null)
152
public static void main(String[] args)
154
org.apache.log4j.BasicConfigurator.configure();
155
org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
159
JNDIDetectorTest2 test = new JNDIDetectorTest2();
161
test.testDetector2();
171
private static class TestNetworkRegistry extends NetworkRegistry
173
public static NetworkRegistry createNetworkRegistry()
175
return new JNDIDetectorTest2.TestNetworkRegistry();
b'\\ No newline at end of file'