completed cassandra read/write (and bench) + added transactional vector and ref + cleaned up transactional state hierarchy + rewrote tx state wiring

This commit is contained in:
Jonas Boner 2009-04-27 19:55:57 +02:00
parent e9f7162245
commit 7dec0a747c
60 changed files with 4481 additions and 6283 deletions

View file

@ -103,58 +103,58 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
} catch (RuntimeException e) {
}
}
}
interface Foo {
public String foo(String msg);
@oneway public void bar(String msg);
public void longRunning();
public void throwsException();
public Bar getBar();
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;
}
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");
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) {
}
}
interface Bar {
@oneway void bar(String msg);
Ext getExt();
public void throwsException() {
throw new RuntimeException("expected");
}
}
class BarImpl implements Bar {
@Inject private Ext ext;
public Ext getExt() {
return ext;
}
public void bar(String msg) {
}
interface Bar {
@oneway void bar(String msg);
Ext getExt();
}
class BarImpl implements Bar {
@Inject private Ext ext;
public Ext getExt() {
return ext;
}
interface Ext {
void ext();
public void bar(String msg) {
}
}
class ExtImpl implements Ext {
public void ext() {
}
interface Ext {
void ext();
}
class ExtImpl implements Ext {
public void ext() {
}
}

View file

@ -14,7 +14,6 @@ import com.google.inject.Scopes;
import junit.framework.TestCase;
public class InMemoryStateTest extends TestCase {
static String messageLog = "";
@ -22,57 +21,50 @@ public class InMemoryStateTest extends TestCase {
protected void setUp() {
conf.configureActiveObjects(
new RestartStrategy(new AllForOne(), 3, 5000), new Component[]{
new Component(
Stateful.class,
StatefulImpl.class,
new LifeCycle(new Permanent(), 1000),
10000000),
new Component(
Failer.class,
FailerImpl.class,
new LifeCycle(new Permanent(), 1000),
1000),
new Component(
Clasher.class,
ClasherImpl.class,
new LifeCycle(new Permanent(), 1000),
100000)
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)
}).inject().supervise();
}
// public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
// Stateful stateful = conf.getActiveObject(Stateful.class);
// stateful.setState("stateful", "init"); // set init state
// stateful.success("stateful", "new state"); // transactional
// assertEquals("new state", stateful.getState("stateful"));
// }
//
// public void testShouldRollbackStateForStatefulServerInCaseOfFailure() {
// Stateful stateful = conf.getActiveObject(Stateful.class);
// stateful.setState("stateful", "init"); // set init state
//
// Failer failer = conf.getActiveObject(Failer.class);
// try {
// stateful.failure("stateful", "new state", failer); // call failing transactional method
// fail("should have thrown an exception");
// } catch (RuntimeException e) { } // expected
// assertEquals("init", stateful.getState("stateful")); // check that state is == init state
// }
// public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
// Stateful stateful = conf.getActiveObject(Stateful.class);
// stateful.setState("stateful", "init"); // set init state
// stateful.success("stateful", "new state"); // transactional
// assertEquals("new state", stateful.getState("stateful"));
// }
//
// public void testShouldRollbackStateForStatefulServerInCaseOfFailure() {
// Stateful stateful = conf.getActiveObject(Stateful.class);
// stateful.setState("stateful", "init"); // set init state
//
// Failer failer = conf.getActiveObject(Failer.class);
// try {
// stateful.failure("stateful", "new state", failer); // call failing
// transactional method
// fail("should have thrown an exception");
// } catch (RuntimeException e) { } // expected
// assertEquals("init", stateful.getState("stateful")); // check that state is
// == init state
// }
public void testShouldRollbackStateForStatefulServerInCaseOfMessageClash() {
Stateful stateful = conf.getActiveObject(Stateful.class);
InMemStateful stateful = conf.getActiveObject(InMemStateful.class);
stateful.setState("stateful", "init"); // set init state
Clasher clasher = conf.getActiveObject(Clasher.class);
InMemClasher clasher = conf.getActiveObject(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.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);
@ -80,113 +72,111 @@ public class InMemoryStateTest extends TestCase {
} 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 Stateful {
// transactional
@transactional
public void success(String key, String msg);
@transactional
public void failure(String key, String msg, Failer failer);
@transactional
public void clashOk(String key, String msg, Clasher clasher);
@transactional
public void clashNotOk(String key, String msg, Clasher clasher);
// non-transactional
public String getState(String key);
public void setState(String key, String value);
}
class StatefulImpl implements Stateful {
@state
private
InMemoryState<String, Object> state = new InMemoryState<String, Object>();
public String getState(String key) {
return (String) state.get(key);
}
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, Failer failer) {
state.put(key, msg);
failer.fail();
}
public void clashOk(String key, String msg, Clasher clasher) {
state.put(key, msg);
clasher.clash();
}
public void clashNotOk(String key, String msg, Clasher clasher) {
state.put(key, msg);
clasher.clash();
clasher.clash();
}
}
interface Failer {
public void fail();
}
class FailerImpl implements Failer {
public void fail() {
throw new RuntimeException("expected");
}
}
interface Clasher {
public void clash();
public String getState(String key);
public void setState(String key, String value);
}
class ClasherImpl implements Clasher {
@state
private InMemoryState<String, Object> state = new InMemoryState<String, Object>();
public String getState(String key) {
return (String) state.get(key);
}
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,ErrRef[Right(null)])] to
// [GenericServer[se.scalablesolutions.akka.api.StatefulImpl]] from
// [GenericServer[se.scalablesolutions.akka.api.ClasherImpl]]]
//try { Thread.sleep(1000); } catch (InterruptedException e) {}
}
assertEquals("init", stateful.getState("stateful")); // check that state is
// == init state
// assertEquals("init", clasher.getState("clasher")); // check that state is
// == init state
}
}
interface InMemStateful {
// transactional
@transactional
public void success(String key, String msg);
@transactional
public void failure(String key, String msg, InMemFailer failer);
@transactional
public void clashOk(String key, String msg, InMemClasher clasher);
@transactional
public void clashNotOk(String key, String msg, InMemClasher clasher);
// non-transactional
public String getState(String key);
public void setState(String key, String value);
}
class InMemStatefulImpl implements InMemStateful {
@state
private InMemoryState<String, Object> state = new InMemoryState<String, Object>();
public String getState(String key) {
return (String) state.get(key);
}
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();
clasher.clash();
}
}
interface InMemFailer {
public void fail();
}
class InMemFailerImpl implements InMemFailer {
public void fail() {
throw new RuntimeException("expected");
}
}
interface InMemClasher {
public void clash();
public String getState(String key);
public void setState(String key, String value);
}
class InMemClasherImpl implements InMemClasher {
@state
private InMemoryState<String, Object> state = new InMemoryState<String, Object>();
public String getState(String key) {
return (String) state.get(key);
}
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,ErrRef[Right(null)])]
// to
// [GenericServer[se.scalablesolutions.akka.api.StatefulImpl]] from
// [GenericServer[se.scalablesolutions.akka.api.ClasherImpl]]]
// try { Thread.sleep(1000); } catch (InterruptedException e) {}
}
}

