~ubuntu-branches/ubuntu/oneiric/libjboss-remoting-java/oneiric

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/marshall/compress/CompressionStressTestParent.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
6
*
 
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.
 
11
*
 
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.
 
16
*
 
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.
 
21
*/
 
22
package org.jboss.test.remoting.marshall.compress;
 
23
 
 
24
import java.net.InetAddress;
 
25
import java.util.HashMap;
 
26
import java.util.Map;
 
27
 
 
28
import javax.management.MBeanServer;
 
29
 
 
30
import junit.framework.TestCase;
 
31
 
 
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;
 
49
 
 
50
 
 
51
/**
 
52
 * Unit test for JBREM-677.
 
53
 * 
 
54
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
55
 * @version $Revision: 1.1 $
 
56
 * <p>
 
57
 * Copyright Mar 6, 2008
 
58
 * </p>
 
59
 */
 
60
abstract public class CompressionStressTestParent extends TestCase
 
61
{
 
62
   private static Logger log = Logger.getLogger(CompressionStressTestParent.class);
 
63
   
 
64
   private static boolean firstTime = true;
 
65
   
 
66
   protected String host;
 
67
   protected int port;
 
68
   protected String locatorURI;
 
69
   protected InvokerLocator serverLocator;
 
70
   protected Connector connector;
 
71
   protected TestInvocationHandler invocationHandler;
 
72
 
 
73
   
 
74
   public void setUp() throws Exception
 
75
   {
 
76
      if (firstTime)
 
77
      {
 
78
         firstTime = false;
 
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());
 
86
      }
 
87
   }
 
88
 
 
89
   
 
90
   public void tearDown()
 
91
   {
 
92
   }
 
93
   
 
94
   
 
95
   public void testCompression() throws Throwable
 
96
   {
 
97
      log.info("entering " + getName());
 
98
      
 
99
      // Start server.
 
100
      setupServer();
 
101
      
 
102
      // Create client.
 
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);
 
108
      client.connect();
 
109
      log.info("client is connected");
 
110
      
 
111
      // Test connections.
 
112
      assertEquals("abc", client.invoke("abc"));
 
113
      log.info("connection is good");
 
114
      
 
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);
 
119
      
 
120
      StringBuffer sb = new StringBuffer(10000);
 
121
      for (int i = 0; i < 1000; i++)
 
122
      {
 
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);
 
127
 
 
128
         if ((i + 1) % 100 == 0)
 
129
         {
 
130
            log.info("invocations: " + (i + 1));
 
131
            log.info("length: " + msg.length());
 
132
         }
 
133
      }
 
134
 
 
135
      client.disconnect();
 
136
      shutdownServer();
 
137
      log.info(getName() + " PASSES");
 
138
   }
 
139
   
 
140
   
 
141
   abstract protected String getTransport();
 
142
   
 
143
   
 
144
   protected void addExtraClientConfig(Map config) {}
 
145
   protected void addExtraServerConfig(Map config) {}
 
146
   
 
147
 
 
148
   protected void setupServer() throws Exception
 
149
   {
 
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);
 
161
      connector.create();
 
162
      invocationHandler = new TestInvocationHandler();
 
163
      connector.addInvocationHandler("test", invocationHandler);
 
164
      connector.start();
 
165
   }
 
166
   
 
167
   
 
168
   protected void shutdownServer() throws Exception
 
169
   {
 
170
      if (connector != null)
 
171
         connector.stop();
 
172
   }
 
173
   
 
174
   
 
175
   static class TestInvocationHandler implements ServerInvocationHandler
 
176
   {
 
177
      public void addListener(InvokerCallbackHandler callbackHandler) {}
 
178
      public Object invoke(final InvocationRequest invocation) throws Throwable
 
179
      {
 
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();
 
184
      }
 
185
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
 
186
      public void setMBeanServer(MBeanServer server) {}
 
187
      public void setInvoker(ServerInvoker invoker) {}
 
188
   }
 
189
}
 
 
b'\\ No newline at end of file'