pekko/akka-fun-test-java/src/test/java/se/scalablesolutions/akka/api/InMemNestedStateTest.java

124 lines
6.4 KiB
Java
Raw Normal View History

/**
* Copyright (C) 2009 Scalable Solutions.
*/
package se.scalablesolutions.akka.api;
2009-09-04 09:47:32 +02:00
import se.scalablesolutions.akka.Config;
import se.scalablesolutions.akka.config.*;
import se.scalablesolutions.akka.config.ActiveObjectConfigurator;
2009-09-04 09:47:32 +02:00
import static se.scalablesolutions.akka.config.JavaConfig.*;
import se.scalablesolutions.akka.actor.*;
import se.scalablesolutions.akka.Kernel;
import junit.framework.TestCase;
public class InMemNestedStateTest extends TestCase {
static String messageLog = "";
final private ActiveObjectConfigurator conf = new ActiveObjectConfigurator();
public InMemNestedStateTest() {
conf.configure(
new RestartStrategy(new AllForOne(), 3, 5000, new Class[]{Exception.class}),
new Component[]{
// FIXME: remove string-name, add ctor to only accept target class
new Component(InMemStateful.class, new LifeCycle(new Permanent()), 10000000),
new Component(InMemStatefulNested.class, new LifeCycle(new Permanent()), 10000000),
new Component(InMemFailer.class, new LifeCycle(new Permanent()), 1000)
//new Component("inmem-clasher", InMemClasher.class, InMemClasherImpl.class, new LifeCycle(new Permanent()), 100000)
}).supervise();
Config.config();
InMemStateful stateful = conf.getInstance(InMemStateful.class);
stateful.init();
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
nested.init();
}
2009-10-06 00:07:27 +02:00
public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() throws Exception {
InMemStateful stateful = conf.getInstance(InMemStateful.class);
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
nested.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state", nested); // transactionrequired
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
assertEquals("new state", nested.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
}
2009-10-06 00:07:27 +02:00
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() throws InterruptedException {
InMemStateful stateful = conf.getInstance(InMemStateful.class);
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
nested.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
InMemFailer failer = conf.getInstance(InMemFailer.class);
try {
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, failer); // call failing transactionrequired method
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
fail("should have thrown an exception");
} catch (RuntimeException e) {
} // expected
assertEquals("init", stateful.getMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
assertEquals("init", nested.getMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state
}
2009-10-06 00:07:27 +02:00
public void testVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess() throws Exception {
InMemStateful stateful = conf.getInstance(InMemStateful.class);
stateful.setVectorState("init"); // set init state
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
nested.setVectorState("init"); // set init state
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state", nested); // transactionrequired
assertEquals("new state", stateful.getVectorState());
assertEquals("new state", nested.getVectorState());
}
2009-10-06 00:07:27 +02:00
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() throws InterruptedException {
InMemStateful stateful = conf.getInstance(InMemStateful.class);
stateful.setVectorState("init"); // set init state
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
nested.setVectorState("init"); // set init state
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
InMemFailer failer = conf.getInstance(InMemFailer.class);
try {
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, failer); // call failing transactionrequired method
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
fail("should have thrown an exception");
} catch (RuntimeException e) {
} // expected
assertEquals("init", stateful.getVectorState()); // check that state is == init state
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
assertEquals("init", nested.getVectorState()); // check that state is == init state
}
2009-10-06 00:07:27 +02:00
public void testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess() throws Exception {
InMemStateful stateful = conf.getInstance(InMemStateful.class);
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
stateful.setRefState("init"); // set init state
nested.setRefState("init"); // set init state
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state", nested); // transactionrequired
assertEquals("new state", stateful.getRefState());
assertEquals("new state", nested.getRefState());
}
2009-10-06 00:07:27 +02:00
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() throws InterruptedException {
InMemStateful stateful = conf.getInstance(InMemStateful.class);
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
stateful.setRefState("init"); // set init state
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
nested.setRefState("init"); // set init state
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
InMemFailer failer = conf.getInstance(InMemFailer.class);
try {
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, failer); // call failing transactionrequired method
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
fail("should have thrown an exception");
} catch (RuntimeException e) {
} // expected
assertEquals("init", stateful.getRefState()); // check that state is == init state
2009-10-06 00:07:27 +02:00
Thread.sleep(100);
assertEquals("init", nested.getRefState()); // check that state is == init state
}
}