View file

@ -14,7 +14,6 @@ import com.google.inject.Scopes;
import junit.framework.TestCase;
public class PersistentStateTest extends TestCase {
static String messageLog = "";
@ -22,131 +21,121 @@ public class PersistentStateTest extends TestCase {
protected void setUp() {
conf.configureActiveObjects(
new RestartStrategy(new AllForOne(), 3, 5000), new Component[]{
new Component(
Stateful.class,
StatefulImpl.class,
new LifeCycle(new Permanent(), 1000),
10000000),
new Component(
Failer.class,
FailerImpl.class,
new LifeCycle(new Permanent(), 1000),
1000),
new Component(
Clasher.class,
ClasherImpl.class,
new LifeCycle(new Permanent(), 1000),
100000)
new RestartStrategy(new 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)
}).inject().supervise();
}
public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
Stateful stateful = conf.getActiveObject(Stateful.class);
PersistentStateful stateful = conf.getActiveObject(PersistentStateful.class);
stateful.setState("stateful", "init"); // set init state
stateful.success("stateful", "new state"); // transactional
assertEquals("new state", stateful.getState("stateful"));
}
}
interface Stateful {
// transactional
@transactional
public void success(String key, String msg);
interface PersistentStateful {
// transactional
@transactional
public void success(String key, String msg);
@transactional
public void failure(String key, String msg, Failer failer);
@transactional
public void failure(String key, String msg, PersistentFailer failer);
@transactional
public void clashOk(String key, String msg, Clasher clasher);
@transactional
public void clashOk(String key, String msg, PersistentClasher clasher);
@transactional
public void clashNotOk(String key, String msg, Clasher clasher);
@transactional
public void clashNotOk(String key, String msg, PersistentClasher clasher);
// non-transactional
public String getState(String key);
// non-transactional
public String getState(String key);
public void setState(String key, String value);
public void setState(String key, String value);
}
class PersistentStatefulImpl implements PersistentStateful {
@state
private InMemoryState<String, Object> state = new InMemoryState<String, Object>();
public String getState(String key) {
return (String) state.get(key);
}
class StatefulImpl implements Stateful {
@state
private InMemoryState<String, Object> state = new InMemoryState<String, Object>();
public String getState(String key) {
return (String) state.get(key);
}
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, Failer failer) {
state.put(key, msg);
failer.fail();
}
public void clashOk(String key, String msg, Clasher clasher) {
state.put(key, msg);
clasher.clash();
}
public void clashNotOk(String key, String msg, Clasher clasher) {
state.put(key, msg);
clasher.clash();
clasher.clash();
}
public void setState(String key, String msg) {
state.put(key, msg);
}
interface Failer {
public void fail();
public void success(String key, String msg) {
state.put(key, msg);
}
class FailerImpl implements Failer {
public void fail() {
throw new RuntimeException("expected");
}
public void failure(String key, String msg, PersistentFailer failer) {
state.put(key, msg);
failer.fail();
}
interface Clasher {
public void clash();
public String getState(String key);
public void setState(String key, String value);
public void clashOk(String key, String msg, PersistentClasher clasher) {
state.put(key, msg);
clasher.clash();
}
class ClasherImpl implements Clasher {
@state
private InMemoryState<String, Object> state = new InMemoryState<String, Object>();
public void clashNotOk(String key, String msg, PersistentClasher clasher) {
state.put(key, msg);
clasher.clash();
clasher.clash();
}
}
public String getState(String key) {
return (String) state.get(key);
}
interface PersistentFailer {
public void fail();
}
public void setState(String key, String msg) {
state.put(key, msg);
}
class PersistentFailerImpl implements PersistentFailer {
public void fail() {
throw new RuntimeException("expected");
}
}
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;
}
interface PersistentClasher {
public void clash();
public String getState(String key);
public void setState(String key, String value);
}
class PersistentClasherImpl implements PersistentClasher {
@state
private InMemoryState<String, Object> state = new InMemoryState<String, Object>();
public String getState(String key) {
return (String) state.get(key);
}
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,ErrRef[Right(null)])] to
// [GenericServer[se.scalablesolutions.akka.api.StatefulImpl]] from
// [GenericServer[se.scalablesolutions.akka.api.ClasherImpl]]]
//try { Thread.sleep(1000); } catch (InterruptedException e) {}
}
// 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) {}
}
}