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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/soak/ClientLauncher.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.soak;
 
23
 
 
24
import java.net.InetAddress;
 
25
import java.util.Collections;
 
26
import java.util.HashMap;
 
27
import java.util.HashSet;
 
28
import java.util.Iterator;
 
29
import java.util.Map;
 
30
import java.util.Random;
 
31
import java.util.Set;
 
32
import java.util.Timer;
 
33
import java.util.TimerTask;
 
34
 
 
35
import org.apache.log4j.ConsoleAppender;
 
36
import org.apache.log4j.Level;
 
37
import org.apache.log4j.Logger;
 
38
import org.apache.log4j.PatternLayout;
 
39
import org.jboss.logging.XLevel;
 
40
 
 
41
 
 
42
/**
 
43
 * 
 
44
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
45
 * @version $Revision: 1.1 $
 
46
 * <p>
 
47
 * Copyright Mar 13, 2008
 
48
 * </p>
 
49
 */
 
50
public class ClientLauncher extends SoakConstants
 
51
{
 
52
   private static Logger log = Logger.getLogger(ClientLauncher.class);
 
53
   
 
54
   private static Set mockEJBClientsInUse = Collections.synchronizedSet(new HashSet());
 
55
   private static Set mockJBMClientsInUse = Collections.synchronizedSet(new HashSet());
 
56
   private static Set heavyComputeClientsInUse = Collections.synchronizedSet(new HashSet());
 
57
   
 
58
   private static Counter mockEJBClientCounter = new Counter();
 
59
   private static Counter mockJBMClientCounter = new Counter();
 
60
   private static Counter heavyComputeClientCounter = new Counter();
 
61
   
 
62
   private static Counter mockEJBClientFailureCounter = new Counter();
 
63
   private static Counter mockJBMClientFailureCounter = new Counter();
 
64
   private static Counter heavyComputeClientFailureCounter = new Counter();
 
65
   
 
66
   private static Random random;
 
67
   private static String[] transports = {"bisocket", "http", "rmi", "socket"};
 
68
   private static int[] ports = {6666, 6667, 6668, 6669};
 
69
   private static int[] transportCounters = new int[4];
 
70
   private static String host;
 
71
   private static boolean creationDone;
 
72
   
 
73
   // Configuration parameters.
 
74
   private static int MAX_CLIENTS = 30;
 
75
   private static int NUMBER_OF_EJB_CALLS = 4000;
 
76
   private static int NUMBER_OF_JBM_CALLS = 2000;
 
77
   private static int NUMBER_OF_JBM_CALLBACKS = 4;
 
78
   private static int NUMBER_OF_HEAVY_COMPUTE_CALLS = 5;
 
79
   private static String HEAVY_COMPUTE_SPIN_TIME = "4000";
 
80
   
 
81
   
 
82
   public static void main(String[] args)
 
83
   {
 
84
      try
 
85
      {
 
86
         Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
 
87
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
 
88
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
 
89
         PatternLayout layout = new PatternLayout(pattern);
 
90
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
 
91
         Logger.getRootLogger().addAppender(consoleAppender); 
 
92
         
 
93
         host = InetAddress.getLocalHost().getHostAddress();
 
94
         random = new Random(System.currentTimeMillis());
 
95
         Timer timer = new Timer(false);
 
96
         timer.schedule(new DisplayTimerTask(), 30000, 30000);
 
97
         long start = System.currentTimeMillis();
 
98
 
 
99
         while (System.currentTimeMillis() - start < DURATION)
 
100
         {
 
101
            if (mockEJBClientsInUse.size() + 
 
102
                  mockJBMClientsInUse.size() +
 
103
                  heavyComputeClientsInUse.size() < MAX_CLIENTS)
 
104
            {
 
105
               createClient();
 
106
            }
 
107
            
 
108
            int n = random.nextInt(40) * 100;
 
109
            log.debug("waiting " + n + " ms");
 
110
            Thread.sleep(n);
 
111
         }
 
112
         
 
113
         creationDone = true;
 
114
         log.info("Client creation phase complete.");
 
115
      }
 
116
      catch (Throwable t)
 
117
      {
 
118
         log.error("Error", t);
 
119
      }
 
120
   }
 
121
   
 
122
   
 
123
   protected static void createClient() throws Throwable
 
124
   {
 
125
      int k = random.nextInt(4);
 
126
      String transport = transports[k];
 
127
      int port = ports[k];
 
128
      transportCounters[k]++;
 
129
      int clientType = random.nextInt(25);
 
130
      
 
131
      if (clientType < 10)
 
132
      {
 
133
         createMockEJBClient(transport, port);
 
134
      }
 
135
      else if (clientType < 20)
 
136
      {
 
137
         createMockJBMClient(transport, port);
 
138
      }
 
139
      else
 
140
      {
 
141
         createHeavyComputeClient(transport, port);
 
142
      }
 
143
   }
 
144
   
 
145
   
 
146
   protected static void createMockEJBClient(String transport, int port) throws Throwable
 
147
   {
 
148
      String locatorURI = transport + "://" + host + ":" + port + "/?timeout=0";
 
149
      Map metadata = new HashMap();
 
150
      metadata.put(NAME, "MockEJBClient" + mockEJBClientCounter.increment() + "[" + transport + "]");
 
151
      metadata.put(IN_USE_SET, mockEJBClientsInUse);
 
152
      metadata.put(FAILURE_COUNTER, mockEJBClientFailureCounter);
 
153
      metadata.put(NUMBER_OF_CALLS, Integer.toString(random.nextInt(NUMBER_OF_EJB_CALLS)));
 
154
      MockEJBClient c = new MockEJBClient(locatorURI, metadata);
 
155
      Thread t = new Thread(c);
 
156
      t.start(); 
 
157
   }
 
158
   
 
159
   
 
160
   protected static void createMockJBMClient(String transport, int port) throws Throwable
 
161
   {
 
162
      String locatorURI = transport + "://" + host + ":" + port + "/?timeout=0";
 
163
      Map metadata = new HashMap();
 
164
      metadata.put(NAME, "MockJBMClient" + mockJBMClientCounter.increment() + "[" + transport + "]");
 
165
      metadata.put(IN_USE_SET, mockJBMClientsInUse);
 
166
      metadata.put(FAILURE_COUNTER, mockJBMClientFailureCounter);
 
167
      metadata.put(NUMBER_OF_CALLS, Integer.toString(random.nextInt(NUMBER_OF_JBM_CALLS)));
 
168
      metadata.put(NUMBER_OF_CALLBACKS, Integer.toString(random.nextInt(NUMBER_OF_JBM_CALLBACKS)));
 
169
      MockJBMClient c = new MockJBMClient(locatorURI, metadata);
 
170
      Thread t = new Thread(c);
 
171
      t.start();
 
172
   }
 
173
   
 
174
   
 
175
   protected static void createHeavyComputeClient(String transport, int port) throws Throwable
 
176
   {
 
177
      String locatorURI = transport + "://" + host + ":" + port + "/?timeout=0";
 
178
      Map metadata = new HashMap();
 
179
      metadata.put(NAME, "HeavyComputeClient" + heavyComputeClientCounter.increment() + "[" + transport + "]");
 
180
      metadata.put(IN_USE_SET, heavyComputeClientsInUse);
 
181
      metadata.put(FAILURE_COUNTER, heavyComputeClientFailureCounter);
 
182
      metadata.put(NUMBER_OF_CALLS, Integer.toString(random.nextInt(NUMBER_OF_HEAVY_COMPUTE_CALLS)));
 
183
      metadata.put(SPIN_TIME, HEAVY_COMPUTE_SPIN_TIME);
 
184
      HeavyComputeClient c = new HeavyComputeClient(locatorURI, metadata);
 
185
      heavyComputeClientCounter.increment();
 
186
      Thread t = new Thread(c);
 
187
      t.start();
 
188
   }
 
189
   
 
190
   
 
191
   static class Counter
 
192
   {
 
193
      int count;
 
194
      
 
195
      public synchronized int getCount() { return count; }
 
196
      public synchronized int increment() { return count++; }
 
197
      public synchronized int decrement() { return --count; }
 
198
   }
 
199
   
 
200
   static class DisplayTimerTask extends TimerTask
 
201
   {
 
202
      public void run()
 
203
      {
 
204
         System.out.println("");
 
205
         System.out.println("=========================================");
 
206
         System.out.println("current MockEJBCLients:      " + mockEJBClientsInUse.size());
 
207
         System.out.println("current MockJBMClients:      " + mockJBMClientsInUse.size());
 
208
         System.out.println("current HeavyComputeClients: " + heavyComputeClientsInUse.size());
 
209
         System.out.println("-----------------------------------------");
 
210
         System.out.println("bisocket clients:            " + transportCounters[0]);
 
211
         System.out.println("http clients:                " + transportCounters[1]);
 
212
         System.out.println("rmi clients:                 " + transportCounters[2]);
 
213
         System.out.println("socket clients:              " + transportCounters[3]);
 
214
         System.out.println("-----------------------------------------");
 
215
         System.out.println("failed MockEJBCLients:       " + mockEJBClientFailureCounter.getCount());
 
216
         System.out.println("failed MockJBMClients:       " + mockJBMClientFailureCounter.getCount());
 
217
         System.out.println("failed HeavyComputeClients:  " + heavyComputeClientFailureCounter.getCount());
 
218
         System.out.println("-----------------------------------------");
 
219
         printSet(mockEJBClientsInUse);
 
220
         printSet(mockJBMClientsInUse);
 
221
         printSet(heavyComputeClientsInUse);
 
222
         System.out.println("=========================================");
 
223
         System.out.println("");
 
224
         
 
225
         if (creationDone &&
 
226
               mockEJBClientsInUse.size() == 0 && 
 
227
               mockJBMClientsInUse.size() == 0 &&
 
228
               heavyComputeClientsInUse.size() == 0)
 
229
 
 
230
            cancel();
 
231
      }
 
232
      
 
233
      private void printSet(Set set)
 
234
      {
 
235
         synchronized (set)
 
236
         {
 
237
            Iterator it = set.iterator();
 
238
            while(it.hasNext())
 
239
            {
 
240
               System.out.println(it.next().toString());
 
241
            }
 
242
         }
 
243
      }
 
244
   }
 
245
}
 
246