You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by se...@apache.org on 2012/10/27 17:48:49 UTC

svn commit: r1402810 - in /incubator/openmeetings/trunk/singlewebapp: .classpath build.xml src/org/apache/openmeetings/test/rtmp/ src/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java src/org/apache/openmeetings/test/rtmp/SimulateLoad.java

Author: sebawagner
Date: Sat Oct 27 15:48:49 2012
New Revision: 1402810

URL: http://svn.apache.org/viewvc?rev=1402810&view=rev
Log:
OPENMEETINGS-455 some test client. Parallel running doesn' work cause Red5's RTMPClient seems to be not able to run on the same instance multiple times (packets get mixed between the instances)

Added:
    incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/
    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/.classpath
    incubator/openmeetings/trunk/singlewebapp/build.xml

Modified: incubator/openmeetings/trunk/singlewebapp/.classpath
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/.classpath?rev=1402810&r1=1402809&r2=1402810&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/.classpath (original)
+++ incubator/openmeetings/trunk/singlewebapp/.classpath Sat Oct 27 15:48:49 2012
@@ -1,17 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
- -->
 <classpath>
 	<classpathentry kind="src" path="WebContent/WEB-INF"/>
 	<classpathentry kind="src" path="src"/>
@@ -28,5 +15,6 @@
 	<classpathentry kind="lib" path="build/red5/server/dist/red5.jar" sourcepath="build/red5/server/src"/>
 	<classpathentry kind="lib" path="build/red5/client/dist/red5-client.jar" sourcepath="build/red5/client/src"/>
 	<classpathentry kind="lib" path="build/lib/java_16_tools.jar"/>
+	<classpathentry kind="lib" path="WebContent/screensharing"/>
 	<classpathentry kind="output" path="build/classes/eclipse"/>
 </classpath>

Modified: incubator/openmeetings/trunk/singlewebapp/build.xml
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/build.xml?rev=1402810&r1=1402809&r2=1402810&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/build.xml (original)
+++ incubator/openmeetings/trunk/singlewebapp/build.xml Sat Oct 27 15:48:49 2012
@@ -446,7 +446,7 @@
 			<fileset dir="${red5.client.lib}" includes="red5-client*.jar" />
 		</copy>
 		<signjar alias="filetest" keystore="${keystore.file}" storepass="secret" lazy="false"
-			sigalg="MD5withRSA" digestalg="SHA1">
+			> <!-- sigalg="MD5withRSA" digestalg="SHA1" -->
 			<path>
 				<fileset dir="${screenshare.out.dir}">
 					<include name="**/*.jar" />
@@ -1066,6 +1066,7 @@
 	<target name="clean.all" depends="clean.dist" description="Clean All">
 		<delete includeemptydirs="true" dir="${build.base.dir}" />
 	</target>
+	
 	<target name="clean.ivy" depends="clean.all,-install-ivy" description="Clears out Ivy cache and build folder">
 		<ivy:cleancache />
 	</target>
@@ -1099,5 +1100,43 @@
 				</not>
 			</condition>
 		</fail>
-	</target>	
+	</target>
+	
+	<path id="loadtest.classpath">
+		<fileset dir="${om.dist.webapp}/screensharing">
+			<include name="*.jar" />
+			<exclude name="openmeetings*.jar" />
+		</fileset>
+		<!--
+		<filelist>
+			<file name="${basedir}/WebContent/screensharing/logback.xml"/>
+		</filelist>
+		 -->
+		<pathelement path="${basedir}/WebContent/screensharing" />
+		<pathelement path="${main.out.dir}" />
+	</path>
+	
+	<property name="runTestHost" value="192.168.1.7" />
+	<property name="runTestPort" value="1935" />
+	<property name="runTestContext" value="openmeetings/1" />
+	
+	<target name="doRunClientTest">
+		<parallel>
+			<java classname="org.apache.openmeetings.test.rtmp.SimulateLoad">
+				<arg value="${runTestHost}"/>
+				<arg value="${runTestPort}"/>
+				<arg value="${runTestContext}"/>
+				<arg value="1" />
+				<classpath refid="loadtest.classpath" />
+			</java>
+			<java classname="org.apache.openmeetings.test.rtmp.SimulateLoad">
+				<arg value="${runTestHost}"/>
+				<arg value="${runTestPort}"/>
+				<arg value="${runTestContext}"/>
+				<arg value="2" />
+				<classpath refid="loadtest.classpath" />
+			</java>
+		</parallel>
+	</target>
+	
 </project>

