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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/connection/deadlock/DeadlockTestServer.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 2008, Red Hat Middleware LLC, and individual contributors
4
 
 * as indicated by the @author tags. See the copyright.txt file in the
5
 
 * distribution for a 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.connection.deadlock;
24
 
 
25
 
import java.net.InetAddress;
26
 
import java.util.HashMap;
27
 
import java.util.Map;
28
 
 
29
 
import javax.management.MBeanServer;
30
 
 
31
 
import org.apache.log4j.ConsoleAppender;
32
 
import org.apache.log4j.Level;
33
 
import org.apache.log4j.Logger;
34
 
import org.apache.log4j.PatternLayout;
35
 
import org.jboss.jrunit.extensions.ServerTestCase;
36
 
import org.jboss.remoting.Client;
37
 
import org.jboss.remoting.ConnectionListener;
38
 
import org.jboss.remoting.InvocationRequest;
39
 
import org.jboss.remoting.InvokerLocator;
40
 
import org.jboss.remoting.ServerInvocationHandler;
41
 
import org.jboss.remoting.ServerInvoker;
42
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
43
 
import org.jboss.remoting.transport.socket.SocketServerInvoker;
44
 
 
45
 
 
46
 
/**
47
 
 * Unit test for JBREM-1070.
48
 
 * 
49
 
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
50
 
 * @version 
51
 
 * <p>
52
 
 * Copyright Nov 29, 2008
53
 
 * </p>
54
 
 */
55
 
public class DeadlockTestServer extends ServerTestCase
56
 
{
57
 
   private static Logger log = Logger.getLogger(DeadlockTestServer.class);
58
 
   
59
 
   private static boolean firstTime = true;
60
 
   
61
 
   protected String host;
62
 
   protected int port = 7777;
63
 
   protected String locatorURI;
64
 
   protected InvokerLocator serverLocator;
65
 
   protected TestServerInvoker serverInvoker;
66
 
   protected TestInvocationHandler invocationHandler;
67
 
   
68
 
   
69
 
   public static void main(String[] args)
70
 
   {
71
 
      try
72
 
      {
73
 
         DeadlockTestServer server = new DeadlockTestServer();
74
 
         server.setUp();
75
 
         Thread.sleep(600000);
76
 
         server.shutdownServer();
77
 
      }
78
 
      catch (Throwable t)
79
 
      {
80
 
         log.error("error", t);
81
 
      }
82
 
   }
83
 
 
84
 
   
85
 
   public void setUp() throws Exception
86
 
   {
87
 
      if (firstTime)
88
 
      {
89
 
         firstTime = false;
90
 
         Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
91
 
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
92
 
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
93
 
         PatternLayout layout = new PatternLayout(pattern);
94
 
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
95
 
         Logger.getRootLogger().addAppender(consoleAppender);  
96
 
      }
97
 
      
98
 
      setupServer();
99
 
   }
100
 
 
101
 
   
102
 
   public void tearDown() throws Exception
103
 
   {
104
 
      shutdownServer();
105
 
   }
106
 
   
107
 
   
108
 
   protected String getTransport()
109
 
   {
110
 
      return "socket";
111
 
   }
112
 
   
113
 
   
114
 
   protected void addExtraClientConfig(Map config) {}
115
 
   protected void addExtraServerConfig(Map config) {}
116
 
   
117
 
 
118
 
   protected void setupServer() throws Exception
119
 
   {
120
 
      host = InetAddress.getLocalHost().getHostAddress();
121
 
      locatorURI = getTransport() + "://" + host + ":" + port;
122
 
      String metadata = System.getProperty("remoting.metadata");
123
 
      if (metadata != null)
124
 
      {
125
 
         locatorURI += "/?" + metadata;
126
 
      }
127
 
      serverLocator = new InvokerLocator(locatorURI);
128
 
      log.info("Starting remoting server with locator uri of: " + locatorURI);
129
 
      HashMap config = new HashMap();
130
 
      config.put(InvokerLocator.FORCE_REMOTE, "true");
131
 
      addExtraServerConfig(config);
132
 
      
133
 
      serverInvoker = new TestServerInvoker(serverLocator, config);
134
 
      serverInvoker.create();
135
 
      invocationHandler = new TestInvocationHandler();
136
 
      serverInvoker.addInvocationHandler("test", invocationHandler);
137
 
      serverInvoker.start();
138
 
      log.info("TestServerInvoker(" + locatorURI + ") started");
139
 
   }
140
 
   
141
 
   
142
 
   protected void shutdownServer() throws Exception
143
 
   {
144
 
      if (serverInvoker != null)
145
 
         serverInvoker.stop();
146
 
   }
147
 
   
148
 
   
149
 
   static class TestInvocationHandler implements ServerInvocationHandler
150
 
   {
151
 
      public void addListener(InvokerCallbackHandler callbackHandler) {}
152
 
      public Object invoke(final InvocationRequest invocation) throws Throwable
153
 
      {
154
 
         return invocation.getParameter();
155
 
      }
156
 
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
157
 
      public void setMBeanServer(MBeanServer server) {}
158
 
      public void setInvoker(ServerInvoker invoker) {}
159
 
   }
160
 
   
161
 
   static class TestServerInvoker extends SocketServerInvoker
162
 
   {
163
 
      public TestServerInvoker(InvokerLocator locator, Map config)
164
 
      {
165
 
         super(locator, config);
166
 
         log.info("TestServerInvoker: " + locator);
167
 
      }
168
 
      public Object invoke(InvocationRequest invocation) throws Throwable
169
 
      {
170
 
         if ("$PING$".equals(invocation.getParameter()))
171
 
         {
172
 
            log.info("TestServerInvoker received $PING$");
173
 
            Thread.sleep(10000);
174
 
            throw new Exception("got $PING$");
175
 
         }
176
 
         else
177
 
         {
178
 
            return super.invoke(invocation);
179
 
         }
180
 
      }
181
 
   }
182
 
 
183
 
   static class TestConnectionListener implements ConnectionListener
184
 
   {
185
 
      public boolean ok;
186
 
      
187
 
      public void handleConnectionException(Throwable throwable, Client client)
188
 
      {
189
 
         ok = true;
190
 
         log.info("handleConnectionException() called");
191
 
      }
192
 
   }
193
 
}
 
 
b'\\ No newline at end of file'