Author: david.lloyd(a)jboss.com
Date: 2008-10-21 01:32:25 -0400 (Tue, 21 Oct 2008)
New Revision: 4605
Added:
remoting3/trunk/protocol/basic/src/test/java/org/
remoting3/trunk/protocol/basic/src/test/java/org/jboss/
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java
Modified:
remoting3/trunk/build.xml
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java
remoting3/trunk/testing-support/src/main/resources/testing.policy
Log:
Add substatial logging, get test working (sort of)
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2008-10-21 04:56:10 UTC (rev 4604)
+++ remoting3/trunk/build.xml 2008-10-21 05:32:25 UTC (rev 4605)
@@ -922,6 +922,7 @@
<path refid="api.classpath"/>
<path refid="core.classpath"/>
<path refid="protocol.basic.classpath"/>
+ <path refid="standalone.classpath"/>
<path refid="util.classpath"/>
<path refid="testing-support.classpath"/>
<pathelement location="${lib.junit.local}"/>
@@ -944,6 +945,7 @@
<sysproperty key="ant.library.dir"
value="${ant.home}/lib"/>
<sysproperty key="lib.junit.local"
value="${lib.junit.local}"/>
<sysproperty key="lib.marshalling-api.local"
value="${lib.marshalling-api.local}"/>
+ <sysproperty key="lib.river.local"
value="${lib.river.local}"/>
<sysproperty key="lib.xnio-api.local"
value="${lib.xnio-api.local}"/>
<sysproperty key="lib.xnio-nio.local"
value="${lib.xnio-nio.local}"/>
<jvmarg line="${test.jvmargs}"/>
@@ -952,6 +954,7 @@
<path refid="api.classpath"/>
<path refid="core.classpath"/>
<path refid="protocol.basic.classpath"/>
+ <path refid="standalone.classpath"/>
<path refid="testing-support.classpath"/>
<path refid="util.classpath"/>
<pathelement
location="protocol/basic/target/test/classes"/>
@@ -970,7 +973,7 @@
</junit>
</target>
- <target name="protocol.basic.test"
depends="lib.xnio-nio,api,core,protocol.basic,testing-support,util,protocol.basic.test.compile">
+ <target name="protocol.basic.test"
depends="lib.river,lib.xnio-nio,api,core,protocol.basic,standalone,testing-support,util,protocol.basic.test.compile">
<antcall inheritall="true" inheritrefs="true"
target="protocol.basic.test.pseudotarget">
<param name="extension" value=".txt"/>
<param name="message" value="Running with no security
manager"/>
Modified:
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java
===================================================================
---
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java 2008-10-21
04:56:10 UTC (rev 4604)
+++
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicHandlerReplyConsumer.java 2008-10-21
05:32:25 UTC (rev 4605)
@@ -29,6 +29,7 @@
import org.jboss.marshalling.Unmarshaller;
import org.jboss.xnio.channels.StreamChannel;
import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
import org.jboss.remoting.spi.remote.ReplyHandler;
import org.jboss.remoting.spi.SpiUtils;
import org.jboss.remoting.RemoteExecutionException;
@@ -40,6 +41,8 @@
*/
final class BasicHandlerReplyConsumer implements Runnable {
+ private static final Logger log = Logger.getLogger(BasicHandlerReplyConsumer.class);
+
private final AtomicInteger replySequence;
private final Unmarshaller unmarshaller;
private final StreamChannel streamChannel;
@@ -124,7 +127,7 @@
}
}
} catch (Exception e) {
- // todo log it
+ log.error(e, "Error receiving reply");
} finally {
IoUtils.safeClose(streamChannel);
reqLock.lock();
Modified:
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java
===================================================================
---
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java 2008-10-21
04:56:10 UTC (rev 4604)
+++
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicRequestHandler.java 2008-10-21
05:32:25 UTC (rev 4605)
@@ -30,6 +30,7 @@
import org.jboss.marshalling.Marshaller;
import org.jboss.xnio.channels.StreamChannel;
import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.Executor;
@@ -41,6 +42,8 @@
*/
final class BasicRequestHandler extends AbstractAutoCloseable<RequestHandler>
implements RequestHandler {
+ private static final Logger log = Logger.getLogger(BasicRequestHandler.class);
+
private final AtomicInteger requestSequence;
private final Lock reqLock;
private final Marshaller marshaller;
@@ -63,7 +66,7 @@
marshaller.writeObject(request);
marshaller.flush();
} catch (IOException e) {
- // todo log it
+ log.error(e, "Error receiving request");
IoUtils.safeClose(this);
} finally {
reqLock.unlock();
@@ -86,7 +89,7 @@
marshaller.writeInt(id);
marshaller.flush();
} catch (IOException e) {
- // todo log it
+ log.error(e, "Error writing cancel request");
IoUtils.safeClose(BasicRequestHandler.this);
}
}
Modified:
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java
===================================================================
---
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java 2008-10-21
04:56:10 UTC (rev 4604)
+++
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerReplyTransmitter.java 2008-10-21
05:32:25 UTC (rev 4605)
@@ -26,6 +26,7 @@
import org.jboss.marshalling.Marshaller;
import org.jboss.xnio.channels.StreamChannel;
import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
import org.jboss.remoting.spi.remote.RequestHandler;
import org.jboss.remoting.spi.remote.Handle;
@@ -34,6 +35,8 @@
*/
final class BasicServerReplyTransmitter implements Runnable {
+ private static final Logger log =
Logger.getLogger(BasicServerReplyTransmitter.class);
+
private final BlockingQueue<FutureBasicReply> replyQueue;
private final Marshaller marshaller;
private final StreamChannel streamChannel;
@@ -49,7 +52,7 @@
public void run() {
try {
for (;;) {
- final FutureBasicReply futureBasicReply = replyQueue.remove();
+ final FutureBasicReply futureBasicReply = replyQueue.take();
OUT: for (;;) switch (futureBasicReply.awaitInterruptibly()) {
case DONE: {
marshaller.write(1);
@@ -77,9 +80,9 @@
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
- // todo log it
+ log.trace(e, "Interrupted");
} catch (Exception e) {
- // todo log it
+ log.error(e, "Error in reply transmitter");
} finally {
IoUtils.safeClose(streamChannel);
IoUtils.safeClose(requestHandlerHandle);
Modified:
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java
===================================================================
---
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java 2008-10-21
04:56:10 UTC (rev 4604)
+++
remoting3/trunk/protocol/basic/src/main/java/org/jboss/remoting/protocol/basic/BasicServerRequestConsumer.java 2008-10-21
05:32:25 UTC (rev 4605)
@@ -29,6 +29,7 @@
import org.jboss.remoting.spi.remote.ReplyHandler;
import org.jboss.xnio.channels.StreamChannel;
import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
import java.util.concurrent.BlockingQueue;
import java.io.IOException;
@@ -37,6 +38,8 @@
*/
final class BasicServerRequestConsumer implements Runnable {
+ private static final Logger log =
Logger.getLogger(BasicServerRequestConsumer.class);
+
private final Unmarshaller unmarshaller;
private final RequestHandler requestHandler;
private final BlockingQueue<FutureBasicReply> replyQueue;
@@ -112,7 +115,7 @@
}
}
} catch (Exception e) {
- // todo log it
+ log.error(e, "Connection failed");
} finally {
IoUtils.safeClose(streamChannel);
IoUtils.safeClose(requestHandlerHandle);
Added:
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java
===================================================================
---
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java
(rev 0)
+++
remoting3/trunk/protocol/basic/src/test/java/org/jboss/remoting/protocol/basic/BasicTestCase.java 2008-10-21
05:32:25 UTC (rev 4605)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.remoting.protocol.basic;
+
+import junit.framework.TestCase;
+import org.jboss.xnio.Xnio;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.IoHandler;
+import org.jboss.xnio.ChannelSource;
+import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.nio.NioXnio;
+import org.jboss.xnio.channels.StreamChannel;
+import org.jboss.river.RiverMarshallerFactory;
+import org.jboss.remoting.Endpoint;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.AbstractRequestListener;
+import org.jboss.remoting.RequestContext;
+import org.jboss.remoting.RemoteExecutionException;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.test.support.LoggingHelper;
+import org.jboss.remoting.spi.remote.RequestHandler;
+import org.jboss.remoting.spi.remote.Handle;
+import org.jboss.marshalling.Configuration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.io.IOException;
+
+/**
+ *
+ */
+public final class BasicTestCase extends TestCase {
+ static {
+ LoggingHelper.init();
+ }
+
+ public static void testConnect() throws Throwable {
+ Executor executor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.SECONDS, new
LinkedBlockingQueue<Runnable>());
+ Xnio xnio = NioXnio.create(executor, 2, 2, 2);
+ final BasicConfiguration configuration = new BasicConfiguration();
+ configuration.setExecutor(executor);
+ configuration.setMarshallerFactory(new RiverMarshallerFactory());
+ final Configuration marshallingConfiguration = new Configuration();
+ configuration.setMarshallingConfiguration(marshallingConfiguration);
+ final Endpoint endpoint = Remoting.createEndpoint("test");
+ final Handle<RequestHandler> requestHandlerHandle =
endpoint.createRequestHandler(new AbstractRequestListener<Object, Object>() {
+ public void handleRequest(final RequestContext<Object> context, final
Object request) throws RemoteExecutionException {
+ System.out.println("Got a request! " + request.toString());
+ try {
+ context.sendReply("GOOMBA");
+ } catch (IOException e) {
+ try {
+ context.sendFailure("Failed", e);
+ } catch (IOException e1) {
+ // buh
+ }
+ }
+ }
+ });
+ final ChannelSource<StreamChannel> channelSource =
xnio.createPipeServer(executor, IoUtils.singletonHandlerFactory(new
IoHandler<StreamChannel>() {
+ public void handleOpened(final StreamChannel channel) {
+ try {
+ System.out.println("Opening channel");
+ BasicProtocol.createServer(requestHandlerHandle, channel,
configuration);
+ } catch (IOException e) {
+ e.printStackTrace();
+ IoUtils.safeClose(channel);
+ }
+ }
+
+ public void handleReadable(final StreamChannel channel) {
+ }
+
+ public void handleWritable(final StreamChannel channel) {
+ }
+
+ public void handleClosed(final StreamChannel channel) {
+ System.out.println("Closing channel");
+ }
+ }));
+ final IoFuture<StreamChannel> futureChannel =
channelSource.open(IoUtils.nullHandler());
+ final Handle<RequestHandler> clientHandlerHandle =
BasicProtocol.createClient(futureChannel.get(), configuration);
+ final Client<Object,Object> client =
endpoint.createClient(clientHandlerHandle.getResource());
+ System.out.println("Reply is:" + client.invoke("GORBA!"));
+
+ }
+}
Modified: remoting3/trunk/testing-support/src/main/resources/testing.policy
===================================================================
--- remoting3/trunk/testing-support/src/main/resources/testing.policy 2008-10-21 04:56:10
UTC (rev 4604)
+++ remoting3/trunk/testing-support/src/main/resources/testing.policy 2008-10-21 05:32:25
UTC (rev 4605)
@@ -17,6 +17,12 @@
permission java.net.SocketPermission "*:*", "accept, connect,
resolve";
};
+grant codeBase "file:${build.home}/protocol/multiplex/target/test/classes/-"
+{
+ permission java.lang.RuntimePermission "modifyThread"; // for executor
control
+ permission java.net.SocketPermission "*:*", "accept, connect,
resolve";
+};
+
// Permissions for Remoting itself
grant codeBase "file:${build.home}/api/target/main/classes/-"
@@ -71,3 +77,8 @@
{
permission java.security.AllPermission;
};
+
+grant codeBase "file:${lib.river.local}"
+{
+ permission java.security.AllPermission;
+};