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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/lease/LeaseTestServer.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.lease;
24
 
 
25
 
import org.jboss.jrunit.extensions.ServerTestCase;
26
 
import org.jboss.remoting.Client;
27
 
import org.jboss.remoting.ConnectionListener;
28
 
import org.jboss.remoting.InvocationRequest;
29
 
import org.jboss.remoting.ServerInvocationHandler;
30
 
import org.jboss.remoting.ServerInvoker;
31
 
import org.jboss.remoting.callback.InvokerCallbackHandler;
32
 
import org.jboss.remoting.transport.Connector;
33
 
import org.w3c.dom.Document;
34
 
 
35
 
import javax.management.MBeanServer;
36
 
import javax.xml.parsers.DocumentBuilderFactory;
37
 
import java.io.ByteArrayInputStream;
38
 
 
39
 
/**
40
 
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
41
 
 */
42
 
public abstract class LeaseTestServer extends ServerTestCase implements ConnectionListener
43
 
{
44
 
   // Default locator values
45
 
   private static String host = "localhost";
46
 
   private static int port = 5400;
47
 
 
48
 
   private boolean error = false;
49
 
   private boolean disconnect = false;
50
 
 
51
 
   private Connector connector = null;
52
 
 
53
 
   public boolean isRunning = true;
54
 
 
55
 
   // String to be returned from invocation handler upon client invocation calls.
56
 
   private static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation";
57
 
 
58
 
   protected abstract String getTransport();
59
 
 
60
 
   public void setupServer() throws Exception
61
 
   {
62
 
      connector = new Connector();
63
 
      StringBuffer buf = new StringBuffer();
64
 
      buf.append("<?xml version=\"1.0\"?>\n");
65
 
      buf.append("<config>");
66
 
      buf.append("<invoker transport=\"" + getTransport() + "\">");
67
 
      buf.append("<attribute name=\"clientLeasePeriod\">3000</attribute>");
68
 
      buf.append("<attribute name=\"serverBindAddress\">" + host + "</attribute>");
69
 
      buf.append("<attribute name=\"serverBindPort\">" + port + "</attribute>");
70
 
      buf.append("</invoker>");
71
 
      buf.append("<handlers>");
72
 
      buf.append("  <handler subsystem=\"mock\">" + SampleInvocationHandler.class.getName() + "</handler>\n");
73
 
      buf.append("</handlers>");
74
 
      buf.append("</config>");
75
 
      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(buf.toString().getBytes()));
76
 
      //connector.setInvokerLocator(locator.getLocatorURI());
77
 
      connector.setConfiguration(xml.getDocumentElement());
78
 
      connector.create();
79
 
      connector.addConnectionListener(this);
80
 
      connector.start();
81
 
 
82
 
   }
83
 
 
84
 
   public void testForError()
85
 
   {
86
 
      while(isRunning)
87
 
      {
88
 
         assertTrue("Received connection failure from client that was not due to disconnect.", !error);
89
 
         try
90
 
         {
91
 
            Thread.currentThread().sleep(1000);
92
 
         }
93
 
         catch(InterruptedException e)
94
 
         {
95
 
            e.printStackTrace();
96
 
         }
97
 
      }
98
 
   }
99
 
 
100
 
   public void setUp() throws Exception
101
 
   {
102
 
      setupServer();
103
 
   }
104
 
 
105
 
   public void tearDown() throws Exception
106
 
   {
107
 
      isRunning = false;
108
 
      if(connector != null)
109
 
      {
110
 
         connector.stop();
111
 
         connector.destroy();
112
 
      }
113
 
      if(!disconnect)
114
 
      {
115
 
         throw new RuntimeException("Never got disconnect notification from any of the clients.");
116
 
      }
117
 
   }
118
 
 
119
 
   public void handleConnectionException(Throwable throwable, Client client)
120
 
   {
121
 
      System.out.println("received connection exception from " + client + " (session id = " + client.getSessionId() + ") " +
122
 
                         "with exception of " + throwable + " and configuration of " + client.getConfiguration());
123
 
      if(throwable == null)
124
 
      {
125
 
         // since there was not an exception (will be one if was from a disconnect),
126
 
         // need to indicate error.
127
 
         error = true;
128
 
      }
129
 
      else
130
 
      {
131
 
         disconnect = true;
132
 
      }
133
 
   }
134
 
 
135
 
   /**
136
 
    * Simple invocation handler implementation.
137
 
    */
138
 
   public static class SampleInvocationHandler implements ServerInvocationHandler
139
 
   {
140
 
      /**
141
 
       * called to handle a specific invocation
142
 
       *
143
 
       * @param invocation
144
 
       * @return
145
 
       * @throws Throwable
146
 
       */
147
 
      public Object invoke(InvocationRequest invocation) throws Throwable
148
 
      {
149
 
         // Print out the invocation request
150
 
         System.out.println("Invocation request is: " + invocation.getParameter());
151
 
 
152
 
         // Just going to return static string as this is just simple example code.
153
 
         return RESPONSE_VALUE;
154
 
      }
155
 
 
156
 
      /**
157
 
       * Adds a callback handler that will listen for callbacks from
158
 
       * the server invoker handler.
159
 
       *
160
 
       * @param callbackHandler
161
 
       */
162
 
      public void addListener(InvokerCallbackHandler callbackHandler)
163
 
      {
164
 
         // NO OP as do not handling callback listeners in this example
165
 
      }
166
 
 
167
 
      /**
168
 
       * Removes the callback handler that was listening for callbacks
169
 
       * from the server invoker handler.
170
 
       *
171
 
       * @param callbackHandler
172
 
       */
173
 
      public void removeListener(InvokerCallbackHandler callbackHandler)
174
 
      {
175
 
         // NO OP as do not handling callback listeners in this example
176
 
      }
177
 
 
178
 
      /**
179
 
       * set the mbean server that the handler can reference
180
 
       *
181
 
       * @param server
182
 
       */
183
 
      public void setMBeanServer(MBeanServer server)
184
 
      {
185
 
         // NO OP as do not need reference to MBeanServer for this handler
186
 
      }
187
 
 
188
 
      /**
189
 
       * set the invoker that owns this handler
190
 
       *
191
 
       * @param invoker
192
 
       */
193
 
      public void setInvoker(ServerInvoker invoker)
194
 
      {
195
 
         // NO OP as do not need reference back to the server invoker
196
 
      }
197
 
 
198
 
   }
199
 
 
200
 
}
 
 
b'\\ No newline at end of file'