|
From: <ian...@us...> - 2008-01-31 01:09:13
|
Revision: 701
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=701&view=rev
Author: iansmith
Date: 2008-01-30 17:09:13 -0800 (Wed, 30 Jan 2008)
Log Message:
-----------
I moved the multiuser tests into ogoglio-common. This is not a huge amount of extra bloat and means that it easy for folks (incl me) to write scripts that do load testing. Before this required chicanery with the test jars.
Added Paths:
-----------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/Bot.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultispaceTests.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultiuserTests.java
Removed Paths:
-------------
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/Bot.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultispaceTests.java
maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultiuserTests.java
maven/trunk/ogoglio-common/src/test/java/com/ogoglio/loadtest/
Copied: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest (from rev 689, maven/trunk/ogoglio-common/src/test/java/com/ogoglio/loadtest)
Deleted: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/Bot.java
===================================================================
--- maven/trunk/ogoglio-common/src/test/java/com/ogoglio/loadtest/Bot.java 2008-01-23 03:18:47 UTC (rev 689)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/Bot.java 2008-01-31 01:09:13 UTC (rev 701)
@@ -1,139 +0,0 @@
-package com.ogoglio.loadtest;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Random;
-import java.util.Vector;
-
-import javax.media.j3d.Transform3D;
-import javax.vecmath.Vector3d;
-
-import com.ogoglio.client.SpaceClient;
-import com.ogoglio.client.model.SplinePath;
-import com.ogoglio.client.model.Thing;
-import com.ogoglio.client.model.User;
-import com.ogoglio.util.Log;
-import com.ogoglio.viewer.j3d.J3DSplinePath;
-
-public class Bot implements SpaceClient.Listener {
- SpaceClient spaceClient = null;
-
- Random random = new Random();
-
- WanderThread wanderThread = null;
-
- public Bot(long spaceID, URI serviceURI) throws IOException {
- String guestCookie = "guestRobot_Banger_Test_" + System.currentTimeMillis() + "_" + random.nextInt();
- if (guestCookie == null) {
- throw new IOException("Could not get a guest cookie");
- }
- spaceClient = new SpaceClient(spaceID, serviceURI, guestCookie, this);
- }
-
- public void wander() {
- wanderThread = new WanderThread();
- wanderThread.start();
- }
-
- public void cleanup() {
- if (spaceClient != null) {
- spaceClient.cleanup();
- }
- }
-
- public void teleport(Transform3D position) {
- spaceClient.viewpointMotionStopped(position);
- }
-
- public void disconnected() {
- Log.error("UserRobot was disconnected");
- }
-
- public void receivedChatMessage(String username, String message) {
- }
-
- public void receivedSpaceTransfer(URI link) {
- }
-
- public void receivedLink(String displayName, String link) {
- }
-
- public void receivedCommandFocusRequest(String preloadedText) {
- }
-
- public void receivedBrowserMessage(long sourceThingID, String message) {
- }
-
- public void receivedContextMenuRequest(Thing thing, String shapeName, int x, int y, long nonce) {
- }
-
- public void receivedContextMenuData(long nonce, String errorIfAny, Vector contextMenu) {
- }
-
- public void contextItemChosen(Thing thing, long nonce, String id) {
- }
-
- public void receivedInfoPanel(long sourceThingID, String nonce) {
- }
-
- private class WanderThread extends Thread {
- public void run() {
- User user = spaceClient.getSpace().getUser(spaceClient.getUsername());
- while (user == null) {
- try {
- sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- user = spaceClient.getSpace().getUser(spaceClient.getUsername());
- }
- Vector3d homePosition = new Vector3d(Math.abs(random.nextInt()) % 10, 0, -30 + Math.abs(random.nextInt()) % 10);
- Transform3D userPosition = new Transform3D();
- userPosition.setTranslation(homePosition);
- boolean lastSpun = true;
- while (true) {
- if (random.nextBoolean() || random.nextBoolean()) {
- userPosition.setTranslation(homePosition);
- spaceClient.viewpointMotionStopped(userPosition);
- try {
- sleep(1000 + Math.abs((random.nextInt() % 5000)));
- } catch (InterruptedException e) {
- break;
- }
- } else if (lastSpun) {
- userPosition.rotY(random.nextFloat() % (2 * Math.PI));
- userPosition.setTranslation(homePosition);
- SplinePath path = J3DSplinePath.getSplinePath(userPosition, 1, 0, 0, 2);
- spaceClient.viewpointMotionChanged(path);
- try {
- sleep(3000 + Math.abs((random.nextInt() % 6000)));
- } catch (InterruptedException e) {
- break;
- }
- lastSpun = false;
- } else {
- userPosition.setTranslation(homePosition);
- SplinePath path = J3DSplinePath.getSplinePath(userPosition, 0, 1, 0, 2);
- spaceClient.viewpointMotionChanged(path);
- try {
- sleep(1000 + Math.abs((random.nextInt() % 6000)));
- } catch (InterruptedException e) {
- break;
- }
- lastSpun = true;
- }
- }
- }
- }
-
- public void receivedUserContextMenuRequest(User user, int x, int y) {
- // TODO Auto-generated method stub
-
- }
-
- public void receivedTellMessage(String username, String message) {
- // TODO Auto-generated method stub
-
- }
-
-}
Copied: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/Bot.java (from rev 700, maven/trunk/ogoglio-common/src/test/java/com/ogoglio/loadtest/Bot.java)
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/Bot.java (rev 0)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/Bot.java 2008-01-31 01:09:13 UTC (rev 701)
@@ -0,0 +1,135 @@
+package com.ogoglio.loadtest;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Random;
+import java.util.Vector;
+
+import javax.media.j3d.Transform3D;
+import javax.vecmath.Vector3d;
+
+import com.ogoglio.client.SpaceClient;
+import com.ogoglio.client.model.SplinePath;
+import com.ogoglio.client.model.Thing;
+import com.ogoglio.client.model.User;
+import com.ogoglio.util.Log;
+import com.ogoglio.viewer.j3d.J3DSplinePath;
+
+public class Bot implements SpaceClient.Listener {
+ SpaceClient spaceClient = null;
+
+ private Random random = new Random();
+ private WanderThread wanderThread = null;
+ private long timeLimitInMillis;
+ private long startTime;
+
+ public Bot(long spaceID, URI serviceURI, long timeLimitInMillis) throws IOException {
+ String guestCookie = "guestRobot_Banger_Test_" + System.currentTimeMillis() + "_" + random.nextInt();
+ if (guestCookie == null) {
+ throw new IOException("Could not get a guest cookie");
+ }
+ spaceClient = new SpaceClient(spaceID, serviceURI, guestCookie, this);
+ this.timeLimitInMillis=timeLimitInMillis;
+ this.startTime=System.currentTimeMillis();
+ }
+
+ public void wander() {
+ wanderThread = new WanderThread();
+ wanderThread.start();
+ }
+
+ public void cleanup() {
+ if (spaceClient != null) {
+ spaceClient.cleanup();
+ }
+ }
+
+ public void teleport(Transform3D position) {
+ spaceClient.viewpointMotionStopped(position);
+ }
+
+ public void disconnected() {
+ Log.error("UserRobot was disconnected");
+ }
+
+ public void receivedChatMessage(String username, String message) {
+ }
+
+ public void receivedSpaceTransfer(URI link) {
+ }
+
+ public void receivedLink(String displayName, String link) {
+ }
+
+ public void receivedCommandFocusRequest(String preloadedText) {
+ }
+
+ public void receivedBrowserMessage(long sourceThingID, String message) {
+ }
+
+ public void receivedContextMenuRequest(Thing thing, String shapeName, int x, int y, long nonce) {
+ }
+
+ public void receivedContextMenuData(long nonce, String errorIfAny, Vector contextMenu) {
+ }
+
+ public void contextItemChosen(Thing thing, long nonce, String id) {
+ }
+
+ public void receivedInfoPanel(long sourceThingID, String nonce) {
+ }
+
+ private class WanderThread extends Thread {
+ public void run() {
+ User user = spaceClient.getSpace().getUser(spaceClient.getUsername());
+ while (user == null) {
+ try {
+ sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ user = spaceClient.getSpace().getUser(spaceClient.getUsername());
+ }
+ try {
+ Vector3d homePosition = new Vector3d(Math.abs(random.nextInt()) % 10, 0, -30 + Math.abs(random.nextInt()) % 10);
+ Transform3D userPosition = new Transform3D();
+ userPosition.setTranslation(homePosition);
+ boolean lastSpun = true;
+ while (System.currentTimeMillis()-startTime < timeLimitInMillis) {
+ if (random.nextBoolean() || random.nextBoolean()) {
+ userPosition.setTranslation(homePosition);
+ spaceClient.viewpointMotionStopped(userPosition);
+ sleep(1000 + Math.abs((random.nextInt() % 5000)));
+ } else if (lastSpun) {
+ userPosition.rotY(random.nextFloat() % (2 * Math.PI));
+ userPosition.setTranslation(homePosition);
+ SplinePath path = J3DSplinePath.getSplinePath(userPosition, 1, 0, 0, 2);
+ spaceClient.viewpointMotionChanged(path);
+ sleep(3000 + Math.abs((random.nextInt() % 6000)));
+ lastSpun = false;
+ } else {
+ userPosition.setTranslation(homePosition);
+ SplinePath path = J3DSplinePath.getSplinePath(userPosition, 0, 1, 0, 2);
+ spaceClient.viewpointMotionChanged(path);
+ sleep(1000 + Math.abs((random.nextInt() % 6000)));
+ lastSpun = true;
+ }
+ }
+ } catch (Throwable t) {
+ Log.warn("Thread "+Thread.currentThread().getId()+" had to abort due to caught error:");
+ Log.warn(t.getClass().getName()+":"+t.getMessage());
+ }
+ }
+ }
+
+ public void receivedUserContextMenuRequest(User user, int x, int y) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void receivedTellMessage(String username, String message) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Deleted: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultispaceTests.java
===================================================================
--- maven/trunk/ogoglio-common/src/test/java/com/ogoglio/loadtest/MultispaceTests.java 2008-01-23 03:18:47 UTC (rev 689)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultispaceTests.java 2008-01-31 01:09:13 UTC (rev 701)
@@ -1,67 +0,0 @@
-package com.ogoglio.loadtest;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Vector;
-
-import com.ogoglio.util.Log;
-
-public class MultispaceTests {
-
- private URI serviceURI = null;
-
- private long lowerSpaceID = -1;
-
- private long upperSpaceID = -1;
-
- Vector bots = new Vector();
-
- public MultispaceTests(URI serviceURI, long lowerSpaceID, long upperSpaceID) {
- this.lowerSpaceID = lowerSpaceID;
- this.upperSpaceID = upperSpaceID;
- this.serviceURI = serviceURI;
- if (lowerSpaceID >= upperSpaceID) {
- throw new IllegalArgumentException("lower space ID must be less than upper space ID");
- }
- }
-
- public void startTests() throws IOException {
- for (long i = lowerSpaceID; i <= upperSpaceID; i++) {
- try {
- Bot bot = new Bot(i, serviceURI);
- System.out.println("Adding bot to space " + i);
- bots.add(bot);
- } catch (IOException e) {
- System.out.println("Skipping space " + i);
- }
- }
- }
-
- public void stopTests() {
- Bot[] theBots = (Bot[]) bots.toArray(new Bot[0]);
- for (int i = 0; i < theBots.length; i++) {
- theBots[i].cleanup();
- }
- }
-
- public static void main(String[] args) {
- if (args.length != 3) {
- Log.error("usage: ... serviceURI lowerSpaceID upperSpaceID");
- return;
- }
-
- URI serviceURI = URI.create(args[0]);
- long lowerSpaceID = Long.parseLong(args[1]);
- long upperSpaceID = Long.parseLong(args[2]);
-
- MultispaceTests tests = new MultispaceTests(serviceURI, lowerSpaceID, upperSpaceID);
- try {
- tests.startTests();
- Thread.sleep(500000000);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
-}
Copied: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultispaceTests.java (from rev 700, maven/trunk/ogoglio-common/src/test/java/com/ogoglio/loadtest/MultispaceTests.java)
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultispaceTests.java (rev 0)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultispaceTests.java 2008-01-31 01:09:13 UTC (rev 701)
@@ -0,0 +1,67 @@
+package com.ogoglio.loadtest;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Vector;
+
+import com.ogoglio.util.Log;
+
+public class MultispaceTests {
+
+ private URI serviceURI = null;
+
+ private long lowerSpaceID = -1;
+
+ private long upperSpaceID = -1;
+
+ Vector bots = new Vector();
+
+ public MultispaceTests(URI serviceURI, long lowerSpaceID, long upperSpaceID) {
+ this.lowerSpaceID = lowerSpaceID;
+ this.upperSpaceID = upperSpaceID;
+ this.serviceURI = serviceURI;
+ if (lowerSpaceID >= upperSpaceID) {
+ throw new IllegalArgumentException("lower space ID must be less than upper space ID");
+ }
+ }
+
+ public void startTests() throws IOException {
+ for (long i = lowerSpaceID; i <= upperSpaceID; i++) {
+ try {
+ Bot bot = new Bot(i, serviceURI, 1000 * 10 * 60);
+ System.out.println("Adding bot to space " + i);
+ bots.add(bot);
+ } catch (IOException e) {
+ System.out.println("Skipping space " + i);
+ }
+ }
+ }
+
+ public void stopTests() {
+ Bot[] theBots = (Bot[]) bots.toArray(new Bot[0]);
+ for (int i = 0; i < theBots.length; i++) {
+ theBots[i].cleanup();
+ }
+ }
+
+ public static void main(String[] args) {
+ if (args.length != 3) {
+ Log.error("usage: ... serviceURI lowerSpaceID upperSpaceID");
+ return;
+ }
+
+ URI serviceURI = URI.create(args[0]);
+ long lowerSpaceID = Long.parseLong(args[1]);
+ long upperSpaceID = Long.parseLong(args[2]);
+
+ MultispaceTests tests = new MultispaceTests(serviceURI, lowerSpaceID, upperSpaceID);
+ try {
+ tests.startTests();
+ Thread.sleep(500000000);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
Deleted: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultiuserTests.java
===================================================================
--- maven/trunk/ogoglio-common/src/test/java/com/ogoglio/loadtest/MultiuserTests.java 2008-01-23 03:18:47 UTC (rev 689)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultiuserTests.java 2008-01-31 01:09:13 UTC (rev 701)
@@ -1,83 +0,0 @@
-package com.ogoglio.loadtest;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Random;
-import java.util.Vector;
-
-import javax.media.j3d.Transform3D;
-import javax.vecmath.Vector3d;
-
-import com.ogoglio.client.SpaceClient;
-import com.ogoglio.client.SpaceClient.Listener;
-import com.ogoglio.client.model.SplinePath;
-import com.ogoglio.client.model.Thing;
-import com.ogoglio.client.model.User;
-import com.ogoglio.util.Log;
-import com.ogoglio.viewer.j3d.J3DSplinePath;
-
-public class MultiuserTests {
-
- private long spaceID = -1;
-
- private URI serviceURI = null;
-
- Vector robots = new Vector();
-
- public MultiuserTests(long spaceID, URI serviceURI) {
- this.spaceID = spaceID;
- this.serviceURI = serviceURI;
- }
-
- public synchronized void addRobot(Transform3D startPosition, boolean wander) throws IOException {
- Bot robot = new Bot(spaceID, serviceURI);
- robot.teleport(startPosition);
- robots.add(robot);
- if (wander) {
- robot.wander();
- }
- }
-
- private synchronized Bot[] getRobots() {
- return (Bot[]) robots.toArray(new Bot[0]);
- }
-
- public void cleanup() {
- Bot[] bots = getRobots();
- for (int i = 0; i < bots.length; i++) {
- bots[i].cleanup();
- }
- }
-
- public static void main(String[] args) {
- if (args.length != 3) {
- Log.error("usage: ... spaceID serviceURI numRobots");
- return;
- }
- MultiuserTests tests = null;
- try {
- long spaceID = Long.parseLong(args[0]);
- URI serviceURI = new URI(args[1]);
- tests = new MultiuserTests(spaceID, serviceURI);
-
- int numRobots = Integer.parseInt(args[2]);
- Transform3D startPosition = new Transform3D();
- for (int i = 0; i < numRobots; i++) {
- startPosition.setTranslation(new Vector3d(0, 0, -50));
- tests.addRobot(startPosition, true);
- Log.info("Added robot " + (i + 1) + " of " + numRobots);
- Thread.sleep(1000);
- }
-
- Thread.sleep(500000000);
- } catch (Throwable e) {
- e.printStackTrace();
- System.exit(1);
- } finally {
- if (tests != null) {
- tests.cleanup();
- }
- }
- }
-
-}
Copied: maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultiuserTests.java (from rev 700, maven/trunk/ogoglio-common/src/test/java/com/ogoglio/loadtest/MultiuserTests.java)
===================================================================
--- maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultiuserTests.java (rev 0)
+++ maven/trunk/ogoglio-common/src/main/java/com/ogoglio/loadtest/MultiuserTests.java 2008-01-31 01:09:13 UTC (rev 701)
@@ -0,0 +1,85 @@
+package com.ogoglio.loadtest;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Date;
+import java.util.Vector;
+
+import javax.media.j3d.Transform3D;
+import javax.vecmath.Vector3d;
+
+import com.ogoglio.util.Log;
+
+public class MultiuserTests {
+
+ private long spaceID = -1;
+
+ private URI serviceURI = null;
+ private long timeLimit;
+
+ Vector robots = new Vector();
+
+ public MultiuserTests(long spaceID, URI serviceURI, long timeLimit) {
+ this.spaceID = spaceID;
+ this.serviceURI = serviceURI;
+ this.timeLimit=timeLimit;
+ }
+
+ public synchronized void addRobot(Transform3D startPosition, boolean wander) throws IOException {
+ Bot robot = new Bot(spaceID, serviceURI, timeLimit);
+ robot.teleport(startPosition);
+ robots.add(robot);
+ if (wander) {
+ robot.wander();
+ }
+ }
+
+ private synchronized Bot[] getRobots() {
+ return (Bot[]) robots.toArray(new Bot[0]);
+ }
+
+ public void cleanup() {
+ Bot[] bots = getRobots();
+ for (int i = 0; i < bots.length; i++) {
+ bots[i].cleanup();
+ }
+ }
+
+ public static void main(String[] args) {
+ if (args.length != 4) {
+ Log.error("usage: ... spaceID serviceURI numRobots duration");
+ return;
+ }
+ MultiuserTests tests = null;
+ try {
+ long spaceID = Long.parseLong(args[0]);
+ long limit= Long.parseLong(args[3]);
+ URI serviceURI = new URI(args[1]);
+ tests = new MultiuserTests(spaceID, serviceURI, limit);
+
+ int numRobots = Integer.parseInt(args[2]);
+ Transform3D startPosition = new Transform3D();
+ for (int i = 0; i < numRobots; i++) {
+ startPosition.setTranslation(new Vector3d(0, 0, -50));
+ tests.addRobot(startPosition, true);
+ Log.info("Added robot " + (i + 1) + " of " + numRobots);
+ Thread.sleep(1000);
+ }
+ Log.info("Finished launching all robots ("+args[2]+") onto "+args[1]+" space="+args[0]+"@"+(new Date())+" thread id "+Thread.currentThread().getId());
+ try {
+ Thread.sleep(limit);
+ } catch (InterruptedException e) {
+
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ return;
+ } finally {
+ Log.info("Cleaning up for thread "+Thread.currentThread().getId()+" @ "+ (new Date()));
+ if (tests != null) {
+ tests.cleanup();
+ }
+ }
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|