2
* JBoss, Home of Professional Open Source
3
* Copyright 2009, 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.datatype;
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.remoting.Client;
37
import org.jboss.remoting.InvocationRequest;
38
import org.jboss.remoting.InvokerLocator;
39
import org.jboss.remoting.MicroRemoteClientInvoker;
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.ClientInvoker;
44
import org.jboss.remoting.transport.Connector;
45
import org.jboss.remoting.transport.PortUtil;
47
import EDU.oswego.cs.dl.util.concurrent.Rendezvous;
51
* Unit test for JBREM-1109.
53
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
56
* Copyright Apr 8, 2009
59
public class DataTypeRaceTestCase extends TestCase
61
private static Logger log = Logger.getLogger(DataTypeRaceTestCase.class);
63
private static boolean firstTime = true;
64
protected static String dataType;
66
protected String host;
68
protected String locatorURI;
69
protected InvokerLocator serverLocator;
70
protected Connector connector;
71
protected TestInvocationHandler invocationHandler;
72
protected Object lock = new Object();
75
public void setUp() throws Exception
80
Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
81
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
82
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
83
PatternLayout layout = new PatternLayout(pattern);
84
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
85
Logger.getRootLogger().addAppender(consoleAppender);
90
public void tearDown()
95
public void testDataTypeRace() throws Throwable
97
log.info("entering " + getName());
103
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
104
HashMap clientConfig = new HashMap();
105
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
106
addExtraClientConfig(clientConfig);
107
Client client = new Client(clientLocator, clientConfig);
109
log.info("client is connected");
111
// Test datatype race.
112
MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
115
TestThread[] threads = new TestThread[THREADS];
116
Rendezvous startBarrier = new Rendezvous(THREADS);
117
Rendezvous stopBarrier = new Rendezvous(THREADS + 1);
119
log.info(getName() + " creating " + THREADS + " threads");
120
for (int i = 0; i < THREADS; i++)
122
threads[i] = new TestThread(clientInvoker, startBarrier, stopBarrier, i);
126
log.info(getName() + " waiting on stopBarrier");
127
rendezvous(stopBarrier);
128
log.info(getName() + " checking threads");
130
for (int i = 0; i < THREADS; i++)
132
assertTrue("failure in " + threads[i], threads[i].ok);
137
log.info(getName() + " PASSES");
141
protected String getTransport()
147
protected void addExtraClientConfig(Map config) {}
148
protected void addExtraServerConfig(Map config) {}
151
protected void setupServer() throws Exception
153
host = InetAddress.getLocalHost().getHostAddress();
154
port = PortUtil.findFreePort(host);
155
locatorURI = getTransport() + "://" + host + ":" + port;
156
String metadata = System.getProperty("remoting.metadata");
157
if (metadata != null)
159
locatorURI += "/?" + metadata;
161
serverLocator = new InvokerLocator(locatorURI);
162
log.info("Starting remoting server with locator uri of: " + locatorURI);
163
HashMap config = new HashMap();
164
config.put(InvokerLocator.FORCE_REMOTE, "true");
165
addExtraServerConfig(config);
166
connector = new Connector(serverLocator, config);
168
invocationHandler = new TestInvocationHandler();
169
connector.addInvocationHandler("test", invocationHandler);
174
protected void shutdownServer() throws Exception
176
if (connector != null)
181
protected static void rendezvous(Rendezvous barrier)
187
barrier.rendezvous(null);
190
catch (InterruptedException e1)
198
static class TestInvocationHandler implements ServerInvocationHandler
200
public void addListener(InvokerCallbackHandler callbackHandler) {}
201
public Object invoke(final InvocationRequest invocation) throws Throwable
203
return invocation.getParameter();
205
public void removeListener(InvokerCallbackHandler callbackHandler) {}
206
public void setMBeanServer(MBeanServer server) {}
207
public void setInvoker(ServerInvoker invoker) {}
210
static class TestThread extends Thread
213
ClientInvoker clientInvoker;
214
Rendezvous startBarrier;
215
Rendezvous stopBarrier;
216
InvocationRequest request = new InvocationRequest(null, null, "abc", null, null, null);
219
public TestThread(ClientInvoker clientInvoker, Rendezvous startBarrier, Rendezvous stopBarrier, int number)
221
this.clientInvoker = clientInvoker;
222
this.startBarrier = startBarrier;
223
this.stopBarrier = stopBarrier;
224
name = "TestThread[" + number + "]";
229
// log.debug(this + " waiting on startBarrier");
230
rendezvous(startBarrier);
231
// log.debug(this + " executing");
234
clientInvoker.invoke(request);
235
// log.debug(this + " waiting on stopBarrier");
237
rendezvous(stopBarrier);
238
// log.debug(this + " done");
243
rendezvous(stopBarrier);
247
public String toString()
b'\\ No newline at end of file'