directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: rev 56130 - incubator/directory/seda/trunk/src/test/org/apache/seda/examples
Date Sun, 31 Oct 2004 07:56:01 GMT
Author: trustin
Date: Sun Oct 31 00:56:01 2004
New Revision: 56130

Modified:
   incubator/directory/seda/trunk/src/test/org/apache/seda/examples/EchoProtocolProviderTest.java
Log:
extracted write buffer generation method.

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
Sun Oct 31 00:56:01 2004
@@ -42,41 +42,59 @@
     {
         EchoTCPClient client = new EchoTCPClient();
         client.connect(InetAddress.getLocalHost(), port);
-        
+
         byte[] writeBuf = new byte[16];
-        for (int i = 0; i < 10; i++) {
-        	for (int j = writeBuf.length-1; j >= 0; j--) {
-        		writeBuf[j] = (byte) (j + i);
-        	}
-        	
-    		client.getOutputStream().write(writeBuf);
+
+        for (int i = 0; i < 10; i++)
+        {
+            fillWriteBuffer(writeBuf, i);
+            client.getOutputStream().write(writeBuf);
         }
-        
-    	byte[] readBuf = new byte[writeBuf.length];
-        for (int i = 0; i < 10; i++) {
-        	for (int j = writeBuf.length-1; j >= 0; j--) {
-        		writeBuf[j] = (byte) (j + i);
-        	}
-
-        	int readBytes = 0;
-    		while (readBytes < readBuf.length) {
-        		int nBytes = client.getInputStream().read(readBuf, readBytes, readBuf.length -
readBytes);
-        		if (nBytes < 0)
-        			fail("Unexpected disconnection.");
-        		readBytes += nBytes;
-    		}
-    		
-    		assertEquals(writeBuf, readBuf);
-    		
+
+        byte[] readBuf = new byte[writeBuf.length];
+
+        for (int i = 0; i < 10; i++)
+        {
+            fillWriteBuffer(writeBuf, i);
+
+            int readBytes = 0;
+            while (readBytes < readBuf.length)
+            {
+                int nBytes =
+                    client.getInputStream().read(readBuf, readBytes,
+                                                 readBuf.length - readBytes);
+
+                if (nBytes < 0)
+                    fail("Unexpected disconnection.");
+
+                readBytes += nBytes;
+            }
+
+            assertEquals(writeBuf, readBuf);
         }
-        
-		client.setSoTimeout(100);
-		try {
-			client.getInputStream().read();
-			fail("Unexpected incoming data.");
-		} catch (SocketTimeoutException e) {
-		}
 
-		client.disconnect();
+        client.setSoTimeout(100);
+
+        try
+        {
+            client.getInputStream().read();
+            fail("Unexpected incoming data.");
+        }
+        catch (SocketTimeoutException e)
+        {
+        }
+
+        client.disconnect();
     }
+
+	/**
+	 * @param writeBuf
+	 * @param i
+	 */
+	private void fillWriteBuffer(byte[] writeBuf, int i) {
+		for (int j = writeBuf.length - 1; j >= 0; j--)
+		{
+		    writeBuf[j] = (byte) (j + i);
+		}
+	}
 }

Mime
View raw message