Author: trustin
Date: Sat Oct 30 21:51:03 2004
New Revision: 56119
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/ProtocolTestCase.java
incubator/directory/seda/trunk/src/test/org/apache/seda/examples/EchoProtocolProviderTest.java
Log:
* Added ProtocolTestCase.assertEquals(byte[], byte[]); EchoProtocolProviderTest
uses it.
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/ProtocolTestCase.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/ProtocolTestCase.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/ProtocolTestCase.java
Sat Oct 30 21:51:03 2004
@@ -18,16 +18,20 @@
package org.apache.seda;
import java.net.InetAddress;
+import java.nio.ByteBuffer;
+import junit.framework.TestCase;
+
+import org.apache.seda.input.InputManagerMonitorAdapter;
+import org.apache.seda.input.TCPInputManager;
import org.apache.seda.listener.AvailablePortFinder;
+import org.apache.seda.listener.ClientKey;
import org.apache.seda.listener.ListenerConfig;
import org.apache.seda.listener.TCPListenerConfig;
import org.apache.seda.protocol.DefaultInetServicesDatabase;
import org.apache.seda.protocol.InetServiceEntry;
import org.apache.seda.protocol.ProtocolProvider;
-import junit.framework.TestCase;
-
/**
* A test harness using the standalone default frontend hardwired using the
@@ -86,5 +90,25 @@
config = new TCPListenerConfig(InetAddress.getLocalHost(), srvEntry);
fe.getListenerManager().bind(config);
fe.register(proto);
+
+ ((TCPInputManager) fe.getInputManager()).setMonitor(new
InputManagerMonitorAdapter() {
+ public void inputRecieved(ByteBuffer buffer, ClientKey key)
+ {
+ System.out.println("READ");
+ }
+ });
+ }
+
+ public static void assertEquals(byte[] expected, byte[] actual) {
+ assertEquals(toString(expected), toString(actual));
+ }
+
+ private static String toString(byte[] buf) {
+ StringBuffer str = new StringBuffer(buf.length * 4);
+ for (int i = 0; i < buf.length; i++) {
+ str.append((int) buf[i]);
+ str.append(' ');
+ }
+ return str.toString();
}
}
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/examples/EchoProtocolProviderTest.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/examples/EchoProtocolProviderTest.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/examples/EchoProtocolProviderTest.java
Sat Oct 30 21:51:03 2004
@@ -18,7 +18,7 @@
package org.apache.seda.examples;
import java.net.InetAddress;
-import java.util.Arrays;
+import java.net.SocketTimeoutException;
import org.apache.commons.net.EchoTCPClient;
import org.apache.seda.ProtocolTestCase;
@@ -42,7 +42,6 @@
{
EchoTCPClient client = new EchoTCPClient();
client.connect(InetAddress.getLocalHost(), port);
- client.setSoTimeout(3000);
byte[] writeBuf = new byte[512];
byte[] readBuf = new byte[writeBuf.length];
@@ -52,6 +51,7 @@
writeBuf[j] = (byte) j;
}
+ client.setSoTimeout(3000);
client.getOutputStream().write(writeBuf);
int readBytes = 0;
@@ -62,7 +62,14 @@
readBytes += nBytes;
}
- assertTrue(Arrays.equals(writeBuf, readBuf));
+ assertEquals(writeBuf, readBuf);
+
+ client.setSoTimeout(100);
+ try {
+ client.getInputStream().read();
+ fail("Unexpected incoming data.");
+ } catch (SocketTimeoutException e) {
+ }
}
client.disconnect();