Author: sebawagner
Date: Sun Oct 28 08:35:32 2012
New Revision: 1402954

URL: http://svn.apache.org/viewvc?rev=1402954&view=rev
Log:
OPENMEETINGS-455 load test client working version as JUnit test

Added:
    
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoadTest.java
Modified:
    
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java
    
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoad.java

Modified: 
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java
URL: 
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java?rev=1402954&r1=1402953&r2=1402954&view=diff
==============================================================================
--- 
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java
 (original)
+++ 
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java
 Sun Oct 28 08:35:32 2012
@@ -26,14 +26,9 @@ import java.util.Map.Entry;
 import org.red5.client.net.rtmp.ClientExceptionHandler;
 import org.red5.client.net.rtmp.INetStreamEventHandler;
 import org.red5.client.net.rtmp.RTMPClient;
-import org.red5.server.api.event.IEvent;
 import org.red5.server.api.service.IPendingServiceCall;
 import org.red5.server.api.service.IPendingServiceCallback;
-import org.red5.server.net.rtmp.Channel;
-import org.red5.server.net.rtmp.RTMPConnection;
-import org.red5.server.net.rtmp.codec.RTMP;
 import org.red5.server.net.rtmp.event.Notify;
-import org.red5.server.net.rtmp.message.Header;
 
 public class LoadTestRtmpClient extends RTMPClient implements 
IPendingServiceCallback, INetStreamEventHandler, ClientExceptionHandler {
 
@@ -78,20 +73,21 @@ public class LoadTestRtmpClient extends 
                
                if (counterCalls % 2 == 0) {
 
-                       if (counterCalls > 500) {
+                       if (counterCalls > 10) {
 
                                return true;
 
                        }
 
                        System.err.println("Rest o do new call " + 
counterCalls);
+                       counterCalls++;
+
                        Map<String, Integer> map = new HashMap<String, 
Integer>();
                        map.put("instanceId", instanceId);
                        map.put("count", counterCalls);
                        calls.put(counterCalls, new CallObject(new Date()));
-                       invoke("syncMessageToCurrentScope", new Object[] {
+                       invoke("loadTestSyncMessage", new Object[] {
                                        "syncMessageToCurrentScopeResult", map, 
true }, this);
-                       counterCalls++;
 
                } else {
                        System.err.println("Call running " + counterCalls);
@@ -110,8 +106,8 @@ public class LoadTestRtmpClient extends 
                        long deltaTime = 
tCallObjectEntry.getValue().getEnded().getTime()
                                        - 
tCallObjectEntry.getValue().getStarted().getTime();
 
-                       System.err.println("Key " + tCallObjectEntry.getKey()
-                                       + "deltaTime " + deltaTime);
+                       // System.err.println("Key " + tCallObjectEntry.getKey()
+                       // + "deltaTime " + deltaTime);
 
                        overallTime += deltaTime;
 
@@ -120,9 +116,6 @@ public class LoadTestRtmpClient extends 
                double averageTime = Long.valueOf(overallTime).doubleValue()
                                / Integer.valueOf(calls.size()).doubleValue();
 
-               System.err.println("Number of calls: " + calls.size() + 
"overallTime: "
-                               + overallTime + " averageTime" + averageTime);
-
                return averageTime;
        }
        
@@ -136,68 +129,44 @@ public class LoadTestRtmpClient extends 
                        isConnected = true;
                }
 
-       }
-
-       protected void onInvoke(RTMPConnection conn, Channel channel,
-                       Header source, Notify invoke, RTMP rtmp) {
-
-               super.onInvoke(conn, channel, source, invoke, rtmp);
-
-               if (invoke.getType() == IEvent.Type.STREAM_DATA) {
-                       return;
-               }
-
-               String method = invoke.getCall().getServiceMethodName();
-               // System.err.println("method2 " + method);
+               if ("loadTestSyncMessage".equals(method)) {
 
-               if ("syncMessageToCurrentScopeResult".equals(method)) {
-
-                       @SuppressWarnings("unchecked")
-                       Map<String, Integer> arguments = (Map<String, Integer>) 
invoke
-                                       .getCall().getArguments()[0];
-                       Integer currentCountReturn = arguments.get("count");
-                       Integer msgInstanceId = arguments.get("instanceId");
-
-                       if (!msgInstanceId.equals(instanceId)) {
-                               throw new RuntimeException(
-                                               "Received msg from other 
instance msgInstanceId "
-                                                               + msgInstanceId 
+ " instanceId" + instanceId);
-                       }
-
-                       CallObject tCallObject = calls.get(currentCountReturn);
+                       CallObject tCallObject = calls.get(counterCalls);
                        if (tCallObject == null) {
 
                                for (Entry<Integer, CallObject> 
tCallObjectEntry : calls
                                                .entrySet()) {
 
-
                                        System.err.println("Key " + 
tCallObjectEntry.getKey()
                                                        + "tCallObjectEntry "
-                                                       + 
tCallObjectEntry.getValue().getStarted()
-                                                       + " current instanceId 
" + instanceId
-                                                       + " message instanceId "
-                                                       + 
arguments.get("instanceId"));
+                                                       + 
tCallObjectEntry.getValue().getStarted());
 
                                }
 
                                throw new RuntimeException(
                                                "tCallObject is null 
currentCountReturn "
-                                                               + 
currentCountReturn + " list size "
+                                                               + counterCalls 
+ " list size "
                                                                + calls.size());
                        }
                        tCallObject.setEnded(new Date());
-                       calls.put(currentCountReturn, tCallObject);
+                       calls.put(counterCalls, tCallObject);
 
-                       // System.err.println("Call received " + counterCalls
-                       // + " currentCountReturn: " + currentCountReturn);
+                       System.err.println("Call received " + counterCalls
+                                       + " instanceId: " + instanceId);
 
                        counterCalls++;
                }
+
        }
 
+
        public void onStreamEvent(Notify notify) {
                // TODO Auto-generated method stub
                
        }
+
+       public int getNumberOfCalls() {
+               return calls.size();
+       }
        
 }

Modified: 
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoad.java
URL: 
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoad.java?rev=1402954&r1=1402953&r2=1402954&view=diff
==============================================================================
--- 
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoad.java
 (original)
+++ 
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoad.java
 Sun Oct 28 08:35:32 2012
@@ -21,16 +21,12 @@ package org.apache.openmeetings.test.rtm
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class SimulateLoad {
+public class SimulateLoad extends Thread {
 
        private static final Logger log = LoggerFactory
                        .getLogger(SimulateLoad.class);
 
        private LoadTestRtmpClient loadTestRtmpClient;
-       private final String host;
-       private final int port;
-       private final String applicationContext;
-       private final int instanceId;
        private boolean testRunning = true;
 
        public double getAverageTime() {
@@ -53,8 +49,9 @@ public class SimulateLoad {
                        SimulateLoad simulateLoad = new SimulateLoad(args[0], 
Integer
                                        .valueOf(args[1]).intValue(), args[2], 
Integer.valueOf(
                                        args[3]).intValue());
-                       simulateLoad.run();
+                       simulateLoad.start();
                        System.err.println("started ");
+
                } catch (Exception er) {
                        er.printStackTrace();
                }
@@ -63,19 +60,15 @@ public class SimulateLoad {
        public SimulateLoad(String host, int port, String applicationContext,
                        int instanceId) {
                super();
-               this.host = host;
-               this.port = port;
-               this.applicationContext = applicationContext;
-               this.instanceId = instanceId;
+
+               loadTestRtmpClient = new LoadTestRtmpClient(instanceId);
+               loadTestRtmpClient.connect(host, port, applicationContext,
+                               loadTestRtmpClient);
        }
 
        public void run() {
                try {
 
-                       loadTestRtmpClient = new LoadTestRtmpClient(instanceId);
-                       loadTestRtmpClient.connect(host, port, 
applicationContext,
-                                       loadTestRtmpClient);
-
                        System.err.println("######### start client");
 
                        while (testRunning) {
@@ -92,4 +85,8 @@ public class SimulateLoad {
                }
        }
 
+       public int getNumberOfCalls() {
+               return loadTestRtmpClient.getNumberOfCalls();
+       }
+
 }

Added: 
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoadTest.java
URL: 
http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoadTest.java?rev=1402954&view=auto
==============================================================================
--- 
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoadTest.java
 (added)
+++ 
incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoadTest.java
 Sun Oct 28 08:35:32 2012
@@ -0,0 +1,74 @@
+package org.apache.openmeetings.test.rtmp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+public class SimulateLoadTest {
+
+       private int numberOfClients = 10;
+       private List<SimulateLoad> simulateLoadList = new 
ArrayList<SimulateLoad>();
+
+       private final String host = "192.168.1.7";
+       private final int port = 1935;
+       private final String applicationContext = "openmeetings/1";
+
+       @Test
+       public void test() {
+               try {
+                       for (int i = 0; i < numberOfClients; i++) {
+                               SimulateLoad simulateLoad = new 
SimulateLoad(host, port,
+                                               applicationContext, i);
+                               simulateLoadList.add(simulateLoad);
+                               Thread.sleep(100);
+                       }
+
+                       System.err.println("Clients initialized");
+
+                       for (SimulateLoad simulateLoad : simulateLoadList) {
+                               simulateLoad.start();
+                               Thread.sleep(50);
+                       }
+
+                       System.err.println("Clients started");
+
+                       boolean running = true;
+                       while (running) {
+                               boolean doRunStill = false;
+                               for (SimulateLoad simulateLoad : 
simulateLoadList) {
+                                       if (simulateLoad.isTestRunning()) {
+                                               doRunStill = true;
+                                               break;
+                                       }
+                               }
+                               running = doRunStill;
+                               try {
+                                       Thread.sleep(200);
+                               } catch (InterruptedException e) {
+                                       e.printStackTrace();
+                               }
+                       }
+
+                       double overallTime = 0;
+
+                       for (SimulateLoad simulateLoad : simulateLoadList) {
+                               overallTime += simulateLoad.getAverageTime();
+                               System.err.println("Number of calls: "
+                                               + 
simulateLoad.getNumberOfCalls() + "overallTime: "
+                                               + overallTime + " averageTime"
+                                               + 
simulateLoad.getAverageTime());
+                       }
+
+                       double deltaAllClients = overallTime
+                                       / 
Integer.valueOf(simulateLoadList.size()).doubleValue();
+
+                       System.err.println("Average time per call: " + 
deltaAllClients);
+
+               } catch (Exception err) {
+                       err.printStackTrace();
+               }
+
+       }
+
+}


Reply via email to