[jboss-remoting-commits] JBoss Remoting SVN: r4355 - remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core.
jboss-remoting-commits at lists.jboss.org
jboss-remoting-commits at lists.jboss.org
Thu Jul 3 20:50:45 EDT 2008
Author: david.lloyd at jboss.com
Date: 2008-07-03 20:50:45 -0400 (Thu, 03 Jul 2008)
New Revision: 4355
Modified:
remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
Log:
Framework for core tests
Modified: remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
===================================================================
--- remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java 2008-07-04 00:30:16 UTC (rev 4354)
+++ remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java 2008-07-04 00:50:45 UTC (rev 4355)
@@ -25,17 +25,94 @@
import junit.framework.TestCase;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.jboss.cx.remoting.AbstractRequestListener;
+import org.jboss.cx.remoting.RequestContext;
+import org.jboss.cx.remoting.RemoteExecutionException;
+import org.jboss.cx.remoting.CloseHandler;
+import org.jboss.cx.remoting.Client;
+import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
+import org.jboss.xnio.IoUtils;
/**
*
*/
public final class EndpointTestCase extends TestCase {
- public void testCreate() {
+ private static void safeStop(EndpointImpl endpoint) {
+ try {
+ endpoint.stop();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ public void testCreate() throws Throwable {
final EndpointImpl endpoint = new EndpointImpl();
final ExecutorService executorService = Executors.newCachedThreadPool();
- endpoint.setExecutor(executorService);
- endpoint.start();
- endpoint.stop();
- executorService.shutdown();
+ try {
+ endpoint.setExecutor(executorService);
+ endpoint.start();
+ endpoint.stop();
+ executorService.shutdown();
+ } finally {
+ executorService.shutdownNow();
+ }
}
+
+ public void testLocalClient() throws Throwable {
+ final AtomicBoolean clientEndpointClosed = new AtomicBoolean(false);
+ final AtomicBoolean clientClosed = new AtomicBoolean(false);
+ final EndpointImpl endpoint = new EndpointImpl();
+ final ExecutorService executorService = Executors.newCachedThreadPool();
+ final Object requestObj = new Object();
+ final Object replyObj = new Object();
+ try {
+ endpoint.setExecutor(executorService);
+ endpoint.start();
+ try {
+ final RemoteClientEndpoint<Object,Object> clientEndpoint = endpoint.createClient(new AbstractRequestListener<Object, Object>() {
+ public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
+ assertEquals(request, requestObj);
+ try {
+ context.sendReply(replyObj);
+ } catch (RemotingException e) {
+ try {
+ context.sendFailure(e.getMessage(), e);
+ } catch (RemotingException e1) {
+ fail("double fault");
+ }
+ }
+ }
+ });
+ try {
+ clientEndpoint.addCloseHandler(new CloseHandler<RemoteClientEndpoint<Object, Object>>() {
+ public void handleClose(final RemoteClientEndpoint<Object, Object> closed) {
+ clientEndpointClosed.set(true);
+ }
+ });
+ final Client<Object,Object> client = clientEndpoint.getClient();
+ try {
+ client.addCloseHandler(new CloseHandler<Client<Object, Object>>() {
+ public void handleClose(final Client<Object, Object> closed) {
+ clientClosed.set(true);
+ }
+ });
+ assertEquals(replyObj, client.invoke(requestObj));
+ client.close();
+ } finally {
+ IoUtils.safeClose(client);
+ }
+ } finally {
+ IoUtils.safeClose(clientEndpoint);
+ }
+ } finally {
+ safeStop(endpoint);
+ }
+ assertTrue(clientEndpointClosed.get());
+ assertTrue(clientClosed.get());
+ } finally {
+ executorService.shutdownNow();
+ }
+ }
}
More information about the jboss-remoting-commits
mailing list