2009-04-19 10:58:20 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009 Scalable Solutions.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package se.scalablesolutions.akka.api;
|
|
|
|
|
|
2009-05-09 19:55:42 +02:00
|
|
|
import se.scalablesolutions.akka.kernel.config.*;
|
|
|
|
|
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*;
|
2009-07-03 17:15:36 +02:00
|
|
|
import se.scalablesolutions.akka.kernel.actor.*;
|
2009-05-13 19:28:55 +02:00
|
|
|
import se.scalablesolutions.akka.kernel.Kernel;
|
2009-04-19 10:58:20 +02:00
|
|
|
|
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
|
|
|
|
|
|
public class PersistentStateTest extends TestCase {
|
|
|
|
|
static String messageLog = "";
|
|
|
|
|
|
2009-07-12 23:08:17 +02:00
|
|
|
final private ActiveObjectManager conf = new ActiveObjectManager();
|
2009-05-13 19:28:55 +02:00
|
|
|
|
2009-04-19 10:58:20 +02:00
|
|
|
protected void setUp() {
|
2009-07-06 23:45:15 +02:00
|
|
|
PersistenceManager.init();
|
2009-07-12 23:08:17 +02:00
|
|
|
conf.configure(
|
2009-05-23 22:24:02 +02:00
|
|
|
new RestartStrategy(new AllForOne(), 3, 5000),
|
2009-05-13 19:28:55 +02:00
|
|
|
new Component[] {
|
2009-05-23 22:24:02 +02:00
|
|
|
new Component(PersistentStateful.class, new LifeCycle(new Permanent(), 1000), 10000000),
|
2009-06-10 20:04:33 +02:00
|
|
|
new Component(PersistentFailer.class, new LifeCycle(new Permanent(), 1000), 1000)
|
|
|
|
|
//new Component(PersistentClasher.class, new LifeCycle(new Permanent(), 1000), 100000)
|
2009-05-13 19:28:55 +02:00
|
|
|
}).supervise();
|
2009-04-19 10:58:20 +02:00
|
|
|
}
|
|
|
|
|
|
2009-05-13 19:28:55 +02:00
|
|
|
protected void tearDown() {
|
|
|
|
|
conf.stop();
|
|
|
|
|
}
|
2009-06-11 13:47:07 +02:00
|
|
|
|
2009-04-19 10:58:20 +02:00
|
|
|
public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
2009-07-12 23:08:17 +02:00
|
|
|
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
2009-06-10 20:04:33 +02:00
|
|
|
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
2009-07-03 17:15:36 +02:00
|
|
|
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
2009-06-10 20:04:33 +02:00
|
|
|
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
2009-05-13 19:28:55 +02:00
|
|
|
}
|
|
|
|
|
|
2009-06-10 20:04:33 +02:00
|
|
|
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
2009-07-12 23:08:17 +02:00
|
|
|
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
2009-06-10 20:04:33 +02:00
|
|
|
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
2009-07-12 23:08:17 +02:00
|
|
|
PersistentFailer failer = conf.getInstance(PersistentFailer.class);
|
2009-06-10 20:04:33 +02:00
|
|
|
try {
|
2009-07-03 17:15:36 +02:00
|
|
|
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired method
|
2009-06-10 20:04:33 +02:00
|
|
|
fail("should have thrown an exception");
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
|
} // expected
|
|
|
|
|
assertEquals("init", stateful.getMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
2009-07-12 23:08:17 +02:00
|
|
|
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
2009-06-10 20:04:33 +02:00
|
|
|
stateful.setVectorState("init"); // set init state
|
2009-07-03 17:15:36 +02:00
|
|
|
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
2009-06-11 13:47:07 +02:00
|
|
|
assertEquals("init", stateful.getVectorState(0));
|
|
|
|
|
assertEquals("new state", stateful.getVectorState(1));
|
2009-06-10 20:04:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
2009-07-12 23:08:17 +02:00
|
|
|
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
2009-06-10 20:04:33 +02:00
|
|
|
stateful.setVectorState("init"); // set init state
|
2009-07-12 23:08:17 +02:00
|
|
|
PersistentFailer failer = conf.getInstance(PersistentFailer.class);
|
2009-06-10 20:04:33 +02:00
|
|
|
try {
|
2009-07-03 17:15:36 +02:00
|
|
|
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired method
|
2009-06-10 20:04:33 +02:00
|
|
|
fail("should have thrown an exception");
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
|
} // expected
|
2009-06-11 13:47:07 +02:00
|
|
|
assertEquals("init", stateful.getVectorState(0)); // check that state is == init state
|
2009-06-10 20:04:33 +02:00
|
|
|
}
|
2009-06-11 13:47:07 +02:00
|
|
|
|
2009-06-10 20:04:33 +02:00
|
|
|
public void testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
2009-07-12 23:08:17 +02:00
|
|
|
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
2009-06-10 20:04:33 +02:00
|
|
|
stateful.setRefState("init"); // set init state
|
2009-07-03 17:15:36 +02:00
|
|
|
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
2009-06-10 20:04:33 +02:00
|
|
|
assertEquals("new state", stateful.getRefState());
|
2009-04-19 10:58:20 +02:00
|
|
|
}
|
2009-06-10 20:04:33 +02:00
|
|
|
|
|
|
|
|
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
2009-07-12 23:08:17 +02:00
|
|
|
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
2009-06-10 20:04:33 +02:00
|
|
|
stateful.setRefState("init"); // set init state
|
2009-07-12 23:08:17 +02:00
|
|
|
PersistentFailer failer = conf.getInstance(PersistentFailer.class);
|
2009-06-10 20:04:33 +02:00
|
|
|
try {
|
2009-07-03 17:15:36 +02:00
|
|
|
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired method
|
2009-06-10 20:04:33 +02:00
|
|
|
fail("should have thrown an exception");
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
|
} // expected
|
|
|
|
|
assertEquals("init", stateful.getRefState()); // check that state is == init state
|
|
|
|
|
}
|
2009-04-27 19:55:57 +02:00
|
|
|
}
|