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

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/shutdown/OpenClient.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.shutdown;
23
 
 
24
 
import java.net.InetAddress;
25
 
import java.util.HashMap;
26
 
import java.util.Map;
27
 
 
28
 
import junit.framework.TestCase;
29
 
 
30
 
import org.apache.log4j.Logger;
31
 
import org.jboss.remoting.Client;
32
 
import org.jboss.remoting.InvokerLocator;
33
 
 
34
 
/** 
35
 
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
36
 
 * @version $Revision: 3011 $
37
 
 * <p>
38
 
 * Copyright Jan 19, 2007
39
 
 * </p>
40
 
 */
41
 
public class OpenClient extends TestCase
42
 
{    
43
 
   private static Logger log = Logger.getLogger(OpenClient.class);
44
 
   private String transport;
45
 
   private Map extraConfig;
46
 
   private Client client;
47
 
   
48
 
   
49
 
   public OpenClient(String transport, Map config)
50
 
   {
51
 
      this.transport = transport;
52
 
      this.extraConfig = new HashMap(config);
53
 
      log.info("client transport: " + transport);
54
 
      Runtime.getRuntime().traceMethodCalls(true);
55
 
   }
56
 
   
57
 
   
58
 
   /**
59
 
    * This test is used to verify that a server can shut down even if a client does not.
60
 
    */
61
 
   public void testShutdown() throws Throwable
62
 
   {
63
 
      try
64
 
      {
65
 
         String host = InetAddress.getLocalHost().getHostAddress();
66
 
         String portString = System.getProperty("port");
67
 
         int port = Integer.parseInt(portString);
68
 
         String locatorURI = transport + "://" + host + ":" + port;
69
 
         InvokerLocator locator = new InvokerLocator(locatorURI);
70
 
         HashMap clientConfig = new HashMap(extraConfig);
71
 
         client = new Client(locator, clientConfig);
72
 
         client.connect();
73
 
         log.info("client connected");
74
 
         log.info("READY");
75
 
         
76
 
         for (int i = 0; i < 5; i++)
77
 
         {
78
 
            new InvokerThread(i).start();
79
 
         }
80
 
         
81
 
         log.info("going to sleep");
82
 
         log.info("*******************************************************");
83
 
         log.info("****************   EXPECT EXCEPTIONS   ****************");
84
 
         log.info("*******************************************************");
85
 
         Thread.sleep(60000);
86
 
         log.info("calling disconnect()");
87
 
         client.disconnect();
88
 
         log.info("client disconnected");
89
 
      }
90
 
      catch (Exception e)
91
 
      {
92
 
         log.info("exception in client: " + e);
93
 
         System.exit(1);
94
 
      }
95
 
   }
96
 
   
97
 
   
98
 
   protected void addCallbackArgs(Map map)
99
 
   {
100
 
      return;
101
 
   }
102
 
   
103
 
   
104
 
   protected static void getConfig(Map config, String configs)
105
 
   {
106
 
      int start = 0;
107
 
      int ampersand = configs.indexOf('&');
108
 
      while (ampersand > 0)
109
 
      {
110
 
         String s = configs.substring(start, ampersand);
111
 
         int equals = s.indexOf('=');
112
 
         String param = s.substring(0, equals);
113
 
         String value = s.substring(equals + 1);
114
 
         config.put(param, value);
115
 
         start = ampersand + 1;
116
 
         ampersand = configs.indexOf('&', start);
117
 
      }
118
 
   }
119
 
   
120
 
 
121
 
   public static void main(String[] args)
122
 
   {
123
 
      try
124
 
      {
125
 
         if (args.length == 0)
126
 
            throw new RuntimeException();
127
 
         
128
 
         String transport = args[0];
129
 
         
130
 
         HashMap config = new HashMap();
131
 
         System.out.println("args.length: " + args.length);
132
 
         if (args.length > 1)
133
 
            getConfig(config, args[1]);
134
 
         
135
 
         OpenClient client = new OpenClient(transport, config);
136
 
         client.testShutdown();
137
 
      }
138
 
      catch (Throwable t)
139
 
      {
140
 
         t.printStackTrace();
141
 
      }
142
 
   }
143
 
   
144
 
   
145
 
   public class InvokerThread extends Thread
146
 
   {
147
 
      private int id;
148
 
      
149
 
      public InvokerThread(int id)
150
 
      {
151
 
         this.id = id;
152
 
         setName("InvokerThread:" + id);
153
 
      }
154
 
      
155
 
      public void run()
156
 
      {
157
 
         try
158
 
         {
159
 
            log.info("client " + id + " making invocation");
160
 
            client.invoke(new Integer(id));
161
 
            log.info("client " + id + " made invocation");
162
 
         }
163
 
         catch (Throwable e)
164
 
         {
165
 
            e.printStackTrace();
166
 
         }
167
 
      }
168
 
   }
169
 
}