first draft of MVCC using Clojure's Map as state holder, still one test failing though

This commit is contained in:
Jonas Boner 2009-04-04 21:34:10 +02:00
parent a453930503
commit 3e703a53ab
9 changed files with 212 additions and 92 deletions

View file

@ -12,6 +12,7 @@ import se.scalablesolutions.akka.kernel.ActiveObjectFactory;
import se.scalablesolutions.akka.kernel.ActiveObjectProxy;
import se.scalablesolutions.akka.kernel.Supervisor;
import se.scalablesolutions.akka.kernel.Worker;
import se.scalablesolutions.akka.kernel.TransientStringState;
import java.util.List;
import java.util.ArrayList;
@ -55,6 +56,7 @@ public class ActiveObjectGuiceConfigurator {
this.components = components;
modules.add(new AbstractModule() {
protected void configure() {
bind(TransientStringState.class);
bind(ResourceProviderFactory.class);
for (int i = 0; i < components.length; i++) {
Component c = components[i];

View file

@ -4,8 +4,9 @@
package se.scalablesolutions.akka.api;
import se.scalablesolutions.akka.annotation.oneway;
import se.scalablesolutions.akka.annotation.*;
import se.scalablesolutions.akka.kernel.configuration.*;
import se.scalablesolutions.akka.kernel.TransientObjectState;
import com.google.inject.Inject;
import com.google.inject.AbstractModule;
@ -34,6 +35,16 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
Bar.class,
BarImpl.class,
new LifeCycle(new Permanent(), 100),
1000),
new Component(
Stateful.class,
StatefulImpl.class,
new LifeCycle(new Permanent(), 100),
1000),
new Component(
Failer.class,
FailerImpl.class,
new LifeCycle(new Permanent(), 100),
1000)
}).inject().supervise();
@ -93,6 +104,19 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
} catch (RuntimeException e) {
}
}
public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
Stateful stateful = conf.getActiveObject(Stateful.class);
stateful.success("test", "new state");
assertEquals("new state", stateful.getState("test"));
}
public void testShouldRollbackStateForStatefulServerInCaseOfFailure() {
Stateful stateful = conf.getActiveObject(Stateful.class);
Failer failer = conf.getActiveObject(Failer.class);
stateful.failure("test", "new state", failer);
assertEquals("nil", stateful.getState("test"));
}
}
// ============== TEST SERVICES ===============
@ -166,4 +190,35 @@ class ExtImpl implements Ext {
}
}
interface Stateful {
@transactional public void success(String key, String msg);
@transactional public void failure(String key, String msg, Failer failer);
public String getState(String key);
}
@stateful // TODO: make it possible to add @stateful to interface not impl class
class StatefulImpl implements Stateful {
@Inject private TransientObjectState state;
public String getState(String key) {
return (String)state.get(key);
}
public void success(String key, String msg) {
state.put(key, msg);
}
public void failure(String key, String msg, Failer failer) {
state.put(key, msg);
failer.fail();
}
}
interface Failer {
public void fail();
}
class FailerImpl implements Failer {
public void fail() {
throw new RuntimeException("expected");
}
}