-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished remote actors (with tests) plus half-baked distributed trans…
…actions (not complete)
- Loading branch information
Showing
19 changed files
with
920 additions
and
682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
fun-test-java/src/test/java/se/scalablesolutions/akka/api/RemoteInMemoryStateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/** | ||
* Copyright (C) 2009 Scalable Solutions. | ||
*/ | ||
|
||
package se.scalablesolutions.akka.api; | ||
|
||
import se.scalablesolutions.akka.kernel.config.*; | ||
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*; | ||
import se.scalablesolutions.akka.kernel.actor.*; | ||
import se.scalablesolutions.akka.kernel.nio.NettyServer; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class RemoteInMemoryStateTest extends TestCase { | ||
static String messageLog = ""; | ||
|
||
static { | ||
new Thread(new Runnable() { | ||
public void run() { | ||
NettyServer server = new NettyServer(); | ||
server.connect(); | ||
} | ||
}).start(); | ||
} | ||
final private ActiveObjectGuiceConfiguratorForJava conf = new ActiveObjectGuiceConfiguratorForJava(); | ||
final private se.scalablesolutions.akka.kernel.actor.ActiveObjectFactory factory = new se.scalablesolutions.akka.kernel.actor.ActiveObjectFactory(); | ||
|
||
protected void setUp() { | ||
new se.scalablesolutions.akka.kernel.nio.NettyServer(); | ||
conf.configureActiveObjects( | ||
new RestartStrategy(new AllForOne(), 3, 5000), | ||
new Component[]{ | ||
// FIXME: remove string-name, add ctor to only accept target class | ||
new Component(InMemStateful.class, new LifeCycle(new Permanent(), 1000), 10000000), | ||
new Component(InMemFailer.class, new LifeCycle(new Permanent(), 1000), 1000) | ||
//new Component("inmem-clasher", InMemClasher.class, InMemClasherImpl.class, new LifeCycle(new Permanent(), 1000), 100000) | ||
}).inject().supervise(); | ||
} | ||
|
||
protected void tearDown() { | ||
conf.stop(); | ||
} | ||
|
||
public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() { | ||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class); | ||
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state | ||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional | ||
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess")); | ||
} | ||
|
||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() { | ||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class); | ||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state | ||
InMemFailer failer = factory.newRemoteInstance(InMemFailer.class); //conf.getActiveObject(InMemFailer.class); | ||
try { | ||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method | ||
fail("should have thrown an exception"); | ||
} catch (RuntimeException e) { | ||
} // expected | ||
assertEquals("init", stateful.getMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state | ||
} | ||
|
||
public void testVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess() { | ||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class); | ||
stateful.setVectorState("init"); // set init state | ||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional | ||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit | ||
assertEquals("new state", stateful.getVectorState()); | ||
} | ||
|
||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() { | ||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class); | ||
stateful.setVectorState("init"); // set init state | ||
InMemFailer failer = factory.newRemoteInstance(InMemFailer.class); //conf.getActiveObject(InMemFailer.class); | ||
try { | ||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method | ||
fail("should have thrown an exception"); | ||
} catch (RuntimeException e) { | ||
} // expected | ||
assertEquals("init", stateful.getVectorState()); // check that state is == init state | ||
} | ||
|
||
public void testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess() { | ||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class); | ||
stateful.setRefState("init"); // set init state | ||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional | ||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit | ||
assertEquals("new state", stateful.getRefState()); | ||
} | ||
|
||
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() { | ||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class); | ||
stateful.setRefState("init"); // set init state | ||
InMemFailer failer = factory.newRemoteInstance(InMemFailer.class); //conf.getActiveObject(InMemFailer.class); | ||
try { | ||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method | ||
fail("should have thrown an exception"); | ||
} catch (RuntimeException e) { | ||
} // expected | ||
assertEquals("init", stateful.getRefState()); // check that state is == init state | ||
} | ||
/* | ||
public void testNestedNonTransactionalMethodHangs() { | ||
InMemStateful stateful = conf.getActiveObject(InMemStateful.class); | ||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state | ||
InMemFailer failer = conf.getActiveObject(InMemFailer.class); | ||
try { | ||
stateful.thisMethodHangs("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method | ||
fail("should have thrown an exception"); | ||
} catch (RuntimeException e) { | ||
} // expected | ||
assertEquals("init", stateful.getMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state | ||
} | ||
*/ | ||
// public void testShouldRollbackStateForStatefulServerInCaseOfMessageClash() | ||
// { | ||
// InMemStateful stateful = conf.getActiveObject(InMemStateful.class); | ||
// stateful.setState("stateful", "init"); // set init state | ||
// | ||
// InMemClasher clasher = conf.getActiveObject(InMemClasher.class); | ||
// clasher.setState("clasher", "init"); // set init state | ||
// | ||
// // try { | ||
// // stateful.clashOk("stateful", "new state", clasher); | ||
// // } catch (RuntimeException e) { } // expected | ||
// // assertEquals("new state", stateful.getState("stateful")); // check that | ||
// // state is == init state | ||
// // assertEquals("was here", clasher.getState("clasher")); // check that | ||
// // state is == init state | ||
// | ||
// try { | ||
// stateful.clashNotOk("stateful", "new state", clasher); | ||
// fail("should have thrown an exception"); | ||
// } catch (RuntimeException e) { | ||
// System.out.println(e); | ||
// } // expected | ||
// assertEquals("init", stateful.getState("stateful")); // check that state is | ||
// // == init state | ||
// // assertEquals("init", clasher.getState("clasher")); // check that state | ||
// is | ||
// // == init state | ||
// } | ||
} |
Oops, something went wrong.