You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by zs...@apache.org on 2009/05/30 03:26:39 UTC

svn commit: r780158 - in /hadoop/hive/trunk: CHANGES.txt serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java

Author: zshao
Date: Sat May 30 01:26:39 2009
New Revision: 780158

URL: http://svn.apache.org/viewvc?rev=780158&view=rev
Log:
HIVE-520. Fix TestTCTLSeparatedProtocol. (Johan Oskarsson via zshao)

Modified:
    hadoop/hive/trunk/CHANGES.txt
    hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java
    hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java

Modified: hadoop/hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/CHANGES.txt?rev=780158&r1=780157&r2=780158&view=diff
==============================================================================
--- hadoop/hive/trunk/CHANGES.txt (original)
+++ hadoop/hive/trunk/CHANGES.txt Sat May 30 01:26:39 2009
@@ -192,6 +192,8 @@
     HIVE-506. MoveTask should fail if target path cannot be deleted.
     (Yongqiang He via zshao)
 
+    HIVE-520. Fix TestTCTLSeparatedProtocol. (Johan Oskarsson via zshao)
+
 Release 0.3.1 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java?rev=780158&r1=780157&r2=780158&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java (original)
+++ hadoop/hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/thrift/TCTLSeparatedProtocol.java Sat May 30 01:26:39 2009
@@ -307,8 +307,6 @@
     this.innerTransport = trans;
     this.bufferSize = bufferSize;
     this.nullString  = "\\N";
-
-    internalInitialize();
   }
 
 

Modified: hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java?rev=780158&r1=780157&r2=780158&view=diff
==============================================================================
--- hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java (original)
+++ hadoop/hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/TestTCTLSeparatedProtocol.java Sat May 30 01:26:39 2009
@@ -19,18 +19,19 @@
 package org.apache.hadoop.hive.serde2;
 
 
-import org.apache.hadoop.hive.serde.Constants;
+import java.util.Properties;
 
 import junit.framework.TestCase;
-import java.io.*;
-import org.apache.hadoop.hive.serde2.*;
-import org.apache.hadoop.hive.serde2.thrift.*;
-import java.util.*;
-import com.facebook.thrift.TException;
-import com.facebook.thrift.transport.*;
-import com.facebook.thrift.*;
-import com.facebook.thrift.protocol.*;
+
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.serde.Constants;
+import org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol;
+
+import com.facebook.thrift.protocol.TField;
+import com.facebook.thrift.protocol.TList;
+import com.facebook.thrift.protocol.TMap;
+import com.facebook.thrift.protocol.TStruct;
+import com.facebook.thrift.transport.TMemoryBuffer;
 
 public class TestTCTLSeparatedProtocol extends TestCase {
 
@@ -38,7 +39,6 @@
   }
 
   public void testReads() throws Exception {
-    try {
     TMemoryBuffer trans = new TMemoryBuffer(1024);
     String foo = "Hello";
     String bar = "World!";
@@ -76,6 +76,7 @@
 
     // use 3 as the row buffer size to force lots of re-buffering.
     TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 1024);
+    prot.initialize(new Configuration(), new Properties());
 
     prot.readStructBegin();
 
@@ -107,18 +108,13 @@
     prot.readFieldBegin();
     hello = prot.readString();
     prot.readFieldEnd();
-    assertTrue(hello.length() == 0);
+    assertNull(hello);
 
     prot.readStructEnd();
-
-    } catch(Exception e) {
-      e.printStackTrace();
-    }
   }
 
 
   public void testWrites() throws Exception {
-    try {
     TMemoryBuffer trans = new TMemoryBuffer(1024);
     TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 1024);
 
@@ -178,7 +174,8 @@
     //
 
     prot = new TCTLSeparatedProtocol(trans, 10);
-
+    prot.initialize(new Configuration(), new Properties());
+    
     // 100 is the start
     prot.readStructBegin();
     prot.readFieldBegin();
@@ -228,24 +225,18 @@
 
     // shouldl return nulls at end
     prot.readFieldBegin();
-    assertTrue(prot.readString().equals(""));
+    assertNull(prot.readString());
     prot.readFieldEnd();
 
     // shouldl return nulls at end
     prot.readFieldBegin();
-    assertTrue(prot.readString().equals(""));
+    assertNull(prot.readString());
     prot.readFieldEnd();
 
     prot.readStructEnd();
-
-
-    } catch(Exception e) {
-      e.printStackTrace();
-    }
   }
 
   public void testQuotedWrites() throws Exception {
-    try {
     TMemoryBuffer trans = new TMemoryBuffer(4096);
     TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 4096);
     Properties schema = new Properties();
@@ -303,20 +294,15 @@
 
     // shouldl return nulls at end
     prot.readFieldBegin();
-    assertTrue(prot.readString().equals(""));
+    assertNull(prot.readString());
     prot.readFieldEnd();
 
     // shouldl return nulls at end
     prot.readFieldBegin();
-    assertTrue(prot.readString().equals(""));
+    assertNull(prot.readString());
     prot.readFieldEnd();
 
     prot.readStructEnd();
-
-
-    } catch(Exception e) {
-      e.printStackTrace();
-    }
   }
 
 
@@ -325,88 +311,83 @@
    * case, TCTLSeparatedProtocol can do it. 
    */
   public void test1ApacheLogFormat() throws Exception {
-    try {
-      final String sample = "127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb.gif HTTP/1.0\" 200 2326";
+    final String sample = "127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb.gif HTTP/1.0\" 200 2326";
 
-      TMemoryBuffer trans = new TMemoryBuffer(4096);
-      trans.write(sample.getBytes(), 0, sample.getBytes().length);
-      trans.flush();
-
-      TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 4096);
-      Properties schema = new Properties();
+    TMemoryBuffer trans = new TMemoryBuffer(4096);
+    trans.write(sample.getBytes(), 0, sample.getBytes().length);
+    trans.flush();
 
-      // this is a hacky way of doing the quotes since it will match any 2 of these, so
-      // "[ hello this is something to split [" would be considered to be quoted.
-      schema.setProperty(Constants.QUOTE_CHAR, "(\"|\\[|\\])");
+    TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 4096);
+    Properties schema = new Properties();
 
