From c39d9eb67a3389e7e941acaf3e168c42f5f81f25 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 3 Oct 2001 03:45:44 +0000 Subject: [PATCH] Created some code to test out the Parlor services. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@390 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/parlor/TestClient.java | 190 ++++++++++++++++++ .../com/threerings/parlor/TestConfig.java | 48 +++++ .../com/threerings/parlor/TestController.java | 11 + .../com/threerings/parlor/TestManager.java | 11 + .../com/threerings/parlor/TestServer.java | 43 ++++ 5 files changed, 303 insertions(+) create mode 100644 tests/src/java/com/threerings/parlor/TestClient.java create mode 100644 tests/src/java/com/threerings/parlor/TestConfig.java create mode 100644 tests/src/java/com/threerings/parlor/TestController.java create mode 100644 tests/src/java/com/threerings/parlor/TestManager.java create mode 100644 tests/src/java/com/threerings/parlor/TestServer.java diff --git a/tests/src/java/com/threerings/parlor/TestClient.java b/tests/src/java/com/threerings/parlor/TestClient.java new file mode 100644 index 000000000..cc0bad332 --- /dev/null +++ b/tests/src/java/com/threerings/parlor/TestClient.java @@ -0,0 +1,190 @@ +// +// $Id: TestClient.java,v 1.1 2001/10/03 03:45:44 mdb Exp $ + +package com.threerings.parlor.test; + +import com.samskivert.util.Config; +import com.samskivert.util.Queue; + +import com.threerings.cocktail.cher.client.*; +import com.threerings.cocktail.cher.dobj.DObjectManager; +import com.threerings.cocktail.cher.net.*; + +import com.threerings.cocktail.party.data.BodyObject; +import com.threerings.cocktail.party.client.*; + +import com.threerings.parlor.Log; +import com.threerings.parlor.client.*; +import com.threerings.parlor.data.*; +import com.threerings.parlor.util.ParlorContext; + +public class TestClient + implements Client.Invoker, ClientObserver, InvitationHandler, + InvitationResponseObserver +{ + public TestClient (Credentials creds) + { + // create our context + _ctx = new ParlorContextImpl(); + + // create the handles on our various services + _config = new Config(); + _client = new Client(creds, this); + _locdir = new LocationDirector(_ctx); + _occmgr = new OccupantManager(_ctx); + _pardtr = new ParlorDirector(_ctx); + + // register ourselves as the invitation handler + _pardtr.setInvitationHandler(this); + + // we want to know about logon/logoff + _client.addObserver(this); + + // for test purposes, hardcode the server info + _client.setServer("localhost", 4007); + } + + public void run () + { + // log on + _client.logon(); + + // loop over our queue, running the runnables + while (true) { + Runnable run = (Runnable)_queue.get(); + run.run(); + } + } + + public void invokeLater (Runnable run) + { + // queue it on up + _queue.append(run); + } + + public void clientDidLogon (Client client) + { + Log.info("Client did logon [client=" + client + "]."); + + // get a casted reference to our body object + _body = (BodyObject)client.getClientObject(); + + // if we're the inviter, do some inviting + if (_body.username.equals("inviter")) { + // send the invitation + TestConfig config = new TestConfig(); + _pardtr.invite("invitee", config, this); + } + } + + public void clientFailedToLogon (Client client, Exception cause) + { + Log.info("Client failed to logon [client=" + client + + ", cause=" + cause + "]."); + } + + public void clientConnectionFailed (Client client, Exception cause) + { + Log.info("Client connection failed [client=" + client + + ", cause=" + cause + "]."); + } + + public boolean clientWillLogoff (Client client) + { + Log.info("Client will logoff [client=" + client + "]."); + return true; + } + + public void clientDidLogoff (Client client) + { + Log.info("Client did logoff [client=" + client + "]."); + System.exit(0); + } + + public void invitationReceived (int inviteId, String inviter, + GameConfig config) + { + Log.info("Invitation received [inviteId=" + inviteId + + ", inviter=" + inviter + ", config=" + config + "]."); + + // accept the invitation. we're game... + _pardtr.accept(inviteId); + } + + public void invitationCancelled (int inviteId) + { + Log.info("Invitation cancelled [inviteId=" + inviteId + "]."); + } + + public void invitationAccepted (int inviteId) + { + Log.info("Invitation accepted [inviteId=" + inviteId + "]."); + } + + public void invitationRefused (int inviteId, String message) + { + Log.info("Invitation refused [inviteId=" + inviteId + + ", message=" + message + "]."); + } + + public void invitationCountered (int inviteId, GameConfig config) + { + Log.info("Invitation countered [inviteId=" + inviteId + + ", config=" + config + "]."); + } + + public static void main (String[] args) + { + String username = System.getProperty("username", "test"); + UsernamePasswordCreds creds = + new UsernamePasswordCreds(username, "test"); + // create our test client + TestClient tclient = new TestClient(creds); + // start it running + tclient.run(); + } + + protected class ParlorContextImpl implements ParlorContext + { + public Config getConfig () + { + return _config; + } + + public Client getClient () + { + return _client; + } + + public DObjectManager getDObjectManager () + { + return _client.getDObjectManager(); + } + + public LocationDirector getLocationDirector () + { + return _locdir; + } + + public OccupantManager getOccupantManager () + { + return _occmgr; + } + + public ParlorDirector getParlorDirector () + { + return _pardtr; + } + } + + protected Config _config; + protected Client _client; + protected LocationDirector _locdir; + protected OccupantManager _occmgr; + protected ParlorDirector _pardtr; + protected ParlorContext _ctx; + + protected BodyObject _body; + + protected Queue _queue = new Queue(); +} diff --git a/tests/src/java/com/threerings/parlor/TestConfig.java b/tests/src/java/com/threerings/parlor/TestConfig.java new file mode 100644 index 000000000..e32e3fb0a --- /dev/null +++ b/tests/src/java/com/threerings/parlor/TestConfig.java @@ -0,0 +1,48 @@ +// +// $Id: TestConfig.java,v 1.1 2001/10/03 03:45:44 mdb Exp $ + +package com.threerings.parlor.test; + +import java.io.IOException; +import java.io.DataInputStream; +import java.io.DataOutputStream; + +import com.threerings.parlor.data.GameConfig; + +public class TestConfig extends GameConfig +{ + /** The foozle parameter. */ + public int foozle; + + public Class getControllerClass () + { + return TestController.class; + } + + public String getManagerClassName () + { + return "com.threerings.parlor.test.TestManager"; + } + + // documentation inherited + public void writeTo (DataOutputStream out) + throws IOException + { + super.writeTo(out); + out.writeInt(foozle); + } + + // documentation inherited + public void readFrom (DataInputStream in) + throws IOException + { + super.readFrom(in); + foozle = in.readInt(); + } + + protected void toString (StringBuffer buf) + { + super.toString(buf); + buf.append(", foozle=").append(foozle); + } +} diff --git a/tests/src/java/com/threerings/parlor/TestController.java b/tests/src/java/com/threerings/parlor/TestController.java new file mode 100644 index 000000000..f0041b104 --- /dev/null +++ b/tests/src/java/com/threerings/parlor/TestController.java @@ -0,0 +1,11 @@ +// +// $Id: TestController.java,v 1.1 2001/10/03 03:45:44 mdb Exp $ + +package com.threerings.parlor.test; + +import com.threerings.parlor.client.GameController; + +public class TestController extends GameController +{ + // nothing doing +} diff --git a/tests/src/java/com/threerings/parlor/TestManager.java b/tests/src/java/com/threerings/parlor/TestManager.java new file mode 100644 index 000000000..817535462 --- /dev/null +++ b/tests/src/java/com/threerings/parlor/TestManager.java @@ -0,0 +1,11 @@ +// +// $Id: TestManager.java,v 1.1 2001/10/03 03:45:44 mdb Exp $ + +package com.threerings.parlor.test; + +import com.threerings.parlor.server.GameManager; + +public class TestManager extends GameManager +{ + // nothing doing +} diff --git a/tests/src/java/com/threerings/parlor/TestServer.java b/tests/src/java/com/threerings/parlor/TestServer.java new file mode 100644 index 000000000..5906e215d --- /dev/null +++ b/tests/src/java/com/threerings/parlor/TestServer.java @@ -0,0 +1,43 @@ +// +// $Id: TestServer.java,v 1.1 2001/10/03 03:45:44 mdb Exp $ + +package com.threerings.parlor.test; + +import com.threerings.cocktail.party.server.PartyServer; + +import com.threerings.parlor.Log; +import com.threerings.parlor.server.ParlorManager; + +/** + * A test server for the Parlor services. + */ +public class TestServer extends PartyServer +{ + /** The parlor manager in operation on this server. */ + public static ParlorManager parmgr = new ParlorManager(); + + /** Initializes the Parlor test server. */ + public void init () + throws Exception + { + super.init(); + + // initialize our parlor manager + parmgr.init(config, invmgr); + + Log.info("Parlor server initialized."); + } + + /** Main entry point for test server. */ + public static void main (String[] args) + { + TestServer server = new TestServer(); + try { + server.init(); + server.run(); + } catch (Exception e) { + Log.warning("Unable to initialize server."); + Log.logStackTrace(e); + } + } +}