avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1095549 - in /avro/branches/branch-1.5: ./ CHANGES.txt lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
Date Wed, 20 Apr 2011 23:09:28 GMT
Author: cutting
Date: Wed Apr 20 23:09:27 2011
New Revision: 1095549

URL: http://svn.apache.org/viewvc?rev=1095549&view=rev
Log:
Merge change 1095548 from trunk to 1.5 branch.  Fixes: AVRO-801.

Modified:
    avro/branches/branch-1.5/   (props changed)
    avro/branches/branch-1.5/CHANGES.txt
    avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
    avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java

Propchange: avro/branches/branch-1.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Apr 20 23:09:27 2011
@@ -1 +1 @@
-/avro/trunk:1075938,1075993,1078917,1079055,1079060,1079063,1083246,1085921,1086727,1086730,1086866,1087076,1087129,1087136,1087439-1087440,1087463,1087472,1087792,1089128,1089131,1089550,1094812,1095206-1095208,1095493,1095529
+/avro/trunk:1075938,1075993,1078917,1079055,1079060,1079063,1083246,1085921,1086727,1086730,1086866,1087076,1087129,1087136,1087439-1087440,1087463,1087472,1087792,1089128,1089131,1089550,1094812,1095206-1095208,1095493,1095529,1095548

Modified: avro/branches/branch-1.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/CHANGES.txt?rev=1095549&r1=1095548&r2=1095549&view=diff
==============================================================================
--- avro/branches/branch-1.5/CHANGES.txt (original)
+++ avro/branches/branch-1.5/CHANGES.txt Wed Apr 20 23:09:27 2011
@@ -59,6 +59,9 @@ Avro 1.5.1 (unreleased)
     AVRO-790. Java: GenericDatumReader can fail when reusing objects with unions
     containing 'bytes' fields. (scottcarey)
 
+    AVRO-810. Java: Fix a bug in SaslSocketTransceiver where large
+    messages were truncated on write. (cutting)
+
 Avro 1.5.0 (10 March 2011)
 
   INCOMPATIBLE CHANGES

Modified: avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java?rev=1095549&r1=1095548&r2=1095549&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
(original)
+++ avro/branches/branch-1.5/lang/java/ipc/src/main/java/org/apache/avro/ipc/SaslSocketTransceiver.java
Wed Apr 20 23:09:27 2011
@@ -256,7 +256,7 @@ public class SaslSocketTransceiver exten
     zeroHeader.flip();                            // zero-terminate
     writes.add(zeroHeader);
 
-    channel.write(writes.toArray(new ByteBuffer[writes.size()]));
+    writeFully(writes.toArray(new ByteBuffer[writes.size()]));
   }
 
   private void write(Status status, String prefix, ByteBuffer response)
@@ -275,7 +275,7 @@ public class SaslSocketTransceiver exten
     ByteBuffer statusBuffer = ByteBuffer.allocate(1);
     statusBuffer.clear();
     statusBuffer.put((byte)(status.ordinal())).flip();
-    channel.write(statusBuffer);
+    writeFully(statusBuffer);
     write(response);
   }
 
@@ -283,7 +283,20 @@ public class SaslSocketTransceiver exten
     LOG.debug("writing: {}", response.remaining());
     writeHeader.clear();
     writeHeader.putInt(response.remaining()).flip();
-    channel.write(new ByteBuffer[] { writeHeader, response });
+    writeFully(writeHeader, response);
+  }
+
+  private void writeFully(ByteBuffer... buffers) throws IOException {
+    int length = buffers.length;
+    int start = 0;
+    do {
+      channel.write(buffers, start, length-start);
+      while (buffers[start].remaining() == 0) {
+        start++;
+        if (start == length)
+          return;
+      }
+    } while (true);
   }
 
   @Override public void close() throws IOException {

Modified: avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java?rev=1095549&r1=1095548&r2=1095549&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
(original)
+++ avro/branches/branch-1.5/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestSaslAnonymous.java
Wed Apr 20 23:09:27 2011
@@ -24,11 +24,14 @@ import java.net.InetSocketAddress;
 
 import org.apache.avro.ipc.generic.GenericRequestor;
 import org.apache.avro.TestProtocolGeneric;
+import org.apache.avro.ipc.reflect.ReflectRequestor;
+import org.apache.avro.ipc.reflect.ReflectResponder;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.junit.Before;
+import org.junit.Test;
 
 public class TestSaslAnonymous extends TestProtocolGeneric {
 
@@ -46,4 +49,27 @@ public class TestSaslAnonymous extends T
 
   @Override public void testHandshake() throws IOException {}
 
+  public interface ProtoInterface {
+    byte[] test(byte[] b);
+  }
+
+  // test big enough to fill socket output buffer
+  @Test
+  public void test64kRequest() throws Exception {
+    SaslSocketServer s = new SaslSocketServer
+      (new ReflectResponder(ProtoInterface.class, new ProtoInterface() {
+        public byte[] test(byte[] b) { return b; }
+      }), new InetSocketAddress(0));
+    s.start();
+    SaslSocketTransceiver client =
+      new SaslSocketTransceiver(new InetSocketAddress(s.getPort()));
+    ProtoInterface proxy =
+      (ProtoInterface)ReflectRequestor.getClient(ProtoInterface.class, client);
+    
+    byte[] result = proxy.test(new byte[64*1024]);
+    
+    client.close();
+    s.close();
+  }
+
 }



Mime
View raw message