Author: david.lloyd(a)jboss.com
Date: 2008-07-03 21:09:27 -0400 (Thu, 03 Jul 2008)
New Revision: 4358
Modified:
remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
Log:
Add a test; fix spurious failure problem
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:58:49 UTC (rev 4357)
+++
remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java 2008-07-04
01:09:27 UTC (rev 4358)
@@ -25,6 +25,7 @@
import junit.framework.TestCase;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.cx.remoting.AbstractRequestListener;
import org.jboss.cx.remoting.RequestContext;
@@ -65,7 +66,7 @@
}
}
- public void testLocalClient() throws Throwable {
+ public void testLocalClientInvoke() throws Throwable {
final AtomicBoolean clientEndpointClosed = new AtomicBoolean(false);
final AtomicBoolean clientClosed = new AtomicBoolean(false);
final EndpointImpl endpoint = new EndpointImpl();
@@ -115,10 +116,71 @@
} finally {
safeStop(endpoint);
}
+ executorService.shutdown();
+ executorService.awaitTermination(1L, TimeUnit.SECONDS);
assertTrue(clientEndpointClosed.get());
assertTrue(clientClosed.get());
} finally {
executorService.shutdownNow();
}
}
+
+ public void testLocalClientSend() 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.send(requestObj).get());
+ clientEndpoint.autoClose();
+ client.close();
+ } finally {
+ IoUtils.safeClose(client);
+ }
+ } finally {
+ IoUtils.safeClose(clientEndpoint);
+ }
+ } finally {
+ safeStop(endpoint);
+ }
+ executorService.shutdown();
+ executorService.awaitTermination(1L, TimeUnit.SECONDS);
+ assertTrue(clientEndpointClosed.get());
+ assertTrue(clientClosed.get());
+ } finally {
+ executorService.shutdownNow();
+ }
+ }
}
Show replies by date