avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1637494 - in /avro/trunk: CHANGES.txt lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java lang/java/trevni/core/src/test/java/org/apache/trevni/TestUtil.java
Date Sat, 08 Nov 2014 00:57:20 GMT
Author: cutting
Date: Sat Nov  8 00:57:20 2014
New Revision: 1637494

URL: http://svn.apache.org/r1637494
Log:
AVRO-1597. Java: Random data tool writes corrupt files to standard out.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
    avro/trunk/lang/java/trevni/core/src/test/java/org/apache/trevni/TestUtil.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1637494&r1=1637493&r2=1637494&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Sat Nov  8 00:57:20 2014
@@ -64,6 +64,9 @@ Trunk (not yet released)
     AVRO-1592. Java: Fix handling of Java reserved words as enum
     constants in generated code. (Lukas Steiblys via cutting)
 
+    AVRO-1597. Java: Random data tool writes corrupt files to standard out.
+    (cutting)
+
 Avro 1.7.7 (23 July 2014)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java?rev=1637494&r1=1637493&r2=1637494&view=diff
==============================================================================
--- avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
(original)
+++ avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestCreateRandomFileTool.java
Sat Nov  8 00:57:20 2014
@@ -17,6 +17,7 @@
  */
 package org.apache.avro.tool;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.PrintStream;
@@ -27,8 +28,10 @@ import java.util.Iterator;
 
 import org.apache.avro.Schema;
 import org.apache.avro.file.DataFileReader;
+import org.apache.avro.file.DataFileStream;
 import org.apache.avro.generic.GenericDatumReader;
 import org.apache.trevni.avro.RandomData;
+import org.apache.trevni.TestUtil;
 
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
@@ -41,11 +44,17 @@ public class TestCreateRandomFileTool {
   private static final File SCHEMA_FILE =
     new File("../../../share/test/schemas/weather.avsc");
 
-  private String run(List<String> args) throws Exception {
+  private byte[] run(List<String> args) throws Exception {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintStream p = new PrintStream(baos);
-    new CreateRandomFileTool().run(null, p, null, args);
-    return baos.toString("UTF-8").replace("\r", "");
+    PrintStream save = System.out;
+    try {
+      System.setOut(p);
+      new CreateRandomFileTool().run(null, p, null, args);
+    } finally {
+      System.setOut(save);
+    }
+    return baos.toByteArray();
   }
   
   public void check(String... extraArgs) throws Exception {
@@ -79,4 +88,22 @@ public class TestCreateRandomFileTool {
     check("--codec", "snappy");
   }
 
+  @Test
+  public void testStdOut() throws Exception {
+    TestUtil.resetRandomSeed();
+    byte[] file =
+      run(Arrays.asList(new String[]
+        { "-", "--count", COUNT, "--schema-file", SCHEMA_FILE.toString() }));
+    
+    DataFileStream<Object> reader =
+      new DataFileStream(new ByteArrayInputStream(file),
+                         new GenericDatumReader<Object>());
+    
+    Iterator<Object> found = reader.iterator();
+    for (Object expected :
+           new RandomData(Schema.parse(SCHEMA_FILE), Integer.parseInt(COUNT)))
+      assertEquals(expected, found.next());
+
+    reader.close();
+  }
 }

Modified: avro/trunk/lang/java/trevni/core/src/test/java/org/apache/trevni/TestUtil.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/trevni/core/src/test/java/org/apache/trevni/TestUtil.java?rev=1637494&r1=1637493&r2=1637494&view=diff
==============================================================================
--- avro/trunk/lang/java/trevni/core/src/test/java/org/apache/trevni/TestUtil.java (original)
+++ avro/trunk/lang/java/trevni/core/src/test/java/org/apache/trevni/TestUtil.java Sat Nov
 8 00:57:20 2014
@@ -41,12 +41,16 @@ public class TestUtil {
         seed = Long.valueOf(configured);
       else 
         seed = System.currentTimeMillis();
-      System.out.println("test.seed="+seed);
+      System.err.println("test.seed="+seed);
       seedSet = true;
     }
     return seed;
  }
 
+  public static void resetRandomSeed() {
+    seedSet = false;
+  }
+
   public static Random createRandom() {
     return new Random(getRandomSeed());
   }



Mime
View raw message