mid jax-rs impl
This commit is contained in:
parent
8c8ba29afc
commit
b38ac067cb
17 changed files with 512 additions and 558 deletions
|
|
@ -49,21 +49,21 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
|||
|
||||
public void testGuiceActiveObjectInjection() {
|
||||
messageLog = "";
|
||||
Foo foo = conf.getActiveObject("foo");
|
||||
Bar bar = conf.getActiveObject("bar");
|
||||
Foo foo = conf.getActiveObject(Foo.class);
|
||||
Bar bar = conf.getActiveObject(Bar.class);
|
||||
assertTrue(foo.getBar().toString().equals(bar.toString()));
|
||||
}
|
||||
|
||||
public void testGuiceExternalDependencyInjection() {
|
||||
messageLog = "";
|
||||
Bar bar = conf.getActiveObject("bar");
|
||||
Bar bar = conf.getActiveObject(Bar.class);
|
||||
Ext ext = conf.getExternalDependency(Ext.class);
|
||||
assertTrue(bar.getExt().toString().equals(ext.toString()));
|
||||
}
|
||||
|
||||
public void testLookupNonSupervisedInstance() {
|
||||
try {
|
||||
String str = conf.getActiveObject("string");
|
||||
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());
|
||||
|
|
@ -72,7 +72,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
|||
|
||||
public void testActiveObjectInvocation() throws InterruptedException {
|
||||
messageLog = "";
|
||||
Foo foo = conf.getActiveObject("foo");
|
||||
Foo foo = conf.getActiveObject(Foo.class);
|
||||
messageLog += foo.foo("foo ");
|
||||
foo.bar("bar ");
|
||||
messageLog += "before_bar ";
|
||||
|
|
@ -82,8 +82,8 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
|||
|
||||
public void testActiveObjectInvocationsInvocation() throws InterruptedException {
|
||||
messageLog = "";
|
||||
Foo foo = conf.getActiveObject("foo");
|
||||
Bar bar = conf.getActiveObject("bar");
|
||||
Foo foo = conf.getActiveObject(Foo.class);
|
||||
Bar bar = conf.getActiveObject(Bar.class);
|
||||
messageLog += foo.foo("foo ");
|
||||
foo.bar("bar ");
|
||||
messageLog += "before_bar ";
|
||||
|
|
@ -94,7 +94,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
|||
|
||||
public void testForcedTimeout() {
|
||||
messageLog = "";
|
||||
Foo foo = conf.getActiveObject("foo");
|
||||
Foo foo = conf.getActiveObject(Foo.class);
|
||||
try {
|
||||
foo.longRunning();
|
||||
fail("exception should have been thrown");
|
||||
|
|
@ -104,7 +104,7 @@ public class ActiveObjectGuiceConfiguratorTest extends TestCase {
|
|||
|
||||
public void testForcedException() {
|
||||
messageLog = "";
|
||||
Foo foo = conf.getActiveObject("foo");
|
||||
Foo foo = conf.getActiveObject(Foo.class);
|
||||
try {
|
||||
foo.throwsException();
|
||||
fail("exception should have been thrown");
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public class InMemoryStateTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
InMemStateful stateful = conf.getActiveObject("inmem-stateful");
|
||||
InMemStateful stateful = conf.getActiveObject(InMemStateful.class);
|
||||
stateful.setState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit
|
||||
|
|
@ -40,9 +40,9 @@ public class InMemoryStateTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
InMemStateful stateful = conf.getActiveObject("inmem-stateful");
|
||||
InMemStateful stateful = conf.getActiveObject(InMemStateful.class);
|
||||
stateful.setState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
InMemFailer failer = conf.getActiveObject("inmem-failer");
|
||||
InMemFailer failer = conf.getActiveObject(InMemFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method
|
||||
fail("should have thrown an exception");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
package se.scalablesolutions.akka.api;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
@Path("/foo")
|
||||
public interface JerseyFoo {
|
||||
@GET
|
||||
@Produces({"application/json"})
|
||||
public String foo();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
@Path("/foo")
|
||||
//@Path("/foo")
|
||||
public class JerseyFooImpl implements JerseyFoo {
|
||||
@GET
|
||||
@Produces({"application/json"})
|
||||
//@GET
|
||||
//@Produces({"application/json"})
|
||||
public String foo() {
|
||||
return "hello foo";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class PersistentStateTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testShouldNotRollbackStateForStatefulServerInCaseOfSuccess() {
|
||||
PersistentStateful stateful = conf.getActiveObject("persistent-stateful");
|
||||
PersistentStateful stateful = conf.getActiveObject(PersistentStateful.class);
|
||||
stateful.setState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init"); // set init state
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // transactional
|
||||
stateful.success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state"); // to trigger commit
|
||||
|
|
@ -50,9 +50,9 @@ public class PersistentStateTest extends TestCase {
|
|||
}
|
||||
|
||||
public void testShouldRollbackStateForStatefulServerInCaseOfFailure() {
|
||||
PersistentStateful stateful = conf.getActiveObject("persistent-stateful");
|
||||
PersistentStateful stateful = conf.getActiveObject(PersistentStateful.class);
|
||||
stateful.setState("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init"); // set init state
|
||||
PersistentFailer failer = conf.getActiveObject("persistent-failer");
|
||||
PersistentFailer failer = conf.getActiveObject(PersistentFailer.class);
|
||||
try {
|
||||
stateful.failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer); // call failing transactional method
|
||||
fail("should have thrown an exception");
|
||||
|
|
|
|||
|
|
@ -8,8 +8,12 @@ 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;
|
||||
import com.sun.grizzly.http.servlet.ServletAdapter;
|
||||
import com.sun.grizzly.tcp.Adapter;
|
||||
import com.sun.grizzly.standalone.StaticStreamAlgorithm;
|
||||
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.servlet.Servlet;
|
||||
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -19,19 +23,33 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import se.scalablesolutions.akka.kernel.config.ActiveObjectGuiceConfiguratorForJava;
|
||||
import se.scalablesolutions.akka.kernel.config.JavaConfig;
|
||||
|
||||
public class RestTest extends TestSuite {
|
||||
|
||||
private static URI URI = UriBuilder.fromUri("http://localhost/").port(9998).build();
|
||||
private static int PORT = 9998;
|
||||
private static URI URI = UriBuilder.fromUri("http://localhost/").port(PORT).build();
|
||||
private static SelectorThread selector = null;
|
||||
private static ActiveObjectGuiceConfiguratorForJava conf = new ActiveObjectGuiceConfiguratorForJava();
|
||||
|
||||
@BeforeClass
|
||||
public static void initialize() throws IOException {
|
||||
conf.configureActiveObjects(
|
||||
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();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() throws IOException {
|
||||
conf.stop();
|
||||
selector.stopEndpoint();
|
||||
System.exit(0);
|
||||
}
|
||||
|
|
@ -46,10 +64,27 @@ public class RestTest extends TestSuite {
|
|||
selector.stopEndpoint();
|
||||
}
|
||||
|
||||
private static SelectorThread startJersey() throws IOException {
|
||||
Map initParams = new java.util.HashMap<String, String>();
|
||||
initParams.put("com.sun.jersey.config.property.packages", "se.scalablesolutions.akka.api");
|
||||
//return GrizzlyWebContainerFactory.create(URI, initParams);
|
||||
return GrizzlyWebContainerFactory.create(URI, se.scalablesolutions.akka.kernel.jersey.AkkaServlet.class);
|
||||
private static SelectorThread startJersey() {
|
||||
try {
|
||||
ServletAdapter adapter = new ServletAdapter();
|
||||
Servlet servlet = se.scalablesolutions.akka.kernel.jersey.AkkaServlet.class.newInstance();
|
||||
adapter.setServletInstance(servlet);
|
||||
adapter.setContextPath(URI.getPath());
|
||||
return createGrizzlySelector(adapter, URI, PORT);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static SelectorThread createGrizzlySelector(Adapter adapter, URI uri, int port) throws IOException, InstantiationException {
|
||||
final String scheme = uri.getScheme();
|
||||
if (!scheme.equalsIgnoreCase("http"))
|
||||
throw new IllegalArgumentException("The URI scheme, of the URI " + uri + ", must be equal (ignoring case) to 'http'");
|
||||
final SelectorThread selectorThread = new SelectorThread();
|
||||
selectorThread.setAlgorithmClassName(StaticStreamAlgorithm.class.getName());
|
||||
selectorThread.setPort(port);
|
||||
selectorThread.setAdapter(adapter);
|
||||
selectorThread.listen();
|
||||
return selectorThread;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue