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.marshall.compress;
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.MicroRemoteClientInvoker;
41
import org.jboss.remoting.ServerInvocationHandler;
42
import org.jboss.remoting.ServerInvoker;
43
import org.jboss.remoting.callback.InvokerCallbackHandler;
44
import org.jboss.remoting.marshal.MarshalFactory;
45
import org.jboss.remoting.marshal.compress.CompressingMarshaller;
46
import org.jboss.remoting.marshal.compress.CompressingUnMarshaller;
47
import org.jboss.remoting.transport.Connector;
48
import org.jboss.remoting.transport.PortUtil;
52
* Unit test for JBREM-677.
54
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
55
* @version $Revision: 1.1 $
57
* Copyright Mar 6, 2008
60
abstract public class CompressionStressTestParent extends TestCase
62
private static Logger log = Logger.getLogger(CompressionStressTestParent.class);
64
private static boolean firstTime = true;
66
protected String host;
68
protected String locatorURI;
69
protected InvokerLocator serverLocator;
70
protected Connector connector;
71
protected TestInvocationHandler invocationHandler;
74
public void setUp() throws Exception
79
Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
80
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
81
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
82
PatternLayout layout = new PatternLayout(pattern);
83
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
84
Logger.getRootLogger().addAppender(consoleAppender);
85
MarshalFactory.addMarshaller("compress", new CompressingMarshaller(), new CompressingUnMarshaller());
90
public void tearDown()
95
public void testCompression() 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");
112
assertEquals("abc", client.invoke("abc"));
113
log.info("connection is good");
115
// Verify CompressingMarshaller / CompressingUnMarshaller are being used.
116
MicroRemoteClientInvoker invoker = (MicroRemoteClientInvoker) client.getInvoker();
117
assertTrue(invoker.getMarshaller() instanceof CompressingMarshaller);
118
assertTrue(invoker.getUnMarshaller() instanceof CompressingUnMarshaller);
120
StringBuffer sb = new StringBuffer(10000);
121
for (int i = 0; i < 1000; i++)
123
sb.append(((char) i % 10));
124
String msg = sb.toString();
125
Object result = client.invoke(msg);
126
assertEquals("failed on invocation " + i, msg, result);
128
if ((i + 1) % 100 == 0)
130
log.info("invocations: " + (i + 1));
131
log.info("length: " + msg.length());
137
log.info(getName() + " PASSES");
141
abstract protected String getTransport();
144
protected void addExtraClientConfig(Map config) {}
145
protected void addExtraServerConfig(Map config) {}
148
protected void setupServer() throws Exception
150
host = InetAddress.getLocalHost().getHostAddress();
151
port = PortUtil.findFreePort(host);
152
locatorURI = getTransport() + "://" + host + ":" + port + "/?datatype=compress";
153
String parameters = System.getProperty("remoting.metadata");
154
if (parameters != null) locatorURI += "&" + parameters;
155
serverLocator = new InvokerLocator(locatorURI);
156
log.info("Starting remoting server with locator uri of: " + locatorURI);
157
HashMap config = new HashMap();
158
config.put(InvokerLocator.FORCE_REMOTE, "true");
159
addExtraServerConfig(config);
160
connector = new Connector(serverLocator, config);
162
invocationHandler = new TestInvocationHandler();
163
connector.addInvocationHandler("test", invocationHandler);
168
protected void shutdownServer() throws Exception
170
if (connector != null)
175
static class TestInvocationHandler implements ServerInvocationHandler
177
public void addListener(InvokerCallbackHandler callbackHandler) {}
178
public Object invoke(final InvocationRequest invocation) throws Throwable
180
// log.info("parameter: " + invocation.getParameter());
181
// log.info("server: type: " + invocation.getParameter().getClass());
182
// log.info("server length: " + ((String)invocation.getParameter()).length());
183
return invocation.getParameter();
185
public void removeListener(InvokerCallbackHandler callbackHandler) {}
186
public void setMBeanServer(MBeanServer server) {}
187
public void setInvoker(ServerInvoker invoker) {}
b'\\ No newline at end of file'