Added: 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=1402810&view=auto
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java (added)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/LoadTestRtmpClient.java Sat Oct 27 15:48:49 2012
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.test.rtmp;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+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 {
+
+	private class CallObject {
+		Date started;
+		Date ended;
+
+		public CallObject(Date started) {
+			super();
+			this.started = started;
+		}
+
+		public Date getStarted() {
+			return started;
+		}
+
+		public Date getEnded() {
+			return ended;
+		}
+
+		public void setEnded(Date ended) {
+			this.ended = ended;
+		}
+	}
+	
+	private int counterCalls = 0; // a call is always 2 steps
+	private Map<Integer, CallObject> calls = new HashMap<Integer, CallObject>();
+	private boolean isConnected = false;
+	private final int instanceId;
+
+	public LoadTestRtmpClient(int instanceId) {
+		this.instanceId = instanceId;
+	}
+	
+	public boolean performCall() {
+
+		// System.err.println("performCall " + isConnected);
+
+		if (!isConnected) {
+			return false;
+		}
+		
+		if (counterCalls % 2 == 0) {
+
+			if (counterCalls > 500) {
+
+				return true;
+
+			}
+
+			System.err.println("Rest o do new call " + 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[] {
+					"syncMessageToCurrentScopeResult", map, true }, this);
+			counterCalls++;
+
+		} else {
+			System.err.println("Call running " + counterCalls);
+		}
+		
+		
+		
+		return false;
+	}
+	
+	public double getAverageTime() {
+		long overallTime = 0L;
+
+		for (Entry<Integer, CallObject> tCallObjectEntry : calls.entrySet()) {
+
+			long deltaTime = tCallObjectEntry.getValue().getEnded().getTime()
+					- tCallObjectEntry.getValue().getStarted().getTime();
+
+			System.err.println("Key " + tCallObjectEntry.getKey()
+					+ "deltaTime " + deltaTime);
+
+			overallTime += deltaTime;
+
+		}
+
+		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;
+	}
+	
+	public void resultReceived(IPendingServiceCall call) {
+		String method = call == null ? null : call.getServiceMethodName();
+		System.err.println("method "+method);
+		if (method == null) {
+			return;
+		}
+		if ("connect".equals(method)) {
+			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 ("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);
+			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"));
+
+				}
+
+				throw new RuntimeException(
+						"tCallObject is null currentCountReturn "
+								+ currentCountReturn + " list size "
+								+ calls.size());
+			}
+			tCallObject.setEnded(new Date());
+			calls.put(currentCountReturn, tCallObject);
+
+			// System.err.println("Call received " + counterCalls
+			// + " currentCountReturn: " + currentCountReturn);
+
+			counterCalls++;
+		}
+	}
+
+	public void onStreamEvent(Notify notify) {
+		// TODO Auto-generated method stub
+		
+	}
+	
+}

Added: 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=1402810&view=auto
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoad.java (added)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/apache/openmeetings/test/rtmp/SimulateLoad.java Sat Oct 27 15:48:49 2012
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.test.rtmp;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SimulateLoad {
+
+	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() {
+		return loadTestRtmpClient.getAverageTime();
+	}
+
+	public boolean isTestRunning() {
+		return testRunning;
+	}
+
+	public static void main(String... args) {
+		try {
+			if (args.length != 4) {
+				new RuntimeException(
+						"4 args needed, host, port, context, instanceId");
+			}
+			for (String arg : args) {
+				System.err.println("arg: " + arg);
+			}
+			SimulateLoad simulateLoad = new SimulateLoad(args[0], Integer
+					.valueOf(args[1]).intValue(), args[2], Integer.valueOf(
+					args[3]).intValue());
+			simulateLoad.run();
+			System.err.println("started ");
+		} catch (Exception er) {
+			er.printStackTrace();
+		}
+	}
+
+	public SimulateLoad(String host, int port, String applicationContext,
+			int instanceId) {
+		super();
+		this.host = host;
+		this.port = port;
+		this.applicationContext = applicationContext;
+		this.instanceId = instanceId;
+	}
+
+	public void run() {
+		try {
+
+			loadTestRtmpClient = new LoadTestRtmpClient(instanceId);
+			loadTestRtmpClient.connect(host, port, applicationContext,
+					loadTestRtmpClient);
+
+			System.err.println("######### start client");
+
+			while (testRunning) {
+				testRunning = !loadTestRtmpClient.performCall();
+				try {
+					Thread.sleep(200);
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				}
+			}
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+}