hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cnaur...@apache.org
Subject git commit: HADOOP-11165. TestUTF8 fails when run against java 8. Contributed by Stephen Chu.
Date Tue, 04 Nov 2014 18:29:19 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 3dfd6e68f -> 85da71c2d


HADOOP-11165. TestUTF8 fails when run against java 8. Contributed by Stephen Chu.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/85da71c2
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/85da71c2
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/85da71c2

Branch: refs/heads/trunk
Commit: 85da71c2d3c565a8920e47fe3925e8e0bef353a5
Parents: 3dfd6e6
Author: cnauroth <cnauroth@apache.org>
Authored: Tue Nov 4 10:27:41 2014 -0800
Committer: cnauroth <cnauroth@apache.org>
Committed: Tue Nov 4 10:27:41 2014 -0800

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt |  3 +++
 .../java/org/apache/hadoop/io/TestUTF8.java     | 23 ++++++++++++++------
 2 files changed, 19 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/85da71c2/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index eb91dcb..1d6adc3 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -383,6 +383,9 @@ Release 2.7.0 - UNRELEASED
     HADOOP-11186. documentation should talk about
     hadoop.htrace.spanreceiver.classes, not hadoop.trace.spanreceiver.classes (cmccabe)
 
+    HADOOP-11165. TestUTF8 fails when run against java 8.
+    (Stephen Chu via cnauroth)
+
 Release 2.6.0 - UNRELEASED
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/85da71c2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestUTF8.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestUTF8.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestUTF8.java
index b387224..ede5940 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestUTF8.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestUTF8.java
@@ -19,8 +19,11 @@
 package org.apache.hadoop.io;
 
 import junit.framework.TestCase;
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
 import java.io.IOException;
 import java.io.UTFDataFormatException;
+import java.nio.ByteBuffer;
 import java.util.Random;
 
 import org.apache.hadoop.test.GenericTestUtils;
@@ -54,11 +57,22 @@ public class TestUTF8 extends TestCase {
       // generate a random string
       String before = getTestString();
 
-      // check its utf8
-      assertEquals(before, new String(UTF8.getBytes(before), "UTF-8"));
+      // Check that the bytes are stored correctly in Modified-UTF8 format.
+      // Note that the DataInput and DataOutput interfaces convert between
+      // bytes and Strings using the Modified-UTF8 format.
+      assertEquals(before, readModifiedUTF(UTF8.getBytes(before)));
     }
   }
 
+  private String readModifiedUTF(byte[] bytes) throws IOException {
+    final short lengthBytes = (short)2;
+    ByteBuffer bb = ByteBuffer.allocate(bytes.length + lengthBytes);
+    bb.putShort((short)bytes.length).put(bytes);
+    ByteArrayInputStream bis = new ByteArrayInputStream(bb.array());
+    DataInputStream dis = new DataInputStream(bis);
+    return dis.readUTF();
+  }
+
   public void testIO() throws Exception {
     DataOutputBuffer out = new DataOutputBuffer();
     DataInputBuffer in = new DataInputBuffer();
@@ -80,11 +94,6 @@ public class TestUTF8 extends TestCase {
       in.reset(out.getData(), out.getLength());
       String after2 = in.readUTF();
       assertEquals(before, after2);
-
-      // test that it is compatible with Java's other decoder
-      String after3 = new String(out.getData(), 2, out.getLength()-2, "UTF-8");
-      assertEquals(before, after3);
-
     }
 
   }


Mime
View raw message