Re-adding runnable Active Object Java tests, which all pass
This commit is contained in:
parent
2ed0feab46
commit
fb2ef58fb1
28 changed files with 15 additions and 1047 deletions
|
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import se.scalablesolutions.akka.config.Config;
|
||||
import se.scalablesolutions.akka.config.ActiveObjectConfigurator;
|
||||
import static se.scalablesolutions.akka.config.JavaConfig.*;
|
||||
import se.scalablesolutions.akka.dispatch.*;
|
||||
|
||||
public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
||||
static String messageLog = "";
|
||||
|
||||
final private ActiveObjectConfigurator conf = new ActiveObjectConfigurator();
|
||||
|
||||
protected void setUp() {
|
||||
Config.config();
|
||||
MessageDispatcher dispatcher = Dispatchers.newExecutorBasedEventDrivenDispatcher("test");
|
||||
|
||||
conf.addExternalGuiceModule(new AbstractModule() {
|
||||
protected void configure() {
|
||||
bind(Ext.class).to(ExtImpl.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
}).configure(
|
||||
new RestartStrategy(new AllForOne(), 3, 5000, new Class[]{Exception.class}),
|
||||
new Component[]{
|
||||
new Component(
|
||||
Foo.class,
|
||||
new LifeCycle(new Permanent()),
|
||||
1000,
|
||||
dispatcher),
|
||||
//new RemoteAddress("localhost", 9999)),
|
||||
new Component(
|
||||
Bar.class,
|
||||
BarImpl.class,
|
||||
new LifeCycle(new Permanent()),
|
||||
1000,
|
||||
dispatcher)
|
||||
}).inject().supervise();
|
||||
|
||||
}
|
||||
|
||||
public void testGuiceActiveObjectInjection() {
|
||||
messageLog = "";
|
||||
Foo foo = conf.getInstance(Foo.class);
|
||||
Bar bar = conf.getInstance(Bar.class);
|
||||
assertEquals(foo.getBar(), bar);
|
||||
}
|
||||
|
||||
public void testGuiceExternalDependencyInjection() {
|
||||
messageLog = "";
|
||||
Bar bar = conf.getInstance(Bar.class);
|
||||
Ext ext = conf.getExternalDependency(Ext.class);
|
||||
assertTrue(bar.getExt().toString().equals(ext.toString()));
|
||||
}
|
||||
|
||||
public void testLookupNonSupervisedInstance() {
|
||||
try {
|
||||
String str = conf.getInstance(String.class);
|
||||
fail("exception should have been thrown");
|
||||
} catch (Exception e) {
|
||||
assertEquals(IllegalStateException.class, e.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
public void testActiveObjectInvocation() throws InterruptedException {
|
||||
messageLog = "";
|
||||
Foo foo = conf.getInstance(Foo.class);
|
||||
messageLog += foo.foo("foo ");
|
||||
foo.bar("bar ");
|
||||
messageLog += "before_bar ";
|
||||
Thread.sleep(500);
|
||||
assertEquals("foo return_foo before_bar ", messageLog);
|
||||
}
|
||||
|
||||
public void testActiveObjectInvocationsInvocation() throws InterruptedException {
|
||||
messageLog = "";
|
||||
Foo foo = conf.getInstance(Foo.class);
|
||||
Bar bar = conf.getInstance(Bar.class);
|
||||
messageLog += foo.foo("foo ");
|
||||
foo.bar("bar ");
|
||||
messageLog += "before_bar ";
|
||||
Thread.sleep(500);
|
||||
assertEquals("foo return_foo before_bar ", messageLog);
|
||||
}
|
||||
|
||||
|
||||
public void testForcedTimeout() {
|
||||
messageLog = "";
|
||||
Foo foo = conf.getInstance(Foo.class);
|
||||
try {
|
||||
foo.longRunning();
|
||||
fail("exception should have been thrown");
|
||||
} catch (se.scalablesolutions.akka.dispatch.FutureTimeoutException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testForcedException() {
|
||||
messageLog = "";
|
||||
Foo foo = conf.getInstance(Foo.class);
|
||||
try {
|
||||
foo.throwsException();
|
||||
fail("exception should have been thrown");
|
||||
} catch (RuntimeException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
public class AllTest extends TestCase {
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("All Java tests");
|
||||
suite.addTestSuite(InMemoryStateTest.class);
|
||||
suite.addTestSuite(InMemNestedStateTest.class);
|
||||
suite.addTestSuite(RemoteInMemoryStateTest.class);
|
||||
suite.addTestSuite(ActiveObjectGuiceConfiguratorTest.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
public interface Bar {
|
||||
void bar(String msg);
|
||||
Ext getExt();
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class BarImpl implements Bar {
|
||||
@Inject
|
||||
private Ext ext;
|
||||
public Ext getExt() {
|
||||
return ext;
|
||||
}
|
||||
public void bar(String msg) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
public interface Ext {
|
||||
void ext();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
public class ExtImpl implements Ext {
|
||||
public void ext() {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class Foo extends se.scalablesolutions.akka.serialization.Serializable.JavaJSON {
|
||||
@Inject
|
||||
private Bar bar;
|
||||
public Foo body() { return this; }
|
||||
public Bar getBar() {
|
||||
return bar;
|
||||
}
|
||||
public String foo(String msg) {
|
||||
return msg + "return_foo ";
|
||||
}
|
||||
public void bar(String msg) {
|
||||
bar.bar(msg);
|
||||
}
|
||||
public String longRunning() {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
return "test";
|
||||
}
|
||||
public String throwsException() {
|
||||
if (true) throw new RuntimeException("expected");
|
||||
return "test";
|
||||
}
|
||||
|
||||
public int $tag() throws java.rmi.RemoteException
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
public class InMemFailer implements java.io.Serializable {
|
||||
public int fail() {
|
||||
throw new RuntimeException("expected");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.config.*;
|
||||
import se.scalablesolutions.akka.config.Config;
|
||||
import se.scalablesolutions.akka.config.ActiveObjectConfigurator;
|
||||
import static se.scalablesolutions.akka.config.JavaConfig.*;
|
||||
import se.scalablesolutions.akka.actor.*;
|
||||
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[]{
|
||||
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();
|
||||
}
|
||||
|
||||
public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() throws Exception {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
Thread.sleep(100);
|
||||
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
|
||||
nested.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
Thread.sleep(100);
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state", nested); // transactionrequired
|
||||
Thread.sleep(100);
|
||||
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
Thread.sleep(100);
|
||||
assertEquals("new state", nested.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
}
|
||||
|
||||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() throws InterruptedException {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
Thread.sleep(100);
|
||||
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
|
||||
nested.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
Thread.sleep(100);
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, failer); // call failing transactionrequired method
|
||||
Thread.sleep(100);
|
||||
fail("should have thrown an exception");
|
||||
} catch (RuntimeException e) {
|
||||
} // expected
|
||||
assertEquals("init", stateful.getMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state
|
||||
Thread.sleep(100);
|
||||
assertEquals("init", nested.getMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state
|
||||
}
|
||||
|
||||
public void testVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess() throws Exception {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
Thread.sleep(100);
|
||||
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
|
||||
Thread.sleep(100);
|
||||
nested.setVectorState("init"); // set init state
|
||||
Thread.sleep(100);
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state", nested); // transactionrequired
|
||||
Thread.sleep(100);
|
||||
assertEquals("new state", stateful.getVectorState());
|
||||
Thread.sleep(100);
|
||||
assertEquals("new state", nested.getVectorState());
|
||||
}
|
||||
|
||||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() throws InterruptedException {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
Thread.sleep(100);
|
||||
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
|
||||
nested.setVectorState("init"); // set init state
|
||||
Thread.sleep(100);
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, failer); // call failing transactionrequired method
|
||||
Thread.sleep(100);
|
||||
fail("should have thrown an exception");
|
||||
} catch (RuntimeException e) {
|
||||
} // expected
|
||||
assertEquals("init", stateful.getVectorState()); // check that state is == init state
|
||||
Thread.sleep(100);
|
||||
assertEquals("init", nested.getVectorState()); // check that state is == init state
|
||||
}
|
||||
|
||||
public void testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess() throws Exception {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
Thread.sleep(100);
|
||||
nested.setRefState("init"); // set init state
|
||||
Thread.sleep(100);
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state", nested); // transactionrequired
|
||||
Thread.sleep(100);
|
||||
assertEquals("new state", stateful.getRefState());
|
||||
Thread.sleep(100);
|
||||
assertEquals("new state", nested.getRefState());
|
||||
}
|
||||
|
||||
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() throws InterruptedException {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
Thread.sleep(100);
|
||||
nested.setRefState("init"); // set init state
|
||||
Thread.sleep(100);
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, failer); // call failing transactionrequired method
|
||||
Thread.sleep(100);
|
||||
fail("should have thrown an exception");
|
||||
} catch (RuntimeException e) {
|
||||
} // expected
|
||||
assertEquals("init", stateful.getRefState()); // check that state is == init state
|
||||
Thread.sleep(100);
|
||||
assertEquals("init", nested.getRefState()); // check that state is == init state
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.actor.annotation.transactionrequired;
|
||||
import se.scalablesolutions.akka.actor.annotation.prerestart;
|
||||
import se.scalablesolutions.akka.actor.annotation.postrestart;
|
||||
import se.scalablesolutions.akka.actor.annotation.inittransactionalstate;
|
||||
import se.scalablesolutions.akka.stm.*;
|
||||
|
||||
@transactionrequired
|
||||
public class InMemStateful {
|
||||
private TransactionalMap<String, String> mapState;
|
||||
private TransactionalVector<String> vectorState;
|
||||
private TransactionalRef<String> refState;
|
||||
private boolean isInitialized = false;
|
||||
|
||||
public void init() {
|
||||
if (!isInitialized) {
|
||||
mapState = TransactionalState.newMap();
|
||||
vectorState = TransactionalState.newVector();
|
||||
refState = TransactionalState.newRef();
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public String getMapState(String key) {
|
||||
return (String)mapState.get(key).get();
|
||||
}
|
||||
|
||||
public String getVectorState() {
|
||||
return (String)vectorState.last();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void success(String key, String msg) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
}
|
||||
|
||||
public void success(String key, String msg, InMemStatefulNested nested) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
nested.success(key, 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 String failure(String key, String msg, InMemStatefulNested nested, InMemFailer failer) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
nested.failure(key, msg, failer);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void thisMethodHangs(String key, String msg, InMemFailer failer) {
|
||||
setMapState(key, msg);
|
||||
}
|
||||
|
||||
@prerestart
|
||||
public void preRestart() {
|
||||
System.out.println("################ PRE RESTART");
|
||||
}
|
||||
|
||||
@postrestart
|
||||
public void postRestart() {
|
||||
System.out.println("################ POST RESTART");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.actor.annotation.transactionrequired;
|
||||
import se.scalablesolutions.akka.actor.annotation.inittransactionalstate;
|
||||
import se.scalablesolutions.akka.stm.*;
|
||||
|
||||
@transactionrequired
|
||||
public class InMemStatefulNested {
|
||||
private TransactionalMap<String, String> mapState;
|
||||
private TransactionalVector<String> vectorState;
|
||||
private TransactionalRef<String> refState;
|
||||
private boolean isInitialized = false;
|
||||
|
||||
public void init() {
|
||||
if (!isInitialized) {
|
||||
mapState = TransactionalState.newMap();
|
||||
vectorState = TransactionalState.newVector();
|
||||
refState = TransactionalState.newRef();
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public String getMapState(String key) {
|
||||
return (String) mapState.get(key).get();
|
||||
}
|
||||
|
||||
|
||||
public String getVectorState() {
|
||||
return (String) vectorState.last();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import se.scalablesolutions.akka.config.Config;
|
||||
import se.scalablesolutions.akka.config.*;
|
||||
import se.scalablesolutions.akka.config.ActiveObjectConfigurator;
|
||||
|
||||
import static se.scalablesolutions.akka.config.JavaConfig.*;
|
||||
|
||||
import se.scalablesolutions.akka.actor.*;
|
||||
|
||||
public class InMemoryStateTest extends TestCase {
|
||||
static String messageLog = "";
|
||||
|
||||
final private ActiveObjectConfigurator conf = new ActiveObjectConfigurator();
|
||||
|
||||
public InMemoryStateTest() {
|
||||
Config.config();
|
||||
conf.configure(
|
||||
new RestartStrategy(new AllForOne(), 3, 5000, new Class[] {Exception.class}),
|
||||
new Component[]{
|
||||
new Component(InMemStateful.class,
|
||||
new LifeCycle(new Permanent()),
|
||||
//new RestartCallbacks("preRestart", "postRestart")),
|
||||
10000),
|
||||
new Component(InMemFailer.class,
|
||||
new LifeCycle(new Permanent()),
|
||||
10000)
|
||||
}).supervise();
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.init();
|
||||
}
|
||||
|
||||
public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
}
|
||||
|
||||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired 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 = conf.getInstance(InMemStateful.class);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getVectorState());
|
||||
}
|
||||
|
||||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired 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 = conf.getInstance(InMemStateful.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getRefState());
|
||||
}
|
||||
|
||||
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired 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.getInstance(InMemStateful.class);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.thisMethodHangs("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired 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.getInstance(InMemStateful.class);
|
||||
// stateful.setState("stateful", "init"); // set init state
|
||||
//
|
||||
// InMemClasher clasher = conf.getInstance(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) {
|
||||
// } // expected
|
||||
// assertEquals("init", stateful.getState("stateful")); // check that state is
|
||||
// // == init state
|
||||
// // assertEquals("init", clasher.getState("clasher")); // check that state
|
||||
// is
|
||||
// // == init state
|
||||
// }
|
||||
}
|
||||
|
||||
/*
|
||||
interface InMemClasher {
|
||||
public void clash();
|
||||
|
||||
public String getState(String key);
|
||||
|
||||
public void setState(String key, String value);
|
||||
}
|
||||
|
||||
class InMemClasherImpl implements InMemClasher {
|
||||
@state
|
||||
private TransactionalMap<String, Object> state = new InMemoryTransactionalMap<String, Object>();
|
||||
|
||||
public String getState(String key) {
|
||||
return (String) state.get(key).get();
|
||||
}
|
||||
|
||||
public void setState(String key, String msg) {
|
||||
state.put(key, msg);
|
||||
}
|
||||
|
||||
public void clash() {
|
||||
state.put("clasher", "was here");
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.config.Config;
|
||||
import se.scalablesolutions.akka.actor.ActiveObject;
|
||||
import se.scalablesolutions.akka.config.ActiveObjectConfigurator;
|
||||
import se.scalablesolutions.akka.remote.RemoteNode;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class RemoteInMemoryStateTest extends TestCase {
|
||||
static String messageLog = "";
|
||||
|
||||
static {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
RemoteNode.start();
|
||||
}
|
||||
}).start();
|
||||
try { Thread.currentThread().sleep(1000); } catch (Exception e) {}
|
||||
Config.config();
|
||||
}
|
||||
final ActiveObjectConfigurator conf = new ActiveObjectConfigurator();
|
||||
|
||||
protected void tearDown() {
|
||||
conf.stop();
|
||||
}
|
||||
|
||||
public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
InMemStateful stateful = ActiveObject.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"));
|
||||
}
|
||||
|
||||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = ActiveObject.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.init();
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = ActiveObject.newRemoteInstance(InMemFailer.class, 1000, "localhost", 9999); //conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired 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 = ActiveObject.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());
|
||||
}
|
||||
|
||||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = ActiveObject.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.init();
|
||||
stateful.setVectorState("init"); // set init state
|
||||
InMemFailer failer = ActiveObject.newRemoteInstance(InMemFailer.class, 1000, "localhost", 9999); //conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired 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 = ActiveObject.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());
|
||||
}
|
||||
|
||||
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = ActiveObject.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.init();
|
||||
stateful.setRefState("init"); // set init state
|
||||
InMemFailer failer = ActiveObject.newRemoteInstance(InMemFailer.class, 1000, "localhost", 9999); //conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired 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.getInstance(InMemStateful.class);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.thisMethodHangs("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactionrequired 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.getInstance(InMemStateful.class);
|
||||
// stateful.setState("stateful", "init"); // set init state
|
||||
//
|
||||
// InMemClasher clasher = conf.getInstance(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) {
|
||||
// } // expected
|
||||
// assertEquals("init", stateful.getState("stateful")); // check that state is
|
||||
// // == init state
|
||||
// // assertEquals("init", clasher.getState("clasher")); // check that state
|
||||
// is
|
||||
// // == init state
|
||||
// }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue