adapted tests to the new STM and tx datastructures
This commit is contained in:
parent
7a74669d99
commit
3971bdf5c4
15 changed files with 770 additions and 862 deletions
|
|
@ -27,7 +27,11 @@ public class InMemNestedStateTest extends TestCase {
|
|||
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();
|
||||
Config.config();
|
||||
Config.config();
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.init();
|
||||
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
|
||||
nested.init();
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,15 @@ public class InMemStateful {
|
|||
private TransactionalMap<String, String> mapState;
|
||||
private TransactionalVector<String> vectorState;
|
||||
private TransactionalRef<String> refState;
|
||||
|
||||
@inittransactionalstate
|
||||
private boolean isInitialized = false;
|
||||
|
||||
public void init() {
|
||||
mapState = TransactionalState.newMap();
|
||||
vectorState = TransactionalState.newVector();
|
||||
refState = TransactionalState.newRef();
|
||||
if (!isInitialized) {
|
||||
mapState = TransactionalState.newMap();
|
||||
vectorState = TransactionalState.newVector();
|
||||
refState = TransactionalState.newRef();
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public String getMapState(String key) {
|
||||
|
|
|
|||
|
|
@ -6,77 +6,80 @@ import se.scalablesolutions.akka.state.*;
|
|||
|
||||
@transactionrequired
|
||||
public class InMemStatefulNested {
|
||||
private TransactionalMap<String, String> mapState;
|
||||
private TransactionalVector<String> vectorState;
|
||||
private TransactionalRef<String> refState;
|
||||
private TransactionalMap<String, String> mapState;
|
||||
private TransactionalVector<String> vectorState;
|
||||
private TransactionalRef<String> refState;
|
||||
private boolean isInitialized = false;
|
||||
|
||||
@inittransactionalstate
|
||||
public void init() {
|
||||
mapState = TransactionalState.newMap();
|
||||
vectorState = TransactionalState.newVector();
|
||||
refState = TransactionalState.newRef();
|
||||
}
|
||||
|
||||
public String getMapState(String key) {
|
||||
return (String)mapState.get(key).get();
|
||||
}
|
||||
public void init() {
|
||||
if (!isInitialized) {
|
||||
mapState = TransactionalState.newMap();
|
||||
vectorState = TransactionalState.newVector();
|
||||
refState = TransactionalState.newRef();
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getVectorState() {
|
||||
return (String)vectorState.last();
|
||||
}
|
||||
public String getMapState(String key) {
|
||||
return (String) mapState.get(key).get();
|
||||
}
|
||||
|
||||
|
||||
public String getRefState() {
|
||||
return (String)refState.get().get();
|
||||
}
|
||||
|
||||
|
||||
public void setMapState(String key, String msg) {
|
||||
mapState.put(key, msg);
|
||||
}
|
||||
public String getVectorState() {
|
||||
return (String) vectorState.last();
|
||||
}
|
||||
|
||||
|
||||
public void setVectorState(String msg) {
|
||||
vectorState.add(msg);
|
||||
}
|
||||
|
||||
|
||||
public void setRefState(String msg) {
|
||||
refState.swap(msg);
|
||||
}
|
||||
public String getRefState() {
|
||||
return (String) refState.get().get();
|
||||
}
|
||||
|
||||
|
||||
public void success(String key, String msg) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
}
|
||||
|
||||
|
||||
public String failure(String key, String msg, InMemFailer failer) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
failer.fail();
|
||||
return msg;
|
||||
}
|
||||
public void setMapState(String key, String msg) {
|
||||
mapState.put(key, msg);
|
||||
}
|
||||
|
||||
|
||||
public void thisMethodHangs(String key, String msg, InMemFailer failer) {
|
||||
setMapState(key, msg);
|
||||
}
|
||||
|
||||
/*
|
||||
public void clashOk(String key, String msg, InMemClasher clasher) {
|
||||
mapState.put(key, msg);
|
||||
clasher.clash();
|
||||
}
|
||||
public void setVectorState(String msg) {
|
||||
vectorState.add(msg);
|
||||
}
|
||||
|
||||
public void clashNotOk(String key, String msg, InMemClasher clasher) {
|
||||
mapState.put(key, msg);
|
||||
clasher.clash();
|
||||
this.success("clash", "clash");
|
||||
}
|
||||
*/
|
||||
|
||||
public void setRefState(String msg) {
|
||||
refState.swap(msg);
|
||||
}
|
||||
|
||||
|
||||
public void success(String key, String msg) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
}
|
||||
|
||||
|
||||
public String failure(String key, String msg, InMemFailer failer) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
failer.fail();
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
public void thisMethodHangs(String key, String msg, InMemFailer failer) {
|
||||
setMapState(key, msg);
|
||||
}
|
||||
|
||||
/*
|
||||
public void clashOk(String key, String msg, InMemClasher clasher) {
|
||||
mapState.put(key, msg);
|
||||
clasher.clash();
|
||||
}
|
||||
|
||||
public void clashNotOk(String key, String msg, InMemClasher clasher) {
|
||||
mapState.put(key, msg);
|
||||
clasher.clash();
|
||||
this.success("clash", "clash");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
@ -32,6 +32,8 @@ public class InMemoryStateTest extends TestCase {
|
|||
new LifeCycle(new Permanent(), 1000),
|
||||
10000)
|
||||
}).inject().supervise();
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.init();
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public class RemoteInMemoryStateTest extends TestCase {
|
|||
|
||||
public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.init();
|
||||
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
|
|
@ -39,6 +40,7 @@ public class RemoteInMemoryStateTest extends TestCase {
|
|||
|
||||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.init();
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = factory.newRemoteInstance(InMemFailer.class, 1000, "localhost", 9999); //conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
|
|
@ -51,6 +53,7 @@ public class RemoteInMemoryStateTest extends TestCase {
|
|||
|
||||
public void testVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.init();
|
||||
stateful.setVectorState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getVectorState());
|
||||
|
|
@ -58,6 +61,7 @@ public class RemoteInMemoryStateTest extends TestCase {
|
|||
|
||||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.init();
|
||||
stateful.setVectorState("init"); // set init state
|
||||
InMemFailer failer = factory.newRemoteInstance(InMemFailer.class, 1000, "localhost", 9999); //conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
|
|
@ -70,6 +74,7 @@ public class RemoteInMemoryStateTest extends TestCase {
|
|||
|
||||
public void testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.init();
|
||||
stateful.setRefState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getRefState());
|
||||
|
|
@ -77,6 +82,7 @@ public class RemoteInMemoryStateTest extends TestCase {
|
|||
|
||||
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.init();
|
||||
stateful.setRefState("init"); // set init state
|
||||
InMemFailer failer = factory.newRemoteInstance(InMemFailer.class, 1000, "localhost", 9999); //conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue