mid camel impl

This commit is contained in:
Jonas Boner 2009-05-09 19:55:42 +02:00
parent 46ede93684
commit b1d91818ef
27 changed files with 560 additions and 513 deletions

View file

@ -5,7 +5,13 @@
package se.scalablesolutions.akka.api;
import se.scalablesolutions.akka.annotation.*;
import se.scalablesolutions.akka.kernel.configuration.*;
import se.scalablesolutions.akka.kernel.config.ActiveObjectGuiceConfiguratorForJava;
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 com.google.inject.Inject;
import com.google.inject.AbstractModule;
@ -16,7 +22,7 @@ import junit.framework.TestCase;
public class ActiveObjectGuiceConfiguratorTest extends TestCase {
static String messageLog = "";
final private ActiveObjectGuiceConfigurator conf = new ActiveObjectGuiceConfigurator();
final private ActiveObjectGuiceConfiguratorForJava conf = new ActiveObjectGuiceConfiguratorForJava();
protected void setUp() {
conf.addExternalGuiceModule(new AbstractModule() {
@ -26,11 +32,13 @@ 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),
new Component(
"bar",
Bar.class,
BarImpl.class,
new LifeCycle(new Permanent(), 1000),
@ -41,21 +49,21 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
public void testGuiceActiveObjectInjection() {
messageLog = "";
Foo foo = conf.getActiveObject(Foo.class);
Bar bar = conf.getActiveObject(Bar.class);
Foo foo = conf.getActiveObject("foo");
Bar bar = conf.getActiveObject("bar");
assertTrue(foo.getBar().toString().equals(bar.toString()));
}
public void testGuiceExternalDependencyInjection() {
messageLog = "";
Bar bar = conf.getActiveObject(Bar.class);
Bar bar = conf.getActiveObject("bar");
Ext ext = conf.getExternalDependency(Ext.class);
assertTrue(bar.getExt().toString().equals(ext.toString()));
}
public void testLookupNonSupervisedInstance() {
try {
String str = conf.getActiveObject(String.class);
String str = conf.getActiveObject("string");
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 supervise() method", e.getMessage());
@ -64,7 +72,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
public void testActiveObjectInvocation() throws InterruptedException {
messageLog = "";
Foo foo = conf.getActiveObject(Foo.class);
Foo foo = conf.getActiveObject("foo");
messageLog += foo.foo("foo ");
foo.bar("bar ");
messageLog += "before_bar ";
@ -74,8 +82,8 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
public void testActiveObjectInvocationsInvocation() throws InterruptedException {
messageLog = "";
Foo foo = conf.getActiveObject(Foo.class);
Bar bar = conf.getActiveObject(Bar.class);
Foo foo = conf.getActiveObject("foo");
Bar bar = conf.getActiveObject("bar");
messageLog += foo.foo("foo ");
foo.bar("bar ");
messageLog += "before_bar ";
@ -86,7 +94,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
public void testForcedTimeout() {
messageLog = "";
Foo foo = conf.getActiveObject(Foo.class);
Foo foo = conf.getActiveObject("foo");
try {
foo.longRunning();
fail("exception should have been thrown");
@ -96,7 +104,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
public void testForcedException() {
messageLog = "";
Foo foo = conf.getActiveObject(Foo.class);
Foo foo = conf.getActiveObject("foo");
try {
foo.throwsException();
fail("exception should have been thrown");

View file

@ -5,31 +5,25 @@
package se.scalablesolutions.akka.api;
import se.scalablesolutions.akka.annotation.*;
import se.scalablesolutions.akka.kernel.*;
import se.scalablesolutions.akka.kernel.configuration.LifeCycle;
import se.scalablesolutions.akka.kernel.configuration.Permanent;
import se.scalablesolutions.akka.kernel.configuration.Component;
import se.scalablesolutions.akka.kernel.configuration.AllForOne;
import se.scalablesolutions.akka.kernel.configuration.RestartStrategy;
import com.google.inject.Inject;
import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
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 junit.framework.TestCase;
public class InMemoryStateTest extends TestCase {
static String messageLog = "";
final private ActiveObjectGuiceConfigurator conf = new ActiveObjectGuiceConfigurator();
final private ActiveObjectGuiceConfiguratorForJava conf = new ActiveObjectGuiceConfiguratorForJava();
protected void setUp() {
conf.configureActiveObjects(
new RestartStrategy(new AllForOne(), 3, 5000),
new Component[] {
new Component(InMemStateful.class, InMemStatefulImpl.class, new LifeCycle(new Permanent(), 1000), 10000000),
new Component(InMemFailer.class, InMemFailerImpl.class, new LifeCycle(new Permanent(), 1000), 1000),
new Component(InMemClasher.class, InMemClasherImpl.class, new LifeCycle(new Permanent(), 1000), 100000)
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("inmem-clasher", InMemClasher.class, InMemClasherImpl.class, new LifeCycle(new Permanent(), 1000), 100000)
}).inject().supervise();
}
@ -39,17 +33,17 @@ public class InMemoryStateTest extends TestCase {
public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
InMemStateful stateful = conf.getActiveObject(InMemStateful.class);
InMemStateful stateful = conf.getActiveObject("inmem-stateful");
stateful.setState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional
assertEquals("new state", stateful.getState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess"));
}
public void testShouldRollbackStateForStatefulServerInCaseOfFailure() {
InMemStateful stateful = conf.getActiveObject(InMemStateful.class);
InMemStateful stateful = conf.getActiveObject("inmem-stateful");
stateful.setState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
InMemFailer failer = conf.getActiveObject(InMemFailer.class);
InMemFailer failer = conf.getActiveObject("inmem-failer");
try {
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method
fail("should have thrown an exception");

View file

@ -5,31 +5,25 @@
package se.scalablesolutions.akka.api;
import se.scalablesolutions.akka.annotation.*;
import se.scalablesolutions.akka.kernel.*;
import se.scalablesolutions.akka.kernel.configuration.LifeCycle;
import se.scalablesolutions.akka.kernel.configuration.Permanent;
import se.scalablesolutions.akka.kernel.configuration.Component;
import se.scalablesolutions.akka.kernel.configuration.AllForOne;
import se.scalablesolutions.akka.kernel.configuration.RestartStrategy;
import com.google.inject.Inject;
import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
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.CassandraPersistentTransactionalMap;
import junit.framework.TestCase;
public class PersistentStateTest extends TestCase {
static String messageLog = "";
final private ActiveObjectGuiceConfigurator conf = new ActiveObjectGuiceConfigurator();
final private ActiveObjectGuiceConfiguratorForJava conf = new ActiveObjectGuiceConfiguratorForJava();
protected void setUp() {
conf.configureActiveObjects(
new RestartStrategy(new AllForOne(), 3, 5000),
new JavaConfig.RestartStrategy(new JavaConfig.AllForOne(), 3, 5000),
new Component[] {
new Component(PersistentStateful.class, PersistentStatefulImpl.class, new LifeCycle(new Permanent(), 1000), 10000000),
new Component(PersistentFailer.class, PersistentFailerImpl.class, new LifeCycle(new Permanent(), 1000), 1000),
new Component(PersistentClasher.class, PersistentClasherImpl.class, new LifeCycle(new Permanent(), 1000), 100000)
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)
}).inject().supervise();
}
@ -63,10 +57,10 @@ interface PersistentStateful {
}
class PersistentStatefulImpl implements PersistentStateful {
private TransactionalMap<String, String> state = new CassandraPersistentTransactionalMap(this);
private TransactionalMap state = new CassandraPersistentTransactionalMap(this);
public String getState(String key) {
return state.get(key);
return (String)state.get(key);
}
public void setState(String key, String msg) {
@ -113,10 +107,10 @@ interface PersistentClasher {
}
class PersistentClasherImpl implements PersistentClasher {
private TransactionalMap<String, String> state = new CassandraPersistentTransactionalMap(this);
private TransactionalMap state = new CassandraPersistentTransactionalMap(this);
public String getState(String key) {
return state.get(key);
return (String)state.get(key);
}
public void setState(String key, String msg) {