1
package org.jboss.test.remoting.transport.socket.ssl.timeout;
3
import java.lang.reflect.Field;
4
import java.net.InetAddress;
5
import java.util.HashMap;
6
import java.util.Iterator;
10
import org.jboss.remoting.Client;
11
import org.jboss.remoting.InvokerLocator;
12
import org.jboss.remoting.ServerInvoker;
13
import org.jboss.remoting.transport.ClientInvoker;
14
import org.jboss.remoting.transport.Connector;
15
import org.jboss.remoting.transport.PortUtil;
16
import org.jboss.remoting.transport.socket.LRUPool;
17
import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
18
import org.jboss.remoting.transport.socket.ServerThread;
19
import org.jboss.remoting.transport.socket.SocketServerInvoker;
20
import org.jboss.remoting.transport.socket.SocketWrapper;
21
import org.jboss.test.remoting.timeout.SSLPerInvocationTimeoutTestRoot;
25
* See javadoc for PerInvocationTimeoutTestRoot.
27
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
28
* @version $Revision: 2936 $
30
* Copyright Feb 6, 2007
33
public class SSLSocketPerInvocationTimeoutTestCase extends SSLPerInvocationTimeoutTestRoot
36
* This test verifies that the timeout for a socket wrapper gets reset after
37
* an invocation with an invocation specific timeout has been executed.
39
public void testTimeoutReset() throws Throwable
41
log.info("entering " + getName());
42
ClientInvoker invoker = client.getInvoker();
43
assertTrue(invoker instanceof MicroSocketClientInvoker);
44
Field field = MicroSocketClientInvoker.class.getDeclaredField("pool");
45
field.setAccessible(true);
46
List pool = (List) field.get(invoker);
47
assertEquals(0, pool.size());
49
Object response = client.invoke(NO_WAIT);
50
assertEquals(NO_WAIT, response);
51
assertEquals(1, pool.size());
52
SocketWrapper socket = (SocketWrapper) pool.get(0);
53
assertEquals(CONFIGURED_TIMEOUT, socket.getTimeout());
55
HashMap metadata = new HashMap();
56
metadata.put(ServerInvoker.TIMEOUT, "1000");
57
response = client.invoke(NO_WAIT, metadata);
58
assertEquals(NO_WAIT, response);
59
assertEquals(1, pool.size());
60
socket = (SocketWrapper) pool.get(0);
61
assertEquals(CONFIGURED_TIMEOUT, socket.getTimeout());
65
// This test verifies that a temporary timeout value gets passed when a new
66
// socket wrapper is created. It is important that the socket wrapper gets
67
// the temporary timeout value because creating object streams entails i/o
69
public void testNewSocketTimeout() throws Throwable
71
log.info("entering " + getName());
72
String host = InetAddress.getLocalHost().getHostAddress();
73
int port = PortUtil.findFreePort(host);
74
String locatorURI = getTransport() + "://" + host + ":" + port;
75
InvokerLocator locator = new InvokerLocator(locatorURI);
76
HashMap serverConfig = new HashMap();
77
addServerConfig(serverConfig);
78
final Connector connector = new Connector(locator, serverConfig);
80
connector.addInvocationHandler("test", new TestHandler());
83
// Disable the server so that the client will need to create a new socket, and
84
// so that the creation of the socket wrapper will fail.
91
// Give the client a chance to connect to the server, then
92
// disable the server.
94
ServerInvoker si = connector.getServerInvoker();
95
assertTrue(si instanceof SocketServerInvoker);
96
SocketServerInvoker ssi = (SocketServerInvoker) si;
97
Field field = SocketServerInvoker.class.getDeclaredField("clientpool");
98
field.setAccessible(true);
99
LRUPool clientpool = (LRUPool) field.get(ssi);
100
Set threads = clientpool.getContents();
101
Iterator it = threads.iterator();
104
ServerThread t = (ServerThread) it.next();
108
ssi.setMaxPoolSize(0);
109
log.info("server is disabled");
118
HashMap clientConfig = new HashMap();
119
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
120
clientConfig.put(ServerInvoker.TIMEOUT, "20000");
121
clientConfig.put(Client.ENABLE_LEASE, "true");
122
addClientConfig(clientConfig);
123
final Client client = new Client(locator, clientConfig);
125
Object response = client.invoke("test 1");
126
assertEquals("test 1", response);
127
log.info("first invocation succeeded");
129
class BooleanHolder {public boolean value;}
130
final BooleanHolder timedOut = new BooleanHolder();
131
timedOut.value = false;
139
// Wait for the server to be disabled.
142
// This invocation will require the creation of a new socket, which
143
// should promptly time out.
144
HashMap metadata = new HashMap();
145
metadata.put(ServerInvoker.TIMEOUT, "1000");
146
client.invoke("test 3", metadata);
147
fail("failed to time out");
151
timedOut.value = true;
152
log.info("time out", e);
157
// It should take the Client a little while for LeasePinger's attempts to contact
158
// the server to time out. Wait for 4 seconds after the call to Client.invoke()
159
// and then verify that the Client has timed out according to the temporary timeout
160
// value 1000 instead of the configureed value 20000.
162
assertTrue(timedOut.value);
166
log.info(getName() + " PASSES");
170
protected String getTransport()