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.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.remoting.Client;
37
import org.jboss.remoting.InvocationRequest;
38
import org.jboss.remoting.InvokerLocator;
39
import org.jboss.remoting.ServerInvocationHandler;
40
import org.jboss.remoting.ServerInvoker;
41
import org.jboss.remoting.callback.Callback;
42
import org.jboss.remoting.callback.HandleCallbackException;
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-1077.
54
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
57
* Copyright Jul 27, 2009
60
public class NewCompressingMarshallerTestCase extends TestCase
62
private static Logger log = Logger.getLogger(NewCompressingMarshallerTestCase.class);
64
private static boolean firstTime = true;
65
private static char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
66
private static int COUNT = 10000;
68
protected String host;
70
protected String locatorURI;
71
protected InvokerLocator serverLocator;
72
protected Connector connector;
73
protected TestInvocationHandler invocationHandler;
76
public void setUp() throws Exception
81
Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
82
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
83
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
84
PatternLayout layout = new PatternLayout(pattern);
85
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
86
Logger.getRootLogger().addAppender(consoleAppender);
88
MarshalFactory.addMarshaller(CompressingMarshaller.DATATYPE,
89
new CompressingMarshaller(),
90
new CompressingUnMarshaller());
95
public void tearDown()
100
public void testCompression() throws Throwable
102
log.info("entering " + getName());
108
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
109
HashMap clientConfig = new HashMap();
110
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
111
addExtraClientConfig(clientConfig);
112
Client client = new Client(clientLocator, clientConfig);
114
log.info("client is connected");
117
assertEquals("abc", client.invoke("abc"));
118
log.info("connection is good");
120
StringBuffer sb = new StringBuffer();
121
for (int i = 0; i < COUNT; i++)
123
String msg = sb.append(digits[i % 10]).toString();
124
Object response = client.invoke(msg);
125
assertEquals("error on invocation " + i, msg, response);
126
if (i % (COUNT / 10) == 0)
128
log.info("OK: " + i);
134
log.info(getName() + " PASSES");
138
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=" + CompressingMarshaller.DATATYPE;
153
String metadata = System.getProperty("remoting.metadata");
154
if (metadata != null)
156
locatorURI += "&" + metadata;
158
serverLocator = new InvokerLocator(locatorURI);
159
log.info("Starting remoting server with locator uri of: " + locatorURI);
160
HashMap config = new HashMap();
161
config.put(InvokerLocator.FORCE_REMOTE, "true");
162
addExtraServerConfig(config);
163
connector = new Connector(serverLocator, config);
165
invocationHandler = new TestInvocationHandler();
166
connector.addInvocationHandler("test", invocationHandler);
171
protected void shutdownServer() throws Exception
173
if (connector != null)
178
static class TestInvocationHandler implements ServerInvocationHandler
180
public void addListener(InvokerCallbackHandler callbackHandler) {}
181
public Object invoke(final InvocationRequest invocation) throws Throwable
183
return invocation.getParameter();
185
public void removeListener(InvokerCallbackHandler callbackHandler) {}
186
public void setMBeanServer(MBeanServer server) {}
187
public void setInvoker(ServerInvoker invoker) {}
191
static class TestCallbackHandler implements InvokerCallbackHandler
193
public void handleCallback(Callback callback) throws HandleCallbackException
195
log.info("received callback");
b'\\ No newline at end of file'