Swapped out Scala Actors to a reactor based impl (still restart and linking to do) + finalized transactional persisted cassandra based vector (ref to go)

This commit is contained in:
Jonas Boner 2009-06-10 20:04:33 +02:00
parent 167b724671
commit ac52556595
22 changed files with 726 additions and 404 deletions

View file

@ -95,7 +95,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
try {
foo.longRunning();
fail("exception should have been thrown");
} catch (se.scalablesolutions.akka.kernel.ActiveObjectInvocationTimeoutException e) {
} catch (se.scalablesolutions.akka.kernel.reactor.FutureTimeoutException e) {
}
}

View file

@ -27,8 +27,8 @@ public class PersistentStateTest extends TestCase {
new RestartStrategy(new AllForOne(), 3, 5000),
new Component[] {
new Component(PersistentStateful.class, new LifeCycle(new Permanent(), 1000), 10000000),
new Component(PersistentFailer.class, new LifeCycle(new Permanent(), 1000), 1000),
new Component(PersistentClasher.class, new LifeCycle(new Permanent(), 1000), 100000)
new Component(PersistentFailer.class, new LifeCycle(new Permanent(), 1000), 1000)
//new Component(PersistentClasher.class, new LifeCycle(new Permanent(), 1000), 100000)
}).supervise();
}
@ -38,21 +38,62 @@ public class PersistentStateTest extends TestCase {
public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
PersistentStateful stateful = conf.getActiveObject(PersistentStateful.class);
stateful.setState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit
assertEquals("new state", stateful.getState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
}
public void testShouldRollbackStateForStatefulServerInCaseOfFailure() {
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
PersistentStateful stateful = conf.getActiveObject(PersistentStateful.class);
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
PersistentFailer failer = conf.getActiveObject(PersistentFailer.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() {
PersistentStateful stateful = conf.getActiveObject(PersistentStateful.class);
stateful.setState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
PersistentFailer failer = conf.getActiveObject(PersistentFailer.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.getState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state
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() {
PersistentStateful stateful = conf.getActiveObject(PersistentStateful.class);
stateful.setVectorState("init"); // set init state
PersistentFailer failer = conf.getActiveObject(PersistentFailer.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() {
PersistentStateful stateful = conf.getActiveObject(PersistentStateful.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() {
PersistentStateful stateful = conf.getActiveObject(PersistentStateful.class);
stateful.setRefState("init"); // set init state
PersistentFailer failer = conf.getActiveObject(PersistentFailer.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
}
*/
}

View file

@ -1,42 +1,56 @@
package se.scalablesolutions.akka.api;
import se.scalablesolutions.akka.kernel.TransactionalMap;
import se.scalablesolutions.akka.kernel.CassandraPersistentTransactionalMap;
import se.scalablesolutions.akka.kernel.*;
import se.scalablesolutions.akka.annotation.transactional;
import se.scalablesolutions.akka.annotation.state;
public class PersistentStateful {
private TransactionalMap state = new CassandraPersistentTransactionalMap(this);
private TransactionalMap mapState = new CassandraPersistentTransactionalMap(this);
private TransactionalVector vectorState = new CassandraPersistentTransactionalVector(this);
//private TransactionalRef refState = new CassandraPersistentTransactionalRef(this);
public String getState(String key) {
return (String)state.get(key).get();
public String getMapState(String key) {
return (String) mapState.get(key).get();
}
public void setState(String key, String msg) {
state.put(key, msg);
public String getVectorState() {
return (String) vectorState.first();
}
// public String getRefState() {
// return (String) refState.get().get();
// }
public void setMapState(String key, String msg) {
mapState.put(key, msg);
}
public void setVectorState(String msg) {
vectorState.add(msg);
}
// public void setRefState(String msg) {
// refState.swap(msg);
// }
@transactional
public void success(String key, String msg) {
state.put(key, msg);
mapState.put(key, msg);
vectorState.add(msg);
// refState.swap(msg);
}
@transactional
public void failure(String key, String msg, PersistentFailer failer) {
state.put(key, msg);
mapState.put(key, msg);
vectorState.add(msg);
// refState.swap(msg);
failer.fail();
}
@transactional
public void clashOk(String key, String msg, PersistentClasher clasher) {
state.put(key, msg);
clasher.clash();
}
@transactional
public void clashNotOk(String key, String msg, PersistentClasher clasher) {
state.put(key, msg);
clasher.clash();
clasher.clash();
public void thisMethodHangs(String key, String msg, PersistentFailer failer) {
setMapState(key, msg);
}
}