2
* JBoss, Home of Professional Open Source.
3
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
4
* as indicated by the @author tags. See the copyright.txt file in the
5
* distribution for a 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.connection.deadlock;
25
import java.net.InetAddress;
26
import java.util.HashMap;
29
import junit.framework.TestCase;
31
import org.apache.log4j.ConsoleAppender;
32
import org.apache.log4j.Level;
33
import org.apache.log4j.Logger;
34
import org.apache.log4j.PatternLayout;
35
import org.jboss.remoting.Client;
36
import org.jboss.remoting.ConnectionListener;
37
import org.jboss.remoting.ConnectionValidator;
38
import org.jboss.remoting.InvokerLocator;
41
* Unit test for JBREM-1070.
43
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
46
* Copyright Nov 29, 2008
49
public class DeadlockTestClient extends TestCase
51
private static Logger log = Logger.getLogger(DeadlockTestClient.class);
53
private static boolean firstTime = true;
55
protected String host;
56
protected int port = 7777;
57
protected String locatorURI;
58
protected InvokerLocator serverLocator;
61
public void setUp() throws Exception
66
Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
67
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
68
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
69
PatternLayout layout = new PatternLayout(pattern);
70
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
71
Logger.getRootLogger().addAppender(consoleAppender);
76
public void tearDown()
81
public void testForDeadlock() throws Throwable
83
log.info("entering " + getName());
84
for (int i = 0; i < 10; i++)
86
assertTrue("failed execution: " + i, doTest());
87
log.info("execution " + i + " PASSES\n");
89
log.info(getName() + " PASSES");
93
public boolean doTest() throws Throwable
96
host = InetAddress.getLocalHost().getHostAddress();
97
locatorURI = getTransport() + "://" + host + ":" + port;
98
String metadata = System.getProperty("remoting.metadata");
101
locatorURI += "/?" + metadata;
103
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
104
HashMap clientConfig = new HashMap();
105
clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, "5000");
106
clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, "1000");
107
addExtraClientConfig(clientConfig);
108
Client client = new Client(clientLocator, clientConfig);
110
log.info("client is connected");
113
assertEquals("abc", client.invoke("abc"));
114
log.info("connection is good");
116
// Add ConnectionListener.
117
TestConnectionListener listener = new TestConnectionListener();
118
client.addConnectionListener(listener);
120
// Wait for notification.
121
for (int i = 0; i < 20; i++)
135
protected String getTransport()
141
protected void addExtraClientConfig(Map config) {}
144
static class TestConnectionListener implements ConnectionListener
148
public void handleConnectionException(Throwable throwable, Client client)
151
log.info("handleConnectionException() called");
b'\\ No newline at end of file'