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.
22
package org.jboss.test.remoting.transport.socket.connection;
24
import java.net.InetAddress;
25
import java.util.HashMap;
28
import javax.management.MBeanServer;
30
import junit.framework.TestCase;
32
import org.apache.log4j.ConsoleAppender;
33
import org.apache.log4j.Level;
34
import org.apache.log4j.Logger;
35
import org.apache.log4j.PatternLayout;
36
import org.jboss.logging.XLevel;
37
import org.jboss.remoting.Client;
38
import org.jboss.remoting.InvocationRequest;
39
import org.jboss.remoting.InvokerLocator;
40
import org.jboss.remoting.ServerInvocationHandler;
41
import org.jboss.remoting.ServerInvoker;
42
import org.jboss.remoting.callback.InvokerCallbackHandler;
43
import org.jboss.remoting.transport.Connector;
44
import org.jboss.remoting.transport.PortUtil;
45
import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
48
* Unit test for JBREM-986.
50
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
51
* @version $Revision: 1.1 $
53
* Copyright May 28, 2008
56
public class ConnectionWaitTestCase extends TestCase
58
private static Logger log = Logger.getLogger(ConnectionWaitTestCase.class);
60
private static boolean firstTime = true;
62
protected String host;
64
protected String locatorURI;
65
protected InvokerLocator serverLocator;
66
protected Connector connector;
67
protected TestInvocationHandler invocationHandler;
70
public void setUp() throws Exception
75
Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
76
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
77
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
78
PatternLayout layout = new PatternLayout(pattern);
79
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
80
Logger.getRootLogger().addAppender(consoleAppender);
85
public void tearDown()
90
public void testConnectionWaitDefault() throws Throwable
92
log.info("entering " + getName());
98
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
99
HashMap clientConfig = new HashMap();
100
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
101
addExtraClientConfig(clientConfig);
102
Client client = new Client(clientLocator, clientConfig);
104
log.info("client is connected");
107
assertEquals("abc", client.invoke("abc"));
108
log.info("connection is good");
110
// Verify connectionWait is set to default value.
111
MicroSocketClientInvoker invoker = (MicroSocketClientInvoker) client.getInvoker();
112
assertEquals(MicroSocketClientInvoker.CONNECTION_WAIT_DEFAULT, invoker.getConnectionWait());
116
log.info(getName() + " PASSES");
120
public void testConnectionWaitSetInLocator() throws Throwable
122
log.info("entering " + getName());
128
String clientLocatorURI = locatorURI + "/?" + MicroSocketClientInvoker.CONNECTION_WAIT + "=12345";
129
InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
130
HashMap clientConfig = new HashMap();
131
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
132
addExtraClientConfig(clientConfig);
133
Client client = new Client(clientLocator, clientConfig);
135
log.info("client is connected");
138
assertEquals("abc", client.invoke("abc"));
139
log.info("connection is good");
141
// Verify connectionWait is set to configured value.
142
MicroSocketClientInvoker invoker = (MicroSocketClientInvoker) client.getInvoker();
143
assertEquals(12345, invoker.getConnectionWait());
147
log.info(getName() + " PASSES");
151
public void testConnectionWaitSetInConfigMap() throws Throwable
153
log.info("entering " + getName());
159
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
160
HashMap clientConfig = new HashMap();
161
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
162
clientConfig.put(MicroSocketClientInvoker.CONNECTION_WAIT, "12345");
163
addExtraClientConfig(clientConfig);
164
Client client = new Client(clientLocator, clientConfig);
166
log.info("client is connected");
169
assertEquals("abc", client.invoke("abc"));
170
log.info("connection is good");
172
// Verify connectionWait is set to configured value.
173
MicroSocketClientInvoker invoker = (MicroSocketClientInvoker) client.getInvoker();
174
assertEquals(12345, invoker.getConnectionWait());
178
log.info(getName() + " PASSES");
182
protected String getTransport()
188
protected void addExtraClientConfig(Map config) {}
189
protected void addExtraServerConfig(Map config) {}
192
protected void setupServer() throws Exception
194
host = InetAddress.getLocalHost().getHostAddress();
195
port = PortUtil.findFreePort(host);
196
locatorURI = getTransport() + "://" + host + ":" + port;
197
serverLocator = new InvokerLocator(locatorURI);
198
log.info("Starting remoting server with locator uri of: " + locatorURI);
199
HashMap config = new HashMap();
200
config.put(InvokerLocator.FORCE_REMOTE, "true");
201
addExtraServerConfig(config);
202
connector = new Connector(serverLocator, config);
204
invocationHandler = new TestInvocationHandler();
205
connector.addInvocationHandler("test", invocationHandler);
210
protected void shutdownServer() throws Exception
212
if (connector != null)
217
static class TestInvocationHandler implements ServerInvocationHandler
219
public void addListener(InvokerCallbackHandler callbackHandler) {}
220
public Object invoke(final InvocationRequest invocation) throws Throwable
222
return invocation.getParameter();
224
public void removeListener(InvokerCallbackHandler callbackHandler) {}
225
public void setMBeanServer(MBeanServer server) {}
226
public void setInvoker(ServerInvoker invoker) {}
b'\\ No newline at end of file'