-      schema.setProperty(Constants.FIELD_DELIM, " ");
-      schema.setProperty(Constants.SERIALIZATION_NULL_FORMAT, "-");
-      prot.initialize(new Configuration(), schema);
+    // this is a hacky way of doing the quotes since it will match any 2 of these, so
+    // "[ hello this is something to split [" would be considered to be quoted.
+    schema.setProperty(Constants.QUOTE_CHAR, "(\"|\\[|\\])");
 
-      prot.readStructBegin();
+    schema.setProperty(Constants.FIELD_DELIM, " ");
+    schema.setProperty(Constants.SERIALIZATION_NULL_FORMAT, "-");
+    prot.initialize(new Configuration(), schema);
 
-      // ip address
-      prot.readFieldBegin();
-      final String ip = prot.readString();
-      prot.readFieldEnd();
+    prot.readStructBegin();
 
-      assertEquals("127.0.0.1", ip);
+    // ip address
+    prot.readFieldBegin();
+    final String ip = prot.readString();
+    prot.readFieldEnd();
 
-      //  identd
-      prot.readFieldBegin();
-      final String identd = prot.readString();
-      prot.readFieldEnd();
+    assertEquals("127.0.0.1", ip);
 
-      assertEquals("", identd);
+    //  identd
+    prot.readFieldBegin();
+    final String identd = prot.readString();
+    prot.readFieldEnd();
 
-      //  user
-      prot.readFieldBegin();
-      final String user = prot.readString();
-      prot.readFieldEnd();
+    assertNull(identd);
 
-      assertEquals("frank",user);
+    //  user
+    prot.readFieldBegin();
+    final String user = prot.readString();
+    prot.readFieldEnd();
 
-      //  finishTime
-      prot.readFieldBegin();
-      final String finishTime = prot.readString();
-      prot.readFieldEnd();
+    assertEquals("frank",user);
 
-      assertEquals("10/Oct/2000:13:55:36 -0700",finishTime);
+    //  finishTime
+    prot.readFieldBegin();
+    final String finishTime = prot.readString();
+    prot.readFieldEnd();
 
-      //  requestLine
-      prot.readFieldBegin();
-      final String requestLine = prot.readString();
-      prot.readFieldEnd();
+    assertEquals("10/Oct/2000:13:55:36 -0700",finishTime);
 
-      assertEquals("GET /apache_pb.gif HTTP/1.0",requestLine);
+    //  requestLine
+    prot.readFieldBegin();
+    final String requestLine = prot.readString();
+    prot.readFieldEnd();
 
-      //  returncode
-      prot.readFieldBegin();
-      final int returnCode = prot.readI32();
-      prot.readFieldEnd();
+    assertEquals("GET /apache_pb.gif HTTP/1.0",requestLine);
 
-      assertEquals(200, returnCode);
+    //  returncode
+    prot.readFieldBegin();
+    final int returnCode = prot.readI32();
+    prot.readFieldEnd();
 
-      //  return size
-      prot.readFieldBegin();
-      final int returnSize = prot.readI32();
-      prot.readFieldEnd();
+    assertEquals(200, returnCode);
 
-      assertEquals(2326, returnSize);
+    //  return size
+    prot.readFieldBegin();
+    final int returnSize = prot.readI32();
+    prot.readFieldEnd();
 
-      prot.readStructEnd();
+    assertEquals(2326, returnSize);
 
-    } catch(Exception e) {
-      e.printStackTrace();
-    }
+    prot.readStructEnd();
   }
 
 
 
   public void testNulls() throws Exception {
-    try {
     TMemoryBuffer trans = new TMemoryBuffer(1024);
     TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 10);
+    prot.initialize(new Configuration(), new Properties());
 
     prot.writeStructBegin(new TStruct());
 
@@ -451,6 +432,7 @@
     trans.write(b, 0, len);
 
     prot = new TCTLSeparatedProtocol(trans, 3);
+    prot.initialize(new Configuration(), new Properties());
     
     prot.readStructBegin();
 
@@ -458,13 +440,13 @@
     String ret = prot.readString();
     prot.readFieldEnd();
 
-    assertTrue(ret.equals(""));
+    assertNull(ret);
 
     prot.readFieldBegin();
     ret = prot.readString();
     prot.readFieldEnd();
     
-    assertTrue(ret.equals(""));
+    assertNull(ret);
 
     prot.readFieldBegin();
     int ret1 = prot.readI32();
@@ -482,25 +464,19 @@
 
     assertTrue(map.size == 3);
 
-    assertTrue(prot.readString().isEmpty());
-    assertTrue(prot.readString().isEmpty());
+    assertNull(prot.readString());
+    assertNull(prot.readString());
 
     assertTrue(prot.readString().equals("key2"));
-    assertTrue(prot.readString().isEmpty());
+    assertNull(prot.readString());
 
-    assertTrue(prot.readString().isEmpty());
+    assertNull(prot.readString());
     assertTrue(prot.readString().equals("val3"));
     
     prot.readMapEnd();
     prot.readFieldEnd();
 
     assertTrue(ret1 == 0);
-
-    } catch(Exception e) {
-      e.printStackTrace();
-    }
   }
 
-
-
 }