Whipped unit tests into shape. Added simple test for dobject transactions.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@978 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-02-09 07:50:04 +00:00
parent c57ff60e69
commit a1162ae85a
11 changed files with 79 additions and 93 deletions
@@ -1,5 +1,5 @@
//
// $Id: DOMTest.java,v 1.6 2001/11/08 05:40:07 mdb Exp $
// $Id: DOMTest.java,v 1.7 2002/02/09 07:50:04 mdb Exp $
package com.threerings.presents.server;
@@ -12,8 +12,7 @@ import com.threerings.presents.dobj.*;
/**
* A simple test case for the dobjmgr.
*/
public class DOMTest
extends TestCase
public class DOMTest extends TestCase
implements Subscriber, AttributeChangeListener
{
public DOMTest ()
@@ -26,8 +25,15 @@ public class DOMTest
// add ourselves as a listener
object.addListener(this);
// set some values
TestObject to = (TestObject)object;
// test transactions
to.startTransaction();
to.setFoo(99);
to.setBar("hoopie");
to.commitTransaction();
// now set some values straight up
to.setFoo(25);
to.setBar("howdy");
}
@@ -35,37 +41,53 @@ public class DOMTest
public void requestFailed (int oid, ObjectAccessException cause)
{
fail("Request failed: " + cause);
omgr.shutdown();
_omgr.shutdown();
}
public void attributeChanged (AttributeChangedEvent event)
{
// if this is the second event, request a shutdown
if (event.getName().equals(TestObject.FOO)) {
assert("foo=25", event.getIntValue() == 25);
assert(fields[_fcount] + " == " + values[_fcount],
event.getName().equals(fields[_fcount]) &&
event.getValue().equals(values[_fcount]));
} else if (event.getName().equals(TestObject.BAR)) {
assert("bar=howdy", "howdy".equals(event.getValue()));
omgr.shutdown();
// shutdown once we receive our last update
if (++_fcount == fields.length) {
_omgr.shutdown();
}
}
public void runTest ()
{
// request that a new TestObject be created
omgr.createObject(TestObject.class, this);
_omgr.createObject(TestObject.class, this);
// or for fun you can try this bogus create request
// omgr.createObject(Integer.class, sub);
// _omgr.createObject(Integer.class, sub);
// and run the object manager
omgr.run();
_omgr.run();
}
public static Test suite ()
{
return new RefTest();
return new DOMTest();
}
public static PresentsDObjectMgr omgr = new PresentsDObjectMgr();
public static void main (String[] args)
{
DOMTest test = new DOMTest();
test.runTest();
}
protected int _fcount = 0;
// the fields that will change in attribute changed events
protected Object[] fields = {
TestObject.FOO, TestObject.BAR, TestObject.FOO, TestObject.BAR };
// the values we'll receive via attribute changed events
protected Object[] values = {
new Integer(99), "hoopie", new Integer(25), "howdy" };
protected static PresentsDObjectMgr _omgr = new PresentsDObjectMgr();
}
@@ -1,5 +1,5 @@
//
// $Id: DestroyedRefTest.java,v 1.6 2001/11/08 05:40:07 mdb Exp $
// $Id: DestroyedRefTest.java,v 1.7 2002/02/09 07:50:04 mdb Exp $
package com.threerings.presents.server;
@@ -71,7 +71,7 @@ public class DestroyedRefTest
} else if (event instanceof AttributeChangedEvent) {
// go bye bye
PresentsServer.shutdown();
_omgr.shutdown();
} else {
fail("Got unexpected event: " + event);
@@ -80,23 +80,12 @@ public class DestroyedRefTest
public void runTest ()
{
PresentsServer server = new TestPresentsServer();
try {
// initialize the server
server.init();
// create two test objects
_omgr.createObject(TestObject.class, this);
_omgr.createObject(TestObject.class, this);
// create two test objects
PresentsServer.omgr.createObject(TestObject.class, this);
PresentsServer.omgr.createObject(TestObject.class, this);
// start the server to running (this method call won't return
// until the server is shut down)
server.run();
} catch (Exception e) {
Log.warning("Unable to initialize server.");
Log.logStackTrace(e);
}
// and run the object manager
_omgr.run();
}
public static Test suite ()
@@ -106,4 +95,6 @@ public class DestroyedRefTest
protected TestObject _objone;
protected TestObject _objtwo;
protected static PresentsDObjectMgr _omgr = new PresentsDObjectMgr();
}
@@ -1,5 +1,5 @@
//
// $Id: RefTest.java,v 1.6 2001/11/08 05:40:07 mdb Exp $
// $Id: RefTest.java,v 1.7 2002/02/09 07:50:04 mdb Exp $
package com.threerings.presents.server;
@@ -63,7 +63,7 @@ public class RefTest
} else {
// Log.info("Other object destroyed.");
// go bye bye
PresentsServer.shutdown();
_omgr.shutdown();
}
} else if (event instanceof ObjectRemovedEvent) {
@@ -76,23 +76,12 @@ public class RefTest
public void runTest ()
{
PresentsServer server = new TestPresentsServer();
try {
// initialize the server
server.init();
// create two test objects
_omgr.createObject(TestObject.class, this);
_omgr.createObject(TestObject.class, this);
// create two test objects
PresentsServer.omgr.createObject(TestObject.class, this);
PresentsServer.omgr.createObject(TestObject.class, this);
// start the server to running (this method call won't return
// until the server is shut down)
server.run();
} catch (Exception e) {
Log.warning("Unable to initialize server.");
Log.logStackTrace(e);
}
// and run the object manager
_omgr.run();
}
public static Test suite ()
@@ -102,4 +91,6 @@ public class RefTest
protected TestObject _objone;
protected TestObject _objtwo;
protected static PresentsDObjectMgr _omgr = new PresentsDObjectMgr();
}
@@ -1,17 +0,0 @@
//
// $Id: TestPresentsServer.java,v 1.1 2001/11/08 05:40:07 mdb Exp $
package com.threerings.presents.server;
/**
* This test version of the server avoids creating a connection manager
* because that requires a shared library which we don't have available
* when testing via ant/JUnit.
*/
public class TestPresentsServer extends PresentsServer
{
protected boolean createConnectionManager ()
{
return false;
}
}