Added tests to Spring module, currently failing
This commit is contained in:
parent
21001a7e10
commit
aef5201386
4 changed files with 103 additions and 25 deletions
|
|
@ -47,13 +47,15 @@ public class AkkaSpringInterceptor extends ActiveObjectAspect implements MethodI
|
|||
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
||||
Dispatcher dispatcher = new Dispatcher(isTransactional());
|
||||
dispatcher.start();
|
||||
AspectInitRegistry.register(methodInvocation.getThis(), new AspectInit(
|
||||
methodInvocation.getThis().getClass(),
|
||||
dispatcher,
|
||||
TIME_OUT));
|
||||
Object result = this.invoke(AkkaSpringJoinPointWrapper.createSpringAkkaAspectWerkzWrapper(methodInvocation));
|
||||
dispatcher.stop();
|
||||
return result;
|
||||
try {
|
||||
AspectInitRegistry.register(methodInvocation.getThis(), new AspectInit(
|
||||
methodInvocation.getThis().getClass(),
|
||||
dispatcher,
|
||||
TIME_OUT));
|
||||
return this.invoke(AkkaSpringJoinPointWrapper.createSpringAkkaAspectWerkzWrapper(methodInvocation));
|
||||
} finally {
|
||||
dispatcher.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -17,10 +17,28 @@ public class AkkaSpringInterceptorTest extends TestCase {
|
|||
return new TestSuite(AkkaSpringInterceptorTest.class);
|
||||
}
|
||||
|
||||
public void testInvokingAkkaEnabledSpringBean() {
|
||||
public void testInvokingAkkaEnabledSpringBeanMethodWithReturnValue() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("spring-test-config.xml");
|
||||
MyService myService = (MyService) context.getBean("actorBeanService");
|
||||
Object obj = myService.getNumbers(12, "vfsh");
|
||||
Object obj = myService.getNumbers(12);
|
||||
assertEquals(new Integer(12), obj);
|
||||
}
|
||||
|
||||
public void testThatAkkaEnabledSpringBeanMethodCallIsInvokedInADifferentThreadThanTheTest() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("spring-test-config.xml");
|
||||
MyService myService = (MyService) context.getBean("actorBeanService");
|
||||
assertNotSame(Thread.currentThread().getName(), myService.getThreadName());
|
||||
}
|
||||
|
||||
public void testInvokingAkkaEnabledSpringBeanMethodWithTransactionalMethod() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("spring-test-config.xml");
|
||||
MyService myService = (MyService) context.getBean("actorBeanService");
|
||||
myService.init();
|
||||
myService.setMapState("key", "value");
|
||||
myService.setRefState("value");
|
||||
myService.setVectorState("value");
|
||||
assertEquals("value", myService.getMapState("key"));
|
||||
assertEquals("value", myService.getRefState());
|
||||
assertEquals("value", myService.getVectorState());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,78 @@ package se.scalablesolutions.akka.spring;
|
|||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
//import se.scalablesolutions.akka.annotation.oneway;
|
||||
import se.scalablesolutions.akka.state.TransactionalState;
|
||||
import se.scalablesolutions.akka.state.TransactionalRef;
|
||||
import se.scalablesolutions.akka.state.TransactionalVector;
|
||||
import se.scalablesolutions.akka.state.TransactionalMap;
|
||||
|
||||
import se.scalablesolutions.akka.annotation.oneway;
|
||||
import se.scalablesolutions.akka.annotation.prerestart;
|
||||
import se.scalablesolutions.akka.annotation.postrestart;
|
||||
|
||||
public class MyService {
|
||||
|
||||
public Integer getNumbers(int aTestNumber, String aText) {
|
||||
return new Integer(aTestNumber);
|
||||
private TransactionalMap<String, String> mapState;
|
||||
private TransactionalVector<String> vectorState;
|
||||
private TransactionalRef<String> refState;
|
||||
private boolean isInitialized = false;
|
||||
|
||||
@Transactional
|
||||
public void init() {
|
||||
if (!isInitialized) {
|
||||
mapState = TransactionalState.newMap();
|
||||
vectorState = TransactionalState.newVector();
|
||||
refState = TransactionalState.newRef();
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
//@oneway
|
||||
public void calculate() {
|
||||
for (int i = 1; i < 10000; i++) {
|
||||
System.out.println("i=" + i);
|
||||
}
|
||||
public String getThreadName() {
|
||||
return Thread.currentThread().getName();
|
||||
}
|
||||
|
||||
public Integer getNumbers(int aTestNumber) {
|
||||
return new Integer(aTestNumber);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String getMapState(String key) {
|
||||
return (String)mapState.get(key).get();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String getVectorState() {
|
||||
return (String)vectorState.last();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String getRefState() {
|
||||
return (String)refState.get().get();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setMapState(String key, String msg) {
|
||||
mapState.put(key, msg);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setVectorState(String msg) {
|
||||
vectorState.add(msg);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void setRefState(String msg) {
|
||||
refState.swap(msg);
|
||||
}
|
||||
|
||||
@prerestart
|
||||
public void preRestart() {
|
||||
System.out.println("################ PRE RESTART");
|
||||
}
|
||||
|
||||
@postrestart
|
||||
public void postRestart() {
|
||||
System.out.println("################ POST RESTART");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue