fixed final issues with AW proxy integration and remaining tests
This commit is contained in:
parent
e0591005ed
commit
bbec315eb2
29 changed files with 933 additions and 866 deletions
|
|
@ -56,5 +56,6 @@
|
|||
<classpathentry kind="lib" path="/Users/jboner/src/scala/akka/lib/commons-collections-3.2.1.jar"/>
|
||||
<classpathentry kind="lib" path="/Users/jboner/src/scala/akka/lib/commons-lang-2.4.jar"/>
|
||||
<classpathentry kind="lib" path="/Users/jboner/src/scala/akka/lib/high-scale-lib.jar"/>
|
||||
<classpathentry kind="lib" path="/Users/jboner/src/scala/akka/lib/jersey-client-1.1.0-ea.jar"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
|
|||
|
|
@ -24,31 +24,37 @@
|
|||
<groupId>com.sun.grizzly</groupId>
|
||||
<artifactId>grizzly-servlet-webserver</artifactId>
|
||||
<version>1.9.9</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-server</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-json</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>1.1.0-ea</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-atom</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jmock</groupId>
|
||||
|
|
|
|||
|
|
@ -32,17 +32,14 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
|||
}).configureActiveObjects(
|
||||
new RestartStrategy(new AllForOne(), 3, 5000), new Component[]{
|
||||
new Component(
|
||||
"foo",
|
||||
Foo.class,
|
||||
FooImpl.class,
|
||||
new LifeCycle(new Permanent(), 1000),
|
||||
1000),
|
||||
10000),
|
||||
new Component(
|
||||
"bar",
|
||||
Bar.class,
|
||||
BarImpl.class,
|
||||
new LifeCycle(new Permanent(), 1000),
|
||||
1000)
|
||||
10000)
|
||||
}).inject().supervise();
|
||||
|
||||
}
|
||||
|
|
@ -51,7 +48,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
|||
messageLog = "";
|
||||
Foo foo = conf.getActiveObject(Foo.class);
|
||||
Bar bar = conf.getActiveObject(Bar.class);
|
||||
assertTrue(foo.getBar().toString().equals(bar.toString()));
|
||||
assertEquals(foo.getBar(), bar);
|
||||
}
|
||||
|
||||
public void testGuiceExternalDependencyInjection() {
|
||||
|
|
@ -66,7 +63,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
|||
String str = conf.getActiveObject(String.class);
|
||||
fail("exception should have been thrown");
|
||||
} catch (Exception e) {
|
||||
assertEquals("Class string has not been put under supervision (by passing in the config to the supervise() method", e.getMessage());
|
||||
assertEquals("Class [java.lang.String] has not been put under supervision (by passing in the config to the 'configureActiveObjects' and then invoking 'supervise') method", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -113,57 +110,4 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
public String foo(String msg);
|
||||
@oneway public void bar(String msg);
|
||||
public void longRunning();
|
||||
public void throwsException();
|
||||
public Bar getBar();
|
||||
}
|
||||
|
||||
class FooImpl implements Foo {
|
||||
@Inject private Bar bar;
|
||||
public Bar getBar() {
|
||||
return bar;
|
||||
}
|
||||
public String foo(String msg) {
|
||||
return msg + "return_foo ";
|
||||
}
|
||||
public void bar(String msg) {
|
||||
bar.bar(msg);
|
||||
}
|
||||
public void longRunning() {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
public void throwsException() {
|
||||
throw new RuntimeException("expected");
|
||||
}
|
||||
}
|
||||
|
||||
interface Bar {
|
||||
@oneway void bar(String msg);
|
||||
Ext getExt();
|
||||
}
|
||||
|
||||
class BarImpl implements Bar {
|
||||
@Inject private Ext ext;
|
||||
public Ext getExt() {
|
||||
return ext;
|
||||
}
|
||||
public void bar(String msg) {
|
||||
}
|
||||
}
|
||||
|
||||
interface Ext {
|
||||
void ext();
|
||||
}
|
||||
|
||||
class ExtImpl implements Ext {
|
||||
public void ext() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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,28 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import se.scalablesolutions.akka.annotation.oneway;
|
||||
|
||||
public class Foo {
|
||||
@Inject
|
||||
private Bar bar;
|
||||
public Bar getBar() {
|
||||
return bar;
|
||||
}
|
||||
public String foo(String msg) {
|
||||
return msg + "return_foo ";
|
||||
}
|
||||
@oneway
|
||||
public void bar(String msg) {
|
||||
bar.bar(msg);
|
||||
}
|
||||
public void longRunning() {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
public void throwsException() {
|
||||
throw new RuntimeException("expected");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
public interface InMemFailer {
|
||||
public void fail();
|
||||
public class InMemFailer {
|
||||
public void fail() {
|
||||
throw new RuntimeException("expected");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,68 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.annotation.state;
|
||||
import se.scalablesolutions.akka.annotation.transactional;
|
||||
import se.scalablesolutions.akka.kernel.*;
|
||||
|
||||
public interface InMemStateful {
|
||||
// transactional
|
||||
@transactional
|
||||
public void success(String key, String msg);
|
||||
public class InMemStateful {
|
||||
@state private TransactionalMap<String, String> mapState = new InMemoryTransactionalMap<String, String>();
|
||||
@state private TransactionalVector<String> vectorState = new InMemoryTransactionalVector<String>();
|
||||
@state private TransactionalRef<String> refState = new TransactionalRef<String>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@transactional
|
||||
public void failure(String key, String msg, InMemFailer failer);
|
||||
public void success(String key, String msg) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
}
|
||||
|
||||
//@transactional
|
||||
//public void clashOk(String key, String msg, InMemClasher clasher);
|
||||
@transactional
|
||||
public void failure(String key, String msg, InMemFailer failer) {
|
||||
mapState.put(key, msg);
|
||||
vectorState.add(msg);
|
||||
refState.swap(msg);
|
||||
failer.fail();
|
||||
}
|
||||
|
||||
//@transactional
|
||||
//public void clashNotOk(String key, String msg, InMemClasher clasher);
|
||||
@transactional
|
||||
public void thisMethodHangs(String key, String msg, InMemFailer failer) {
|
||||
setMapState(key, msg);
|
||||
}
|
||||
|
||||
// non-transactional
|
||||
public String getState(String key);
|
||||
/*
|
||||
public void clashOk(String key, String msg, InMemClasher clasher) {
|
||||
mapState.put(key, msg);
|
||||
clasher.clash();
|
||||
}
|
||||
|
||||
public void setState(String key, String value);
|
||||
}
|
||||
public void clashNotOk(String key, String msg, InMemClasher clasher) {
|
||||
mapState.put(key, msg);
|
||||
clasher.clash();
|
||||
this.success("clash", "clash");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.annotation.state;
|
||||
import se.scalablesolutions.akka.kernel.TransactionalMap;
|
||||
import se.scalablesolutions.akka.kernel.InMemoryTransactionalMap;
|
||||
|
||||
public class InMemStatefulImpl implements InMemStateful {
|
||||
@state
|
||||
private TransactionalMap<String, String> state = new InMemoryTransactionalMap<String, String>();
|
||||
|
||||
public String getState(String key) {
|
||||
return state.get(key).get();
|
||||
}
|
||||
|
||||
public void setState(String key, String msg) {
|
||||
state.put(key, msg);
|
||||
}
|
||||
|
||||
public void success(String key, String msg) {
|
||||
state.put(key, msg);
|
||||
}
|
||||
|
||||
public void failure(String key, String msg, InMemFailer failer) {
|
||||
state.put(key, msg);
|
||||
failer.fail();
|
||||
}
|
||||
|
||||
/*
|
||||
public void clashOk(String key, String msg, InMemClasher clasher) {
|
||||
state.put(key, msg);
|
||||
clasher.clash();
|
||||
}
|
||||
|
||||
public void clashNotOk(String key, String msg, InMemClasher clasher) {
|
||||
state.put(key, msg);
|
||||
clasher.clash();
|
||||
this.success("clash", "clash");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
@ -4,11 +4,8 @@
|
|||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.annotation.*;
|
||||
import se.scalablesolutions.akka.kernel.config.*;
|
||||
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*;
|
||||
import se.scalablesolutions.akka.kernel.TransactionalMap;
|
||||
import se.scalablesolutions.akka.kernel.InMemoryTransactionalMap;
|
||||
import se.scalablesolutions.akka.kernel.config.*;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
|
@ -22,35 +19,68 @@ public class InMemoryStateTest extends TestCase {
|
|||
new RestartStrategy(new AllForOne(), 3, 5000),
|
||||
new Component[] {
|
||||
// FIXME: remove string-name, add ctor to only accept target class
|
||||
new Component("inmem-stateful", InMemStateful.class, InMemStatefulImpl.class, new LifeCycle(new Permanent(), 1000), 10000000),
|
||||
new Component("inmem-failer", InMemFailer.class, InMemFailerImpl.class, new LifeCycle(new Permanent(), 1000), 1000)
|
||||
new Component(InMemStateful.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();
|
||||
}
|
||||
|
||||
|
||||
protected void tearDown() {
|
||||
conf.stop();
|
||||
}
|
||||
|
||||
public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
public void testMapShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
InMemStateful stateful = conf.getActiveObject(InMemStateful.class);
|
||||
stateful.setState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
stateful.setMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit
|
||||
assertEquals("new state", stateful.getState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
assertEquals("new state", stateful.getMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
|
||||
}
|
||||
|
||||
public void testShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
public void testMapShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = conf.getActiveObject(InMemStateful.class);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = conf.getActiveObject(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", 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
|
||||
}
|
||||
|
||||
public void testVectorShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
InMemStateful stateful = conf.getActiveObject(InMemStateful.class);
|
||||
stateful.setState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = conf.getActiveObject(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method
|
||||
fail("should have thrown an exception");
|
||||
} catch (RuntimeException e) {
|
||||
} // expected
|
||||
assertEquals("init", stateful.getState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state
|
||||
stateful.setVectorState("init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit
|
||||
assertEquals("new state", stateful.getVectorState());
|
||||
}
|
||||
|
||||
public void testVectorShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = conf.getActiveObject(InMemStateful.class);
|
||||
stateful.setVectorState("init"); // set init state
|
||||
InMemFailer failer = conf.getActiveObject(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method
|
||||
fail("should have thrown an exception");
|
||||
} catch (RuntimeException e) {
|
||||
} // expected
|
||||
assertEquals("init", stateful.getVectorState()); // check that state is == init state
|
||||
}
|
||||
|
||||
public void testNestedNonTransactionalMethodHangs() {
|
||||
InMemStateful stateful = conf.getActiveObject(InMemStateful.class);
|
||||
stateful.setMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = conf.getActiveObject(InMemFailer.class);
|
||||
try {
|
||||
stateful.thisMethodHangs("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", 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
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
// public void testShouldRollbackStateForStatefulServerInCaseOfMessageClash()
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@ import javax.ws.rs.GET;
|
|||
import javax.ws.rs.Produces;
|
||||
|
||||
@Path("/foo")
|
||||
public interface JerseyFoo {
|
||||
public class JerseyFoo {
|
||||
@GET
|
||||
@Produces({"application/json"})
|
||||
public String foo();
|
||||
}
|
||||
public String foo() {
|
||||
return "hello foo";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
//@Path("/foo")
|
||||
public class JerseyFooImpl implements JerseyFoo {
|
||||
//@GET
|
||||
//@Produces({"application/json"})
|
||||
public String foo() {
|
||||
return "hello foo";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.TransactionalMap;
|
||||
import se.scalablesolutions.akka.kernel.CassandraPersistentTransactionalMap;
|
||||
|
||||
public class PersistentClasher {
|
||||
private TransactionalMap state = new CassandraPersistentTransactionalMap(this);
|
||||
|
||||
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,ErrRef[Right(null)])]
|
||||
// to
|
||||
// [GenericServer[se.scalablesolutions.akka.api.StatefulImpl]] from
|
||||
// [GenericServer[se.scalablesolutions.akka.api.ClasherImpl]]]
|
||||
// try { Thread.sleep(1000); } catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
public class InMemFailerImpl implements InMemFailer {
|
||||
public class PersistentFailer {
|
||||
public void fail() {
|
||||
throw new RuntimeException("expected");
|
||||
}
|
||||
|
|
@ -6,11 +6,6 @@ package se.scalablesolutions.akka.api;
|
|||
|
||||
import se.scalablesolutions.akka.annotation.*;
|
||||
import se.scalablesolutions.akka.kernel.config.*;
|
||||
import se.scalablesolutions.akka.kernel.config.JavaConfig.AllForOne;
|
||||
import se.scalablesolutions.akka.kernel.config.JavaConfig.Component;
|
||||
import se.scalablesolutions.akka.kernel.config.JavaConfig.LifeCycle;
|
||||
import se.scalablesolutions.akka.kernel.config.JavaConfig.Permanent;
|
||||
import se.scalablesolutions.akka.kernel.config.JavaConfig.RestartStrategy;
|
||||
import static se.scalablesolutions.akka.kernel.config.JavaConfig.*;
|
||||
import se.scalablesolutions.akka.kernel.Kernel;
|
||||
import se.scalablesolutions.akka.kernel.TransactionalMap;
|
||||
|
|
@ -29,11 +24,11 @@ public class PersistentStateTest extends TestCase {
|
|||
|
||||
protected void setUp() {
|
||||
conf.configureActiveObjects(
|
||||
new JavaConfig.RestartStrategy(new JavaConfig.AllForOne(), 3, 5000),
|
||||
new RestartStrategy(new AllForOne(), 3, 5000),
|
||||
new Component[] {
|
||||
new Component("persistent-stateful", PersistentStateful.class, PersistentStatefulImpl.class, new LifeCycle(new Permanent(), 1000), 10000000),
|
||||
new Component("persistent-failer", PersistentFailer.class, PersistentFailerImpl.class, new LifeCycle(new Permanent(), 1000), 1000),
|
||||
new Component("persistent-clasher", PersistentClasher.class, PersistentClasherImpl.class, new LifeCycle(new Permanent(), 1000), 100000)
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
@ -61,96 +56,3 @@ public class PersistentStateTest extends TestCase {
|
|||
assertEquals("init", stateful.getState("testShouldRollbackStateForStatefulServerInCaseOfFailure")); // check that state is == init state
|
||||
}
|
||||
}
|
||||
|
||||
interface PersistentStateful {
|
||||
@transactional
|
||||
public void success(String key, String msg);
|
||||
|
||||
@transactional
|
||||
public void failure(String key, String msg, PersistentFailer failer);
|
||||
|
||||
@transactional
|
||||
public void clashOk(String key, String msg, PersistentClasher clasher);
|
||||
|
||||
@transactional
|
||||
public void clashNotOk(String key, String msg, PersistentClasher clasher);
|
||||
|
||||
public String getState(String key);
|
||||
|
||||
public void setState(String key, String value);
|
||||
}
|
||||
|
||||
class PersistentStatefulImpl implements PersistentStateful {
|
||||
private TransactionalMap state = new CassandraPersistentTransactionalMap(this);
|
||||
|
||||
public String getState(String key) {
|
||||
return (String)state.get(key).get();
|
||||
}
|
||||
|
||||
public void setState(String key, String msg) {
|
||||
state.put(key, msg);
|
||||
}
|
||||
|
||||
public void success(String key, String msg) {
|
||||
state.put(key, msg);
|
||||
}
|
||||
|
||||
public void failure(String key, String msg, PersistentFailer failer) {
|
||||
state.put(key, msg);
|
||||
failer.fail();
|
||||
}
|
||||
|
||||
public void clashOk(String key, String msg, PersistentClasher clasher) {
|
||||
state.put(key, msg);
|
||||
clasher.clash();
|
||||
}
|
||||
|
||||
public void clashNotOk(String key, String msg, PersistentClasher clasher) {
|
||||
state.put(key, msg);
|
||||
clasher.clash();
|
||||
clasher.clash();
|
||||
}
|
||||
}
|
||||
|
||||
interface PersistentFailer {
|
||||
public void fail();
|
||||
}
|
||||
|
||||
class PersistentFailerImpl implements PersistentFailer {
|
||||
public void fail() {
|
||||
throw new RuntimeException("expected");
|
||||
}
|
||||
}
|
||||
|
||||
interface PersistentClasher {
|
||||
public void clash();
|
||||
|
||||
public String getState(String key);
|
||||
|
||||
public void setState(String key, String value);
|
||||
}
|
||||
|
||||
class PersistentClasherImpl implements PersistentClasher {
|
||||
private TransactionalMap state = new CassandraPersistentTransactionalMap(this);
|
||||
|
||||
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,ErrRef[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,42 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import se.scalablesolutions.akka.kernel.TransactionalMap;
|
||||
import se.scalablesolutions.akka.kernel.CassandraPersistentTransactionalMap;
|
||||
import se.scalablesolutions.akka.annotation.transactional;
|
||||
|
||||
public class PersistentStateful {
|
||||
private TransactionalMap state = new CassandraPersistentTransactionalMap(this);
|
||||
|
||||
public String getState(String key) {
|
||||
return (String)state.get(key).get();
|
||||
}
|
||||
|
||||
public void setState(String key, String msg) {
|
||||
state.put(key, msg);
|
||||
}
|
||||
|
||||
@transactional
|
||||
public void success(String key, String msg) {
|
||||
state.put(key, msg);
|
||||
}
|
||||
|
||||
@transactional
|
||||
public void failure(String key, String msg, PersistentFailer failer) {
|
||||
state.put(key, msg);
|
||||
failer.fail();
|
||||
}
|
||||
|
||||
@transactional
|
||||
public void clashOk(String key, String msg, PersistentClasher clasher) {
|
||||
state.put(key, msg);
|
||||
clasher.clash();
|
||||
}
|
||||
|
||||
@transactional
|
||||
public void clashNotOk(String key, String msg, PersistentClasher clasher) {
|
||||
state.put(key, msg);
|
||||
clasher.clash();
|
||||
clasher.clash();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory;
|
||||
import com.sun.jersey.api.client.Client;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import com.sun.grizzly.http.SelectorThread;
|
||||
|
|
@ -18,7 +17,6 @@ import javax.servlet.Servlet;
|
|||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
|
|
@ -39,9 +37,7 @@ public class RestTest extends TestSuite {
|
|||
new JavaConfig.RestartStrategy(new JavaConfig.AllForOne(), 3, 5000),
|
||||
new JavaConfig.Component[] {
|
||||
new JavaConfig.Component(
|
||||
"jersey-foo",
|
||||
JerseyFoo.class,
|
||||
JerseyFooImpl.class,
|
||||
new JavaConfig.LifeCycle(new JavaConfig.Permanent(), 1000), 10000000)
|
||||
}).inject().supervise();
|
||||
selector = startJersey();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue