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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/transport/InvokerServerTest.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
 
 
23
package org.jboss.test.remoting.transport;
 
24
 
 
25
import java.util.HashMap;
 
26
import java.util.Iterator;
 
27
import java.util.Map;
 
28
import java.util.Set;
 
29
import org.jboss.jrunit.extensions.ServerTestCase;
 
30
import org.jboss.logging.Logger;
 
31
import org.jboss.remoting.InvokerLocator;
 
32
import org.jboss.remoting.ServerInvocationHandler;
 
33
import org.jboss.remoting.transport.Connector;
 
34
import org.jboss.test.remoting.TestUtil;
 
35
import org.jboss.test.remoting.performance.synchronous.PerformanceServerTest;
 
36
import org.jboss.test.remoting.performance.synchronous.PerformanceTestCase;
 
37
import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
 
38
 
 
39
/**
 
40
 * This is the concrete test for invoker server.
 
41
 *
 
42
 * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
 
43
 */
 
44
public abstract class InvokerServerTest extends ServerTestCase
 
45
{
 
46
   protected int serverPort = 9091;  // default port
 
47
   protected Connector connector = null;
 
48
 
 
49
   protected static final Logger log = Logger.getLogger(InvokerServerTest.class);
 
50
 
 
51
   public abstract String getTransport();
 
52
 
 
53
   public String getSerializationType()
 
54
   {
 
55
      return null;
 
56
   }
 
57
 
 
58
   public void init(Map metatdata) throws Exception
 
59
   {
 
60
 
 
61
      if(serverPort < 0)
 
62
      {
 
63
         serverPort = TestUtil.getRandomPort();
 
64
      }
 
65
      log.debug("port = " + serverPort);
 
66
 
 
67
      connector = new Connector();
 
68
      InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata));
 
69
      connector.setInvokerLocator(locator.getLocatorURI());
 
70
      System.out.println("Creating connector with locator of " + locator);
 
71
      connector.create();
 
72
      connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler());
 
73
      connector.start();
 
74
   }
 
75
 
 
76
   protected String buildLocatorURI(Map metadata)
 
77
   {
 
78
      String host = System.getProperty("jrunit.bind_addr", "localhost");
 
79
 
 
80
      if(metadata == null || metadata.size() == 0)
 
81
      {
 
82
         return getTransport() + "://" + host + ":" + serverPort;
 
83
      }
 
84
      else
 
85
      {
 
86
         StringBuffer uriBuffer = new StringBuffer(getTransport() + "://" + host + ":" + serverPort);
 
87
 
 
88
         Set keys = metadata.keySet();
 
89
         if(keys.size() > 0)
 
90
         {
 
91
            uriBuffer.append("/?");
 
92
         }
 
93
         Iterator itr = keys.iterator();
 
94
         while(itr.hasNext())
 
95
         {
 
96
            String key = (String) itr.next();
 
97
            String value = (String) metadata.get(key);
 
98
            uriBuffer.append(key).append("=").append(value).append("&");
 
99
         }
 
100
         return uriBuffer.substring(0, uriBuffer.length() - 1);
 
101
      }
 
102
   }
 
103
 
 
104
   protected String getSubsystem()
 
105
   {
 
106
      return "mock";
 
107
   }
 
108
 
 
109
   protected ServerInvocationHandler getServerInvocationHandler()
 
110
   {
 
111
      return new MockServerInvocationHandler();
 
112
   }
 
113
 
 
114
   public void setUp() throws Exception
 
115
   {
 
116
      Map metadata = new HashMap();
 
117
      String newMetadata = System.getProperty(PerformanceTestCase.REMOTING_METADATA);
 
118
      if(newMetadata != null && newMetadata.length() > 0)
 
119
      {
 
120
         metadata.putAll(PerformanceServerTest.parseMetadataString(newMetadata));
 
121
      }
 
122
      init(metadata);
 
123
   }
 
124
 
 
125
   public void tearDown() throws Exception
 
126
   {
 
127
      if(connector != null)
 
128
      {
 
129
         connector.stop();
 
130
         connector.destroy();
 
131
      }
 
132
   }
 
133
 
 
134
}