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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/version/ConfigurableVersionTestParent.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.version;
 
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.Remoting;
 
41
import org.jboss.remoting.ServerInvocationHandler;
 
42
import org.jboss.remoting.ServerInvoker;
 
43
import org.jboss.remoting.Version;
 
44
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
45
import org.jboss.remoting.transport.Connector;
 
46
import org.jboss.remoting.transport.PortUtil;
 
47
 
 
48
 
 
49
/**
 
50
 * Unit test for JBREM-764.
 
51
 * 
 
52
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
53
 * @version $Revision: 1.1 $
 
54
 * <p>
 
55
 * Copyright Mar 6, 2008
 
56
 * </p>
 
57
 */
 
58
public abstract class ConfigurableVersionTestParent extends TestCase
 
59
{
 
60
   private static Logger log = Logger.getLogger(ConfigurableVersionTestParent.class);
 
61
   
 
62
   private static boolean firstTime = true;
 
63
   
 
64
   protected String host;
 
65
   protected int port;
 
66
   protected String locatorURI;
 
67
   protected InvokerLocator serverLocator;
 
68
   protected Connector connector;
 
69
   protected TestInvocationHandler invocationHandler;
 
70
 
 
71
   
 
72
   public void setUp() throws Exception
 
73
   {
 
74
      if (firstTime)
 
75
      {
 
76
         firstTime = false;
 
77
         Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
 
78
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
 
79
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
 
80
         PatternLayout layout = new PatternLayout(pattern);
 
81
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
 
82
         Logger.getRootLogger().addAppender(consoleAppender);  
 
83
      }
 
84
   }
 
85
 
 
86
   
 
87
   public void tearDown()
 
88
   {
 
89
   }
 
90
   
 
91
   
 
92
   public void testVersions() throws Throwable
 
93
   {
 
94
      log.info("entering " + getName());
 
95
      
 
96
      // Start servers.
 
97
      Connector connector1 = setupServer(Version.VERSION_1);
 
98
      Connector connector2 = setupServer(Version.VERSION_2);
 
99
      Connector connector22 = setupServer(Version.VERSION_2_2);
 
100
      Connector connector0 = setupServer(-1);
 
101
      
 
102
      // Create clients.
 
103
      Client client1 = setupClient(connector1);
 
104
      Client client2 = setupClient(connector2);
 
105
      Client client22 = setupClient(connector22);
 
106
      Client client0 = setupClient(connector0);
 
107
      
 
108
      // Test connections.
 
109
      assertEquals("abc", client1.invoke("abc"));
 
110
      assertEquals("abc", client2.invoke("abc"));
 
111
      assertEquals("abc", client22.invoke("abc"));
 
112
      assertEquals("abc", client0.invoke("abc"));
 
113
      
 
114
      client1.disconnect();
 
115
      client2.disconnect();
 
116
      client22.disconnect();
 
117
      client0.disconnect();
 
118
      
 
119
      connector1.stop();
 
120
      connector2.stop();
 
121
      connector22.stop();
 
122
      connector0.stop();
 
123
      
 
124
      log.info(getName() + " PASSES");
 
125
   }
 
126
   
 
127
   
 
128
   abstract protected String getTransport();
 
129
   
 
130
   
 
131
   protected void addExtraClientConfig(Map config) {}
 
132
   protected void addExtraServerConfig(Map config) {}
 
133
   
 
134
 
 
135
   protected Connector setupServer(int version) throws Exception
 
136
   {
 
137
      host = InetAddress.getLocalHost().getHostAddress();
 
138
      port = PortUtil.findFreePort(host);
 
139
      locatorURI = getTransport() + "://" + host + ":" + port + "/?";
 
140
      
 
141
      if (version > 0)
 
142
      {
 
143
         locatorURI += Remoting.REMOTING_VERSION + "=" + version;
 
144
      }
 
145
      else
 
146
      {
 
147
         locatorURI += "x=y";
 
148
      }
 
149
      
 
150
      String parameters = System.getProperty("remoting.metadata");
 
151
      if (parameters != null)
 
152
      {
 
153
         locatorURI += "&" + parameters;
 
154
      }
 
155
      
 
156
      serverLocator = new InvokerLocator(locatorURI);
 
157
      log.info("Starting remoting server with locator uri of: " + locatorURI);
 
158
      HashMap config = new HashMap();
 
159
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
160
      addExtraServerConfig(config);
 
161
      connector = new Connector(serverLocator, config);
 
162
      connector.create();
 
163
      invocationHandler = new TestInvocationHandler();
 
164
      connector.addInvocationHandler("test", invocationHandler);
 
165
      connector.start();
 
166
      return connector;
 
167
   }
 
168
   
 
169
   
 
170
   protected Client setupClient(Connector connector) throws Exception
 
171
   {
 
172
      InvokerLocator locator = connector.getLocator();
 
173
      HashMap config = new HashMap();
 
174
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
175
      addExtraClientConfig(config);
 
176
      Client client = new Client(locator, config);
 
177
      client.connect();
 
178
      log.info("client is connected to: " + locator);
 
179
      return client;
 
180
   }
 
181
   
 
182
   
 
183
   static class TestInvocationHandler implements ServerInvocationHandler
 
184
   {
 
185
      public void addListener(InvokerCallbackHandler callbackHandler) {}
 
186
      public Object invoke(final InvocationRequest invocation) throws Throwable
 
187
      {
 
188
         return invocation.getParameter();
 
189
      }
 
190
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
 
191
      public void setMBeanServer(MBeanServer server) {}
 
192
      public void setInvoker(ServerInvoker invoker) {}
 
193
   }
 
194
}
 
 
b'\\ No newline at end of file'