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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/transport/socket/shutdown/ProcessInvocationShutdownTestCase.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 2009, 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.transport.socket.shutdown;
23
 
 
24
 
import java.io.IOException;
25
 
import java.net.InetAddress;
26
 
import java.util.HashMap;
27
 
import java.util.Map;
28
 
 
29
 
import javax.management.MBeanServer;
30
 
 
31
 
import junit.framework.TestCase;
32
 
 
33
 
import org.apache.log4j.ConsoleAppender;
34
 
import org.apache.log4j.Level;
35
 
import org.apache.log4j.Logger;
36
 
import org.apache.log4j.PatternLayout;
37
 
import org.jboss.remoting.Client;
38
 
import org.jboss.remoting.InvocationRequest;
39
 
import org.jboss.remoting.InvokerLocator;
40
 
import org.jboss.remoting.InvokerRegistry;
41
 
import org.jboss.remoting.ServerInvocationHandler;
42
 
import org.jboss.remoting.ServerInvoker;
43
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
44
 
import org.jboss.remoting.transport.Connector;
45
 
import org.jboss.remoting.transport.PortUtil;
46
 
import org.jboss.remoting.transport.ServerFactory;
47
 
import org.jboss.remoting.transport.socket.LRUPool;
48
 
import org.jboss.remoting.transport.socket.SocketServerInvoker;
49
 
import org.jboss.remoting.transport.socket.TransportClientFactory;
50
 
 
51
 
 
52
 
/**
53
 
 * Unit test for JBREM-1076.
54
 
 * 
55
 
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
56
 
 * @version $Rev$
57
 
 * <p>
58
 
 * Copyright Apr 12, 2009
59
 
 * </p>
60
 
 */
61
 
public class ProcessInvocationShutdownTestCase extends TestCase
62
 
{
63
 
   private static Logger log = Logger.getLogger(ProcessInvocationShutdownTestCase.class);
64
 
   
65
 
   private static boolean firstTime = true;
66
 
   
67
 
   protected String host;
68
 
   protected int port;
69
 
   protected String locatorURI;
70
 
   protected InvokerLocator serverLocator;
71
 
   protected Connector connector;
72
 
   protected TestInvocationHandler invocationHandler;
73
 
   protected SocketServerInvoker socketServerInvoker;
74
 
 
75
 
   
76
 
   public void setUp() throws Exception
77
 
   {
78
 
      if (firstTime)
79
 
      {
80
 
         firstTime = false;
81
 
         Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
82
 
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
83
 
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
84
 
         PatternLayout layout = new PatternLayout(pattern);
85
 
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
86
 
         Logger.getRootLogger().addAppender(consoleAppender);  
87
 
      }
88
 
   }
89
 
 
90
 
   
91
 
   public void tearDown()
92
 
   {
93
 
   }
94
 
   
95
 
   
96
 
   public void testShutdown() throws Throwable
97
 
   {
98
 
      log.info("entering " + getName());
99
 
      
100
 
      // Start server.
101
 
      setupServer();
102
 
      assertTrue(connector.getServerInvoker() instanceof TestServerInvoker);
103
 
      log.info("using a TestServerInvoker");
104
 
      
105
 
      // Create client.
106
 
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
107
 
      HashMap clientConfig = new HashMap();
108
 
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
109
 
      addExtraClientConfig(clientConfig);
110
 
      final Client client = new Client(clientLocator, clientConfig);
111
 
      client.connect();
112
 
      log.info("client is connected");
113
 
      
114
 
      // Start SocketServerInvoker.processInvocation().
115
 
      new Thread()
116
 
      {
117
 
         public void run()
118
 
         {
119
 
            try
120
 
            {
121
 
               client.invoke("abc");
122
 
            }
123
 
            catch (Throwable e)
124
 
            {
125
 
               e.printStackTrace();
126
 
            }
127
 
         }
128
 
      }.start();
129
 
      
130
 
      Thread.sleep(4000);
131
 
      shutdownServer();
132
 
      Thread.sleep(4000);
133
 
      assertFalse(TestLRUPool.called);
134
 
      log.info(getName() + " PASSES");
135
 
   }
136
 
   
137
 
   
138
 
   protected String getTransport()
139
 
   {
140
 
      return "test";
141
 
   }
142
 
   
143
 
   
144
 
   protected void addExtraClientConfig(Map config) {}
145
 
   protected void addExtraServerConfig(Map config) {}
146
 
   
147
 
 
148
 
   protected void setupServer() throws Exception
149
 
   {
150
 
      InvokerRegistry.registerInvokerFactories(getTransport(), TransportClientFactory.class, TestTransportServerFactory.class);
151
 
      host = InetAddress.getLocalHost().getHostAddress();
152
 
      port = PortUtil.findFreePort(host);
153
 
      locatorURI = getTransport() + "://" + host + ":" + port;
154
 
      String metadata = System.getProperty("remoting.metadata");
155
 
      if (metadata != null)
156
 
      {
157
 
         locatorURI += "/?" + metadata;
158
 
      }
159
 
      serverLocator = new InvokerLocator(locatorURI);
160
 
      log.info("Starting remoting server with locator uri of: " + locatorURI);
161
 
      HashMap config = new HashMap();
162
 
      config.put(InvokerLocator.FORCE_REMOTE, "true");
163
 
      addExtraServerConfig(config);
164
 
      connector = new Connector(serverLocator, config);
165
 
      connector.create();
166
 
      invocationHandler = new TestInvocationHandler();
167
 
      connector.addInvocationHandler("test", invocationHandler);
168
 
      connector.start();
169
 
      socketServerInvoker = (SocketServerInvoker) connector.getServerInvoker();
170
 
      socketServerInvoker.setMaxPoolSize(0);
171
 
   }
172
 
   
173
 
   
174
 
   protected void shutdownServer() throws Exception
175
 
   {
176
 
      if (connector != null)
177
 
         connector.stop();
178
 
   }
179
 
   
180
 
   
181
 
   static class TestInvocationHandler implements ServerInvocationHandler
182
 
   {
183
 
      public void addListener(InvokerCallbackHandler callbackHandler) {}
184
 
      public Object invoke(final InvocationRequest invocation) throws Throwable
185
 
      {
186
 
         return invocation.getParameter();
187
 
      }
188
 
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
189
 
      public void setMBeanServer(MBeanServer server) {}
190
 
      public void setInvoker(ServerInvoker invoker) {}
191
 
   }
192
 
 
193
 
   static class TestLRUPool extends LRUPool
194
 
   {
195
 
      static public boolean called;
196
 
      
197
 
      public TestLRUPool(int min, int max)
198
 
      {
199
 
         super(min, max);
200
 
      }  
201
 
      public void insert(Object key, Object o)
202
 
      {
203
 
         log.info(this + ".insert() called");
204
 
         called = true;
205
 
      }
206
 
   }
207
 
   
208
 
   static class TestServerInvoker extends SocketServerInvoker
209
 
   {
210
 
      public TestServerInvoker(InvokerLocator locator, Map configuration)
211
 
      {
212
 
         super(locator, configuration);
213
 
      }
214
 
      public TestServerInvoker(InvokerLocator locator)
215
 
      {
216
 
         super(locator);
217
 
      }
218
 
      public synchronized void start() throws IOException
219
 
      {
220
 
         super.start();
221
 
         clientpool = new TestLRUPool(2, maxPoolSize);
222
 
         clientpool.create(); 
223
 
      }
224
 
   }
225
 
   
226
 
   static public class TestTransportServerFactory implements ServerFactory
227
 
   {
228
 
      public boolean called;
229
 
      
230
 
      public ServerInvoker createServerInvoker(InvokerLocator locator, Map config)
231
 
      {
232
 
         called = true;
233
 
         log.info(this + ".createServerInvoker() called");
234
 
         return new TestServerInvoker(locator, config);
235
 
      }
236
 
      public boolean supportsSSL()
237
 
      {
238
 
         return false;
239
 
      }
240
 
   }
241
 
}
 
 
b'\\ No newline at end of file'