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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/timeout/QuickDisconnectServerParent.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.timeout;
 
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 org.apache.log4j.ConsoleAppender;
 
31
import org.apache.log4j.Logger;
 
32
import org.apache.log4j.PatternLayout;
 
33
import org.jboss.jrunit.extensions.ServerTestCase;
 
34
import org.jboss.logging.XLevel;
 
35
import org.jboss.remoting.Client;
 
36
import org.jboss.remoting.ConnectionListener;
 
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.InvokerCallbackHandler;
 
42
import org.jboss.remoting.transport.Connector;
 
43
import org.jboss.remoting.transport.PortUtil;
 
44
 
 
45
 
 
46
/** 
 
47
 * QuickDisconnectTestParent verifies that LeasePinger can set its
 
48
 * own short timeout value when it is called during Client.disconnect(), so that,
 
49
 * even if the server is unavailable, Client.disconnect() can finish quickly.
 
50
 * 
 
51
 * It also tests that Client can set its own short timeout value when in
 
52
 * removeListener().
 
53
 * 
 
54
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
55
 * @version $Revision: 2922 $
 
56
 * <p>
 
57
 * Copyright Jan 24, 2007
 
58
 * </p>
 
59
 */
 
60
public abstract class QuickDisconnectServerParent extends ServerTestCase
 
61
{
 
62
   public static final String START_SERVER = "startServer";
 
63
   public static final int port = 3999;
 
64
   
 
65
   protected static Logger log = Logger.getLogger(QuickDisconnectServerParent.class);
 
66
   protected static boolean firstTime = true;
 
67
   
 
68
   protected Connector connector;
 
69
   protected boolean receivedConnectionException;
 
70
   
 
71
   public void setUp() throws Exception
 
72
   {
 
73
      String host = InetAddress.getLocalHost().getHostAddress();
 
74
      String locatorURI = getTransport() + "://" + host + ":" + port;
 
75
      InvokerLocator locator = new InvokerLocator(locatorURI);
 
76
      HashMap serverConfig = new HashMap();
 
77
      addServerConfig(serverConfig);
 
78
      connector = new Connector(locator, serverConfig);
 
79
      connector.create();
 
80
      connector.addInvocationHandler("test", new TestHandler());
 
81
      connector.addConnectionListener(new TestListener());
 
82
      connector.start();
 
83
   }
 
84
   
 
85
   
 
86
   public void tearDown()
 
87
   {
 
88
      connector.stop();
 
89
   }
 
90
   
 
91
   
 
92
   protected abstract String getTransport();
 
93
 
 
94
   
 
95
   protected void addServerConfig(Map config)
 
96
   {  
 
97
   }
 
98
   
 
99
   
 
100
   public class TestHandler implements ServerInvocationHandler
 
101
   {
 
102
      public void setMBeanServer(MBeanServer server) {}
 
103
      public void setInvoker(ServerInvoker invoker) {}
 
104
 
 
105
      public Object invoke(InvocationRequest invocation) throws Throwable
 
106
      {
 
107
         if (START_SERVER.equals(invocation.getParameter()))
 
108
         {
 
109
            int port = PortUtil.findFreePort(InetAddress.getLocalHost().getHostName());
 
110
            new ServerStarter(port).start();
 
111
            return new Integer(port);
 
112
         }
 
113
         else
 
114
         {
 
115
            return invocation.getParameter();
 
116
         }
 
117
      }
 
118
 
 
119
      public void addListener(InvokerCallbackHandler callbackHandler) {}
 
120
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
 
121
   }
 
122
   
 
123
   
 
124
   public class TestListener implements ConnectionListener
 
125
   {
 
126
      public void handleConnectionException(Throwable throwable, Client client)
 
127
      {
 
128
         log.info("received connection exception");
 
129
      }
 
130
   }
 
131
   
 
132
   
 
133
   public class ServerStarter extends Thread
 
134
   {
 
135
      int port;
 
136
      
 
137
      public ServerStarter(int port)
 
138
      {
 
139
         this.port = port;
 
140
      }
 
141
      
 
142
      public void run()
 
143
      {
 
144
         try
 
145
         {
 
146
            String host = InetAddress.getLocalHost().getHostAddress();
 
147
            String locatorURI = getTransport() + "://" + host + ":" + port;
 
148
            InvokerLocator locator = new InvokerLocator(locatorURI);
 
149
            HashMap serverConfig = new HashMap();
 
150
            addServerConfig(serverConfig);
 
151
            final Connector connector = new Connector(locator, serverConfig);
 
152
            connector.create();
 
153
            connector.addInvocationHandler("test", new TestHandler());
 
154
            connector.addConnectionListener(new TestListener());
 
155
            connector.start();
 
156
            log.info("Connector started: " + connector.getInvokerLocator());
 
157
            Thread.sleep(10000);
 
158
            connector.stop();
 
159
            log.info("Connector stopped: " + connector.getInvokerLocator());
 
160
         }
 
161
         catch (Exception e)
 
162
         {
 
163
            
 
164
         }
 
165
      }
 
166
   }
 
167
}