splitted kernel up in core + many sub modules
This commit is contained in:
parent
deeaa923d1
commit
ab6637044f
154 changed files with 1510 additions and 2651 deletions
|
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* Copyright (C) 2009 Scalable Solutions.
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.reactor.EventBasedThreadPoolDispatcher;
|
||||
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
||||
static String messageLog = "";
|
||||
|
||||
final private se.scalablesolutions.akka.kernel.config.ActiveObjectManager conf = new se.scalablesolutions.akka.kernel.config.ActiveObjectManager();
|
||||
|
||||
protected void setUp() {
|
||||
se.scalablesolutions.akka.kernel.Kernel$.MODULE$.config();
|
||||
EventBasedThreadPoolDispatcher dispatcher = new EventBasedThreadPoolDispatcher("name");
|
||||
dispatcher
|
||||
.withNewThreadPoolWithBoundedBlockingQueue(100)
|
||||
.setCorePoolSize(16)
|
||||
.setMaxPoolSize(128)
|
||||
.setKeepAliveTimeInMillis(60000)
|
||||
.setRejectionPolicy(new ThreadPoolExecutor.CallerRunsPolicy())
|
||||
.buildThreadPool();
|
||||
|
||||
conf.addExternalGuiceModule(new AbstractModule() {
|
||||
protected void configure() {
|
||||
bind(Ext.class).to(ExtImpl.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
}).configure(
|
||||
new RestartStrategy(new AllForOne(), 3, 5000), new Component[]{
|
||||
new Component(
|
||||
Foo.class,
|
||||
new LifeCycle(new Permanent(), 1000),
|
||||
1000,
|
||||
dispatcher),
|
||||
//new RemoteAddress("localhost", 9999)),
|
||||
new Component(
|
||||
Bar.class,
|
||||
BarImpl.class,
|
||||
new LifeCycle(new Permanent(), 1000),
|
||||
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("Class [java.lang.String] has not been put under supervision (by passing in the config to the 'configure' and then invoking 'supervise') method", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
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.kernel.reactor.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,24 @@
|
|||
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(PersistentStateTest.class);
|
||||
//suite.addTestSuite(PersistentNestedStateTest.class);
|
||||
suite.addTestSuite(RemoteInMemoryStateTest.class);
|
||||
//suite.addTestSuite(RemotePersistentStateTest.class);
|
||||
suite.addTestSuite(ActiveObjectGuiceConfiguratorTest.class);
|
||||
//suite.addTestSuite(RestTest.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.annotation.oneway;
|
||||
|
||||
public interface Bar {
|
||||
@oneway
|
||||
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,30 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import se.scalablesolutions.akka.annotation.oneway;
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
|
@ -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,110 @@
|
|||
/**
|
||||
* Copyright (C) 2009 Scalable Solutions.
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.config.*;
|
||||
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*;
|
||||
import se.scalablesolutions.akka.kernel.actor.*;
|
||||
import se.scalablesolutions.akka.kernel.Kernel;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class InMemNestedStateTest extends TestCase {
|
||||
static String messageLog = "";
|
||||
|
||||
final private ActiveObjectManager conf = new ActiveObjectManager();
|
||||
final private ActiveObjectFactory factory = new ActiveObjectFactory();
|
||||
|
||||
protected void setUp() {
|
||||
conf.configure(
|
||||
new RestartStrategy(new AllForOne(), 3, 5000),
|
||||
new Component[]{
|
||||
// FIXME: remove string-name, add ctor to only accept target class
|
||||
new Component(InMemStateful.class, new LifeCycle(new Permanent(), 1000), 10000000),
|
||||
new Component(InMemStatefulNested.class, new LifeCycle(new Permanent(), 1000), 10000000),
|
||||
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();
|
||||
se.scalablesolutions.akka.kernel.Kernel$.MODULE$.config();
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
conf.stop();
|
||||
}
|
||||
|
||||
public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
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"));
|
||||
}
|
||||
|
||||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
|
||||
nested.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, 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
|
||||
assertEquals("init", nested.getMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state
|
||||
}
|
||||
|
||||
public void testVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
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());
|
||||
}
|
||||
|
||||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
|
||||
nested.setVectorState("init"); // set init state
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, 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
|
||||
assertEquals("init", nested.getVectorState()); // check that state is == init state
|
||||
}
|
||||
|
||||
public void testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
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());
|
||||
}
|
||||
|
||||
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = conf.getInstance(InMemStateful.class);
|
||||
InMemStatefulNested nested = conf.getInstance(InMemStatefulNested.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
nested.setRefState("init"); // set init state
|
||||
InMemFailer failer = conf.getInstance(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, 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
|
||||
assertEquals("init", nested.getRefState()); // check that state is == init state
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.annotation.transactionrequired;
|
||||
import se.scalablesolutions.akka.annotation.prerestart;
|
||||
import se.scalablesolutions.akka.annotation.postrestart;
|
||||
import se.scalablesolutions.akka.kernel.state.*;
|
||||
|
||||
@transactionrequired
|
||||
public class InMemStateful {
|
||||
private TransactionalState factory = new TransactionalState();
|
||||
private TransactionalMap<String, String> mapState = factory.newInMemoryMap();
|
||||
private TransactionalVector<String> vectorState = factory.newInMemoryVector();
|
||||
private TransactionalRef<String> refState = factory.newInMemoryRef();
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
/*
|
||||
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,76 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.annotation.transactionrequired;
|
||||
import se.scalablesolutions.akka.kernel.state.*;
|
||||
|
||||
@transactionrequired
|
||||
public class InMemStatefulNested {
|
||||
private TransactionalState factory = new TransactionalState();
|
||||
private TransactionalMap<String, String> mapState = factory.newInMemoryMap();
|
||||
private TransactionalVector<String> vectorState = factory.newInMemoryVector();
|
||||
private TransactionalRef<String> refState = factory.newInMemoryRef();
|
||||
|
||||
|
||||
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,180 @@
|
|||
/**
|
||||
* Copyright (C) 2009 Scalable Solutions.
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.config.*;
|
||||
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*;
|
||||
import se.scalablesolutions.akka.kernel.actor.*;
|
||||
import se.scalablesolutions.akka.kernel.Kernel;
|
||||
|
||||
public class InMemoryStateTest extends TestCase {
|
||||
static String messageLog = "";
|
||||
|
||||
final private ActiveObjectManager conf = new ActiveObjectManager();
|
||||
|
||||
|
||||
protected void setUp() {
|
||||
se.scalablesolutions.akka.kernel.Kernel$.MODULE$.config();
|
||||
conf.configure(
|
||||
new RestartStrategy(new AllForOne(), 3, 5000),
|
||||
new Component[]{
|
||||
// FIXME: remove string-name, add ctor to only accept target class
|
||||
new Component(InMemStateful.class,
|
||||
new LifeCycle(new Permanent(), 1000),
|
||||
//new RestartCallbacks("preRestart", "postRestart")),
|
||||
10000),
|
||||
new Component(InMemFailer.class,
|
||||
new LifeCycle(new Permanent(), 1000),
|
||||
10000)
|
||||
}).inject().supervise();
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
conf.stop();
|
||||
}
|
||||
|
||||
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
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit
|
||||
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
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit
|
||||
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) {
|
||||
// System.out.println(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");
|
||||
// spend some time here
|
||||
// for (long i = 0; i < 1000000000; i++) {
|
||||
// for (long j = 0; j < 10000000; j++) {
|
||||
// j += i;
|
||||
// }
|
||||
// }
|
||||
|
||||
// FIXME: this statement gives me this error:
|
||||
// se.scalablesolutions.akka.kernel.ActiveObjectException:
|
||||
// Unexpected message [!(scala.actors.Channel@c2b2f6,ResultOrFailure[Right(null)])]
|
||||
// to
|
||||
// [GenericServer[se.scalablesolutions.akka.api.StatefulImpl]] from
|
||||
// [GenericServer[se.scalablesolutions.akka.api.ClasherImpl]]]
|
||||
// try { Thread.sleep(1000); } catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
@Path("/foo")
|
||||
public class JerseyFoo {
|
||||
@GET
|
||||
@Produces({"application/json"})
|
||||
public String foo() {
|
||||
return "hello foo";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
public class PersistenceManager {
|
||||
private static volatile boolean isRunning = false;
|
||||
public static void init() {
|
||||
if (!isRunning) {
|
||||
se.scalablesolutions.akka.kernel.Kernel.startRemoteService();
|
||||
isRunning = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.state.TransactionalMap;
|
||||
import se.scalablesolutions.akka.kernel.state.CassandraPersistentTransactionalMap;
|
||||
|
||||
public class PersistentClasher {
|
||||
private TransactionalMap state = new CassandraPersistentTransactionalMap();
|
||||
|
||||
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");
|
||||
// spend some time here
|
||||
|
||||
// FIXME: this statement gives me this error:
|
||||
// se.scalablesolutions.akka.kernel.ActiveObjectException:
|
||||
// Unexpected message [!(scala.actors.Channel@c2b2f6,ResultOrFailure[Right(null)])]
|
||||
// to
|
||||
// [GenericServer[se.scalablesolutions.akka.api.StatefulImpl]] from
|
||||
// [GenericServer[se.scalablesolutions.akka.api.ClasherImpl]]]
|
||||
// try { Thread.sleep(1000); } catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
public class PersistentFailer implements java.io.Serializable {
|
||||
public int fail() {
|
||||
throw new RuntimeException("expected");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
/**
|
||||
* Copyright (C) 2009 Scalable Solutions.
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.config.*;
|
||||
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*;
|
||||
import se.scalablesolutions.akka.kernel.actor.*;
|
||||
import se.scalablesolutions.akka.kernel.Kernel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersistentNestedStateTest extends TestCase {
|
||||
static String messageLog = "";
|
||||
|
||||
final private ActiveObjectManager conf = new ActiveObjectManager();
|
||||
final private ActiveObjectFactory factory = new ActiveObjectFactory();
|
||||
|
||||
protected void setUp() {
|
||||
PersistenceManager.init();
|
||||
conf.configure(
|
||||
new RestartStrategy(new AllForOne(), 3, 5000),
|
||||
new Component[]{
|
||||
// FIXME: remove string-name, add ctor to only accept target class
|
||||
new Component(PersistentStateful.class, new LifeCycle(new Permanent(), 1000), 10000000),
|
||||
new Component(PersistentStatefulNested.class, new LifeCycle(new Permanent(), 1000), 10000000),
|
||||
new Component(PersistentFailer.class, new LifeCycle(new Permanent(), 1000), 1000)
|
||||
//new Component("inmem-clasher", InMemClasher.class, InMemClasherImpl.class, new LifeCycle(new Permanent(), 1000), 100000)
|
||||
}).inject().supervise();
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
conf.stop();
|
||||
}
|
||||
|
||||
public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() throws Exception {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
PersistentStatefulNested nested = conf.getInstance(PersistentStatefulNested.class);
|
||||
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
nested.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state", nested); // transactional
|
||||
assertEquals("new state", nested.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
}
|
||||
|
||||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
PersistentStatefulNested nested = conf.getInstance(PersistentStatefulNested.class);
|
||||
nested.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
PersistentFailer failer = conf.getInstance(PersistentFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, 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
|
||||
assertEquals("init", nested.getMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state
|
||||
}
|
||||
|
||||
public void testVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
PersistentStatefulNested nested = conf.getInstance(PersistentStatefulNested.class);
|
||||
nested.setVectorState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state", nested); // transactional
|
||||
assertEquals(2, stateful.getVectorLength()); // BAD: keeps one element since last test
|
||||
assertEquals(2, nested.getVectorLength());
|
||||
}
|
||||
|
||||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
PersistentStatefulNested nested = conf.getInstance(PersistentStatefulNested.class);
|
||||
nested.setVectorState("init"); // set init state
|
||||
PersistentFailer failer = conf.getInstance(PersistentFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, failer); // call failing transactional method
|
||||
fail("should have thrown an exception");
|
||||
} catch (RuntimeException e) {
|
||||
} // expected
|
||||
assertEquals(1, stateful.getVectorLength());
|
||||
assertEquals(1, nested.getVectorLength());
|
||||
}
|
||||
|
||||
public void testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
PersistentStatefulNested nested = conf.getInstance(PersistentStatefulNested.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
nested.setRefState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state", nested); // transactional
|
||||
assertEquals("new state", stateful.getRefState());
|
||||
assertEquals("new state", nested.getRefState());
|
||||
}
|
||||
|
||||
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
PersistentStatefulNested nested = conf.getInstance(PersistentStatefulNested.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
nested.setRefState("init"); // set init state
|
||||
PersistentFailer failer = conf.getInstance(PersistentFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", nested, 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
|
||||
assertEquals("init", nested.getRefState()); // check that state is == init state
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* Copyright (C) 2009 Scalable Solutions.
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.config.*;
|
||||
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*;
|
||||
import se.scalablesolutions.akka.kernel.actor.*;
|
||||
import se.scalablesolutions.akka.kernel.Kernel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersistentStateTest extends TestCase {
|
||||
static String messageLog = "";
|
||||
|
||||
final private ActiveObjectManager conf = new ActiveObjectManager();
|
||||
|
||||
protected void setUp() {
|
||||
PersistenceManager.init();
|
||||
conf.configure(
|
||||
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)
|
||||
}).supervise();
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
conf.stop();
|
||||
}
|
||||
|
||||
public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
}
|
||||
|
||||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
PersistentFailer failer = conf.getInstance(PersistentFailer.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() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("init", stateful.getVectorState(0));
|
||||
assertEquals("new state", stateful.getVectorState(1));
|
||||
}
|
||||
|
||||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
PersistentFailer failer = conf.getInstance(PersistentFailer.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(0)); // check that state is == init state
|
||||
}
|
||||
|
||||
public void testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getRefState());
|
||||
}
|
||||
|
||||
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
PersistentFailer failer = conf.getInstance(PersistentFailer.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
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.annotation.transactionrequired;
|
||||
import se.scalablesolutions.akka.kernel.state.*;
|
||||
|
||||
@transactionrequired
|
||||
public class PersistentStateful {
|
||||
private TransactionalState factory = new TransactionalState();
|
||||
private TransactionalMap mapState = factory.newPersistentMap(new CassandraStorageConfig());
|
||||
private TransactionalVector vectorState = factory.newPersistentVector(new CassandraStorageConfig());;
|
||||
private TransactionalRef refState = factory.newPersistentRef(new CassandraStorageConfig());
|
||||
|
||||
|
||||
public String getMapState(String key) {
|
||||
return (String) mapState.get(key).get();
|
||||
}
|
||||
|
||||
|
||||
public String getVectorState(int index) {
|
||||
return (String) vectorState.get(index);
|
||||
}
|
||||
|
||||
public int getVectorLength() {
|
||||
return vectorState.length();
|
||||
}
|
||||
|
||||
public String getRefState() {
|
||||
if (refState.isDefined()) {
|
||||
return (String) refState.get().get();
|
||||
} else throw new IllegalStateException("No such element");
|
||||
}
|
||||
|
||||
|
||||
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, PersistentFailer failer) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
failer.fail();
|
||||
return msg;
|
||||
}
|
||||
|
||||
public String success(String key, String msg, PersistentStatefulNested nested) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
nested.success(key, msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
public String failure(String key, String msg, PersistentStatefulNested nested, PersistentFailer 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, PersistentFailer failer) {
|
||||
setMapState(key, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.annotation.transactionrequired;
|
||||
import se.scalablesolutions.akka.kernel.state.*;
|
||||
|
||||
@transactionrequired
|
||||
public class PersistentStatefulNested {
|
||||
private TransactionalState factory = new TransactionalState();
|
||||
private TransactionalMap mapState = factory.newPersistentMap(new CassandraStorageConfig());
|
||||
private TransactionalVector vectorState = factory.newPersistentVector(new CassandraStorageConfig());;
|
||||
private TransactionalRef refState = factory.newPersistentRef(new CassandraStorageConfig());
|
||||
|
||||
|
||||
public String getMapState(String key) {
|
||||
return (String) mapState.get(key).get();
|
||||
}
|
||||
|
||||
|
||||
public String getVectorState(int index) {
|
||||
return (String) vectorState.get(index);
|
||||
}
|
||||
|
||||
public int getVectorLength() {
|
||||
return vectorState.length();
|
||||
}
|
||||
|
||||
public String getRefState() {
|
||||
if (refState.isDefined()) {
|
||||
return (String) refState.get().get();
|
||||
} else throw new IllegalStateException("No such element");
|
||||
}
|
||||
|
||||
|
||||
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 String success(String key, String msg) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
public String failure(String key, String msg, PersistentFailer failer) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
failer.fail();
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
public void thisMethodHangs(String key, String msg, PersistentFailer failer) {
|
||||
setMapState(key, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,401 @@
|
|||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
public final class ProtobufProtocol {
|
||||
private ProtobufProtocol() {}
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistry registry) {
|
||||
}
|
||||
public static final class ProtobufPOJO extends
|
||||
com.google.protobuf.GeneratedMessage {
|
||||
// Use ProtobufPOJO.newBuilder() to construct.
|
||||
private ProtobufPOJO() {}
|
||||
|
||||
private static final ProtobufPOJO defaultInstance = new ProtobufPOJO();
|
||||
public static ProtobufPOJO getDefaultInstance() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
public ProtobufPOJO getDefaultInstanceForType() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return se.scalablesolutions.akka.api.ProtobufProtocol.internal_static_se_scalablesolutions_akka_api_ProtobufPOJO_descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return se.scalablesolutions.akka.api.ProtobufProtocol.internal_static_se_scalablesolutions_akka_api_ProtobufPOJO_fieldAccessorTable;
|
||||
}
|
||||
|
||||
// required uint64 id = 1;
|
||||
public static final int ID_FIELD_NUMBER = 1;
|
||||
private boolean hasId;
|
||||
private long id_ = 0L;
|
||||
public boolean hasId() { return hasId; }
|
||||
public long getId() { return id_; }
|
||||
|
||||
// required string name = 2;
|
||||
public static final int NAME_FIELD_NUMBER = 2;
|
||||
private boolean hasName;
|
||||
private java.lang.String name_ = "";
|
||||
public boolean hasName() { return hasName; }
|
||||
public java.lang.String getName() { return name_; }
|
||||
|
||||
// required bool status = 3;
|
||||
public static final int STATUS_FIELD_NUMBER = 3;
|
||||
private boolean hasStatus;
|
||||
private boolean status_ = false;
|
||||
public boolean hasStatus() { return hasStatus; }
|
||||
public boolean getStatus() { return status_; }
|
||||
|
||||
@Override
|
||||
public final boolean isInitialized() {
|
||||
if (!hasId) return false;
|
||||
if (!hasName) return false;
|
||||
if (!hasStatus) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
if (hasId()) {
|
||||
output.writeUInt64(1, getId());
|
||||
}
|
||||
if (hasName()) {
|
||||
output.writeString(2, getName());
|
||||
}
|
||||
if (hasStatus()) {
|
||||
output.writeBool(3, getStatus());
|
||||
}
|
||||
getUnknownFields().writeTo(output);
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
@Override
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (hasId()) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeUInt64Size(1, getId());
|
||||
}
|
||||
if (hasName()) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeStringSize(2, getName());
|
||||
}
|
||||
if (hasStatus()) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeBoolSize(3, getStatus());
|
||||
}
|
||||
size += getUnknownFields().getSerializedSize();
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
public static se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return newBuilder().mergeFrom(data).buildParsed();
|
||||
}
|
||||
public static se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistry extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return newBuilder().mergeFrom(data, extensionRegistry)
|
||||
.buildParsed();
|
||||
}
|
||||
public static se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return newBuilder().mergeFrom(data).buildParsed();
|
||||
}
|
||||
public static se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistry extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return newBuilder().mergeFrom(data, extensionRegistry)
|
||||
.buildParsed();
|
||||
}
|
||||
public static se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return newBuilder().mergeFrom(input).buildParsed();
|
||||
}
|
||||
public static se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO parseFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistry extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return newBuilder().mergeFrom(input, extensionRegistry)
|
||||
.buildParsed();
|
||||
}
|
||||
public static se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return newBuilder().mergeDelimitedFrom(input).buildParsed();
|
||||
}
|
||||
public static se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistry extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return newBuilder().mergeDelimitedFrom(input, extensionRegistry)
|
||||
.buildParsed();
|
||||
}
|
||||
public static se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return newBuilder().mergeFrom(input).buildParsed();
|
||||
}
|
||||
public static se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO parseFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistry extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return newBuilder().mergeFrom(input, extensionRegistry)
|
||||
.buildParsed();
|
||||
}
|
||||
|
||||
public static Builder newBuilder() { return new Builder(); }
|
||||
public Builder newBuilderForType() { return new Builder(); }
|
||||
public static Builder newBuilder(se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO prototype) {
|
||||
return new Builder().mergeFrom(prototype);
|
||||
}
|
||||
public Builder toBuilder() { return newBuilder(this); }
|
||||
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessage.Builder<Builder> {
|
||||
// Construct using se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO.newBuilder()
|
||||
private Builder() {}
|
||||
|
||||
se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO result = new se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO();
|
||||
|
||||
@Override
|
||||
protected se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO internalGetResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder clear() {
|
||||
result = new se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder clone() {
|
||||
return new Builder().mergeFrom(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO.getDescriptor();
|
||||
}
|
||||
|
||||
public se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO getDefaultInstanceForType() {
|
||||
return se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO.getDefaultInstance();
|
||||
}
|
||||
|
||||
public se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO build() {
|
||||
if (result != null && !isInitialized()) {
|
||||
throw new com.google.protobuf.UninitializedMessageException(
|
||||
result);
|
||||
}
|
||||
return buildPartial();
|
||||
}
|
||||
|
||||
private se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO buildParsed()
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
if (!isInitialized()) {
|
||||
throw new com.google.protobuf.UninitializedMessageException(
|
||||
result).asInvalidProtocolBufferException();
|
||||
}
|
||||
return buildPartial();
|
||||
}
|
||||
|
||||
public se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO buildPartial() {
|
||||
if (result == null) {
|
||||
throw new IllegalStateException(
|
||||
"build() has already been called on this Builder."); }
|
||||
se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO returnMe = result;
|
||||
result = null;
|
||||
return returnMe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||
if (other instanceof se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO) {
|
||||
return mergeFrom((se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO other) {
|
||||
if (other == se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO.getDefaultInstance()) return this;
|
||||
if (other.hasId()) {
|
||||
setId(other.getId());
|
||||
}
|
||||
if (other.hasName()) {
|
||||
setName(other.getName());
|
||||
}
|
||||
if (other.hasStatus()) {
|
||||
setStatus(other.getStatus());
|
||||
}
|
||||
this.mergeUnknownFields(other.getUnknownFields());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return mergeFrom(input,
|
||||
com.google.protobuf.ExtensionRegistry.getEmptyRegistry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistry extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||
com.google.protobuf.UnknownFieldSet.newBuilder(
|
||||
this.getUnknownFields());
|
||||
while (true) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
this.setUnknownFields(unknownFields.build());
|
||||
return this;
|
||||
default: {
|
||||
if (!parseUnknownField(input, unknownFields,
|
||||
extensionRegistry, tag)) {
|
||||
this.setUnknownFields(unknownFields.build());
|
||||
return this;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
setId(input.readUInt64());
|
||||
break;
|
||||
}
|
||||
case 18: {
|
||||
setName(input.readString());
|
||||
break;
|
||||
}
|
||||
case 24: {
|
||||
setStatus(input.readBool());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// required uint64 id = 1;
|
||||
public boolean hasId() {
|
||||
return result.hasId();
|
||||
}
|
||||
public long getId() {
|
||||
return result.getId();
|
||||
}
|
||||
public Builder setId(long value) {
|
||||
result.hasId = true;
|
||||
result.id_ = value;
|
||||
return this;
|
||||
}
|
||||
public Builder clearId() {
|
||||
result.hasId = false;
|
||||
result.id_ = 0L;
|
||||
return this;
|
||||
}
|
||||
|
||||
// required string name = 2;
|
||||
public boolean hasName() {
|
||||
return result.hasName();
|
||||
}
|
||||
public java.lang.String getName() {
|
||||
return result.getName();
|
||||
}
|
||||
public Builder setName(java.lang.String value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
result.hasName = true;
|
||||
result.name_ = value;
|
||||
return this;
|
||||
}
|
||||
public Builder clearName() {
|
||||
result.hasName = false;
|
||||
result.name_ = "";
|
||||
return this;
|
||||
}
|
||||
|
||||
// required bool status = 3;
|
||||
public boolean hasStatus() {
|
||||
return result.hasStatus();
|
||||
}
|
||||
public boolean getStatus() {
|
||||
return result.getStatus();
|
||||
}
|
||||
public Builder setStatus(boolean value) {
|
||||
result.hasStatus = true;
|
||||
result.status_ = value;
|
||||
return this;
|
||||
}
|
||||
public Builder clearStatus() {
|
||||
result.hasStatus = false;
|
||||
result.status_ = false;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
se.scalablesolutions.akka.api.ProtobufProtocol.getDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
private static com.google.protobuf.Descriptors.Descriptor
|
||||
internal_static_se_scalablesolutions_akka_api_ProtobufPOJO_descriptor;
|
||||
private static
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
||||
internal_static_se_scalablesolutions_akka_api_ProtobufPOJO_fieldAccessorTable;
|
||||
|
||||
public static com.google.protobuf.Descriptors.FileDescriptor
|
||||
getDescriptor() {
|
||||
return descriptor;
|
||||
}
|
||||
private static com.google.protobuf.Descriptors.FileDescriptor
|
||||
descriptor;
|
||||
static {
|
||||
java.lang.String descriptorData =
|
||||
"\n4se/scalablesolutions/akka/api/Protobuf" +
|
||||
"Protocol.proto\022\035se.scalablesolutions.akk" +
|
||||
"a.api\"8\n\014ProtobufPOJO\022\n\n\002id\030\001 \002(\004\022\014\n\004nam" +
|
||||
"e\030\002 \002(\t\022\016\n\006status\030\003 \002(\010B\002H\001";
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
public com.google.protobuf.ExtensionRegistry assignDescriptors(
|
||||
com.google.protobuf.Descriptors.FileDescriptor root) {
|
||||
descriptor = root;
|
||||
internal_static_se_scalablesolutions_akka_api_ProtobufPOJO_descriptor =
|
||||
getDescriptor().getMessageTypes().get(0);
|
||||
internal_static_se_scalablesolutions_akka_api_ProtobufPOJO_fieldAccessorTable = new
|
||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
|
||||
internal_static_se_scalablesolutions_akka_api_ProtobufPOJO_descriptor,
|
||||
new java.lang.String[] { "Id", "Name", "Status", },
|
||||
se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO.class,
|
||||
se.scalablesolutions.akka.api.ProtobufProtocol.ProtobufPOJO.Builder.class);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor
|
||||
.internalBuildGeneratedFileFrom(descriptorData,
|
||||
new com.google.protobuf.Descriptors.FileDescriptor[] {
|
||||
}, assigner);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* Copyright (C) 2009 Scalable Solutions.
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
/*
|
||||
Compile with:
|
||||
cd ./fun-test-java/src/test/java
|
||||
protoc se/scalablesolutions/akka/api/ProtobufProtocol.proto --java_out .
|
||||
*/
|
||||
|
||||
option optimize_for = SPEED;
|
||||
|
||||
message ProtobufPOJO {
|
||||
required uint64 id = 1;
|
||||
required string name = 2;
|
||||
required bool status = 3;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* Copyright (C) 2009 Scalable Solutions.
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import se.scalablesolutions.akka.serialization.SerializerFactory;
|
||||
|
||||
public class ProtobufSerializationTest extends TestCase {
|
||||
public void testOutIn() throws Exception {
|
||||
SerializerFactory factory = new SerializerFactory();
|
||||
ProtobufProtocol.ProtobufPOJO pojo1 = ProtobufProtocol.ProtobufPOJO.getDefaultInstance().toBuilder().setId(1).setName("protobuf").setStatus(true).build();
|
||||
|
||||
byte[] bytes = factory.getProtobuf().out(pojo1);
|
||||
Object obj = factory.getProtobuf().in(bytes, pojo1.getClass());
|
||||
|
||||
assertTrue(obj instanceof ProtobufProtocol.ProtobufPOJO);
|
||||
ProtobufProtocol.ProtobufPOJO pojo2 = (ProtobufProtocol.ProtobufPOJO)obj;
|
||||
assertEquals(pojo1.getId(), pojo2.getId());
|
||||
assertEquals(pojo1.getName(), pojo2.getName());
|
||||
assertEquals(pojo1.getStatus(), pojo2.getStatus());
|
||||
}
|
||||
|
||||
public void testDeepClone() throws Exception {
|
||||
SerializerFactory factory = new SerializerFactory();
|
||||
ProtobufProtocol.ProtobufPOJO pojo1 = ProtobufProtocol.ProtobufPOJO.getDefaultInstance().toBuilder().setId(1).setName("protobuf").setStatus(true).build();
|
||||
|
||||
Object obj = factory.getProtobuf().deepClone(pojo1);
|
||||
|
||||
assertTrue(obj instanceof ProtobufProtocol.ProtobufPOJO);
|
||||
ProtobufProtocol.ProtobufPOJO pojo2 = (ProtobufProtocol.ProtobufPOJO)obj;
|
||||
assertEquals(pojo1.getId(), pojo2.getId());
|
||||
assertEquals(pojo1.getName(), pojo2.getName());
|
||||
assertEquals(pojo1.getStatus(), pojo2.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
/**
|
||||
* Copyright (C) 2009 Scalable Solutions.
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.actor.ActiveObjectFactory;
|
||||
import se.scalablesolutions.akka.kernel.nio.RemoteServer;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class RemoteInMemoryStateTest extends TestCase {
|
||||
static String messageLog = "";
|
||||
|
||||
static {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
RemoteServer server = new RemoteServer();
|
||||
server.start();
|
||||
}
|
||||
}).start();
|
||||
try { Thread.currentThread().sleep(1000); } catch (Exception e) {}
|
||||
se.scalablesolutions.akka.kernel.Kernel$.MODULE$.config();
|
||||
}
|
||||
final private se.scalablesolutions.akka.kernel.config.ActiveObjectManager conf = new se.scalablesolutions.akka.kernel.config.ActiveObjectManager();
|
||||
final private ActiveObjectFactory factory = new ActiveObjectFactory();
|
||||
|
||||
protected void tearDown() {
|
||||
conf.stop();
|
||||
}
|
||||
|
||||
public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
}
|
||||
|
||||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = factory.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 = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getVectorState());
|
||||
}
|
||||
|
||||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
InMemFailer failer = factory.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 = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.setRefState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getRefState());
|
||||
}
|
||||
|
||||
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = factory.newRemoteInstance(InMemStateful.class, 1000, "localhost", 9999);
|
||||
stateful.setRefState("init"); // set init state
|
||||
InMemFailer failer = factory.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) {
|
||||
// System.out.println(e);
|
||||
// } // expected
|
||||
// assertEquals("init", stateful.getState("stateful")); // check that state is
|
||||
// // == init state
|
||||
// // assertEquals("init", clasher.getState("clasher")); // check that state
|
||||
// is
|
||||
// // == init state
|
||||
// }
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* Copyright (C) 2009 Scalable Solutions.
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.config.*;
|
||||
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*;
|
||||
import se.scalablesolutions.akka.kernel.actor.*;
|
||||
import se.scalablesolutions.akka.kernel.Kernel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class RemotePersistentStateTest extends TestCase {
|
||||
static String messageLog = "";
|
||||
|
||||
final private ActiveObjectManager conf = new ActiveObjectManager();
|
||||
|
||||
protected void setUp() {
|
||||
PersistenceManager.init();
|
||||
conf.configure(
|
||||
new RestartStrategy(new AllForOne(), 3, 5000),
|
||||
new Component[] {
|
||||
new Component(PersistentStateful.class, new LifeCycle(new Permanent(), 1000), 1000000, new RemoteAddress("localhost", 9999)),
|
||||
new Component(PersistentFailer.class, new LifeCycle(new Permanent(), 1000), 1000000, new RemoteAddress("localhost", 9999))
|
||||
}).supervise();
|
||||
}
|
||||
|
||||
protected void tearDown() {
|
||||
conf.stop();
|
||||
}
|
||||
|
||||
public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
}
|
||||
|
||||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
PersistentFailer failer = conf.getInstance(PersistentFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "MapShouldRollBack", 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() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
int init = stateful.getVectorLength();
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "VectorShouldNotRollback"); // transactionrequired
|
||||
assertEquals(init + 1, stateful.getVectorLength());
|
||||
}
|
||||
|
||||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
int init = stateful.getVectorLength();
|
||||
PersistentFailer failer = conf.getInstance(PersistentFailer.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.getVectorLength());
|
||||
}
|
||||
|
||||
public void testRefShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactionrequired
|
||||
assertEquals("new state", stateful.getRefState());
|
||||
}
|
||||
|
||||
public void testRefShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
PersistentStateful stateful = conf.getInstance(PersistentStateful.class);
|
||||
stateful.setRefState("init"); // set init state
|
||||
PersistentFailer failer = conf.getInstance(PersistentFailer.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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* Copyright (C) 2009 Scalable Solutions.
|
||||
*/
|
||||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import com.sun.jersey.api.client.Client;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory;
|
||||
import com.sun.grizzly.http.SelectorThread;
|
||||
import com.sun.grizzly.http.servlet.ServletAdapter;
|
||||
import com.sun.grizzly.tcp.Adapter;
|
||||
import com.sun.grizzly.standalone.StaticStreamAlgorithm;
|
||||
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.servlet.Servlet;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.config.*;
|
||||
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*;
|
||||
|
||||
|
||||
public class RestTest extends TestCase {
|
||||
|
||||
private static int PORT = 9998;
|
||||
private static URI URI = UriBuilder.fromUri("http://localhost/").port(PORT).build();
|
||||
private static SelectorThread selector = null;
|
||||
private static ActiveObjectManager conf = new ActiveObjectManager();
|
||||
|
||||
@BeforeClass
|
||||
protected void setUp() {
|
||||
conf.configure(
|
||||
new RestartStrategy(new AllForOne(), 3, 5000),
|
||||
new Component[] {
|
||||
new Component(
|
||||
JerseyFoo.class,
|
||||
new LifeCycle(new Permanent(), 1000),
|
||||
10000000)
|
||||
}).inject().supervise();
|
||||
selector = startJersey();
|
||||
}
|
||||
|
||||
public void testSimpleRequest() {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@Test
|
||||
public void testSimpleRequest() throws IOException, InstantiationException {
|
||||
selector.listen();
|
||||
Client client = Client.create();
|
||||
WebResource webResource = client.resource(URI);
|
||||
String responseMsg = webResource.path("/foo").get(String.class);
|
||||
assertEquals("hello foo", responseMsg);
|
||||
selector.stopEndpoint();
|
||||
}
|
||||
*/
|
||||
private static SelectorThread startJersey() {
|
||||
try {
|
||||
Servlet servlet = new se.scalablesolutions.akka.kernel.rest.AkkaServlet();
|
||||
ServletAdapter adapter = new ServletAdapter();
|
||||
adapter.setServletInstance(servlet);
|
||||
adapter.setContextPath(URI.getPath());
|
||||
return createGrizzlySelector(adapter, URI, PORT);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static SelectorThread createGrizzlySelector(Adapter adapter, URI uri, int port) throws IOException, InstantiationException {
|
||||
final String scheme = uri.getScheme();
|
||||
if (!scheme.equalsIgnoreCase("http"))
|
||||
throw new IllegalArgumentException("The URI scheme, of the URI " + uri + ", must be equal (ignoring case) to 'http'");
|
||||
final SelectorThread selectorThread = new SelectorThread();
|
||||
selectorThread.setAlgorithmClassName(StaticStreamAlgorithm.class.getName());
|
||||
selectorThread.setPort(port);
|
||||
selectorThread.setAdapter(adapter);
|
||||
return selectorThread;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue