avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1386824 - in /avro/trunk: ./ lang/java/avro/ lang/java/avro/src/test/java/org/apache/avro/ lang/java/avro/src/test/java/org/apache/avro/reflect/ lang/java/compiler/ lang/java/compiler/src/test/java/org/apache/avro/compiler/ lang/java/ipc/ ...
Date Mon, 17 Sep 2012 20:42:51 GMT
Author: cutting
Date: Mon Sep 17 20:42:50 2012
New Revision: 1386824

URL: http://svn.apache.org/viewvc?rev=1386824&view=rev
Log:
AVRO-1150. Java: Fix tests to create all temporary files in target directories.  Contributed
by Gabriel Reid.

Removed:
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/AvroTestUtil.java
    avro/trunk/lang/java/tools/src/test/java/org/apache/avro/AvroTestUtil.java
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/pom.xml
    avro/trunk/lang/java/avro/src/test/java/org/apache/avro/AvroTestUtil.java
    avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestDataFileMeta.java
    avro/trunk/lang/java/avro/src/test/java/org/apache/avro/reflect/ByteBufferTest.java
    avro/trunk/lang/java/compiler/pom.xml
    avro/trunk/lang/java/compiler/src/test/java/org/apache/avro/compiler/TestSpecificCompiler.java
    avro/trunk/lang/java/ipc/pom.xml
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
    avro/trunk/lang/java/tools/pom.xml
    avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileTools.java
    avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestRecodecTool.java
    avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Mon Sep 17 20:42:50 2012
@@ -80,6 +80,9 @@ Avro 1.7.2 (unreleased)
     AVRO-1166. Java: Fix bug in SpecificData.getSchema(Map). (George
     Fletcher via cutting)
 
+    AVRO-1150. Java: Fix tests to create all temporary files in target
+    directories.  (Gabriel Reid via cutting)
+
 Avro 1.7.1 (16 July 2012)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/avro/pom.xml
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/pom.xml?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/pom.xml (original)
+++ avro/trunk/lang/java/avro/pom.xml Mon Sep 17 20:42:50 2012
@@ -61,6 +61,17 @@
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/AvroTestUtil.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/AvroTestUtil.java?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/AvroTestUtil.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/AvroTestUtil.java Mon Sep 17 20:42:50
2012
@@ -21,12 +21,34 @@ import java.io.File;
 
 /** Utilities for Avro tests. */
 public class AvroTestUtil {
-  static final File TMPDIR = new File(System.getProperty("test.dir", "/tmp"));
+  static final File TMPDIR = new File(System.getProperty("test.dir", System.getProperty("java.io.tmpdir",
"/tmp")), "tmpfiles");
 
-  private AvroTestUtil() { }
-  
-  /** Create a temporary file in a test-appropriate directory. */
-  public static File tempFile(String name) {
-    return new File(TMPDIR, name);
+  private AvroTestUtil() {
   }
+
+  /** 
+   * Create a temporary file in a test-appropriate directory.
+   * 
+   * @param testClass The test case class requesting the file creation
+   * @param name The name of the file to be created 
+   */
+  public static File tempFile(Class testClass, String name) {
+    File testClassDir = new File(TMPDIR, testClass.getName());
+    testClassDir.mkdirs();
+    return new File(testClassDir, name);
+  }
+
+  /** 
+   * Create a temporary directory in a test-appropriate directory.
+   * 
+   * @param testClass The test case class requesting the directory creation
+   * @param name The name of the directory to be created  
+   */
+  public static File tempDirectory(Class testClass, String name) {
+    File tmpFile = tempFile(testClass, name);
+    tmpFile.delete();
+    tmpFile.mkdir();
+    return tmpFile;
+  }
+
 }

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestDataFileMeta.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestDataFileMeta.java?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestDataFileMeta.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestDataFileMeta.java Mon Sep
17 20:42:50 2012
@@ -44,7 +44,7 @@ public class TestDataFileMeta {
   @Test()
   public void testUseMeta() throws IOException {
     DataFileWriter<?> w = new DataFileWriter<Object>(new GenericDatumWriter<Object>());
-    File f = AvroTestUtil.tempFile("testDataFileMeta.avro");
+    File f = AvroTestUtil.tempFile(getClass(), "testDataFileMeta.avro");
     w.setMeta("hello", "bar");
     w.create(Schema.create(Type.NULL), f);
     w.close();

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/reflect/ByteBufferTest.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/reflect/ByteBufferTest.java?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/reflect/ByteBufferTest.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/reflect/ByteBufferTest.java Mon
Sep 17 20:42:50 2012
@@ -33,6 +33,7 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Iterator;
 
+import org.apache.avro.AvroTestUtil;
 import org.apache.avro.Schema;
 import org.apache.avro.file.DataFileReader;
 import org.apache.avro.file.DataFileWriter;
@@ -51,13 +52,10 @@ public class ByteBufferTest {
     String name = "";
     ByteBuffer content;
   }
-  File tmpdir;
   File content;
 
   @Before public void before() throws IOException{
-    tmpdir = File.createTempFile("avro", "test");
-    tmpdir.delete();
-    tmpdir.mkdirs();
+    File tmpdir = AvroTestUtil.tempDirectory(getClass(), "content");
     content = new File(tmpdir,"test-content");
     FileOutputStream out = new FileOutputStream(content);
     for(int i=0;i<100000;i++){

Modified: avro/trunk/lang/java/compiler/pom.xml
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/pom.xml?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/pom.xml (original)
+++ avro/trunk/lang/java/compiler/pom.xml Mon Sep 17 20:42:50 2012
@@ -83,6 +83,13 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>avro</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>commons-lang</groupId>
       <artifactId>commons-lang</artifactId>
       <version>${commons-lang.version}</version>

Modified: avro/trunk/lang/java/compiler/src/test/java/org/apache/avro/compiler/TestSpecificCompiler.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/test/java/org/apache/avro/compiler/TestSpecificCompiler.java?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/src/test/java/org/apache/avro/compiler/TestSpecificCompiler.java
(original)
+++ avro/trunk/lang/java/compiler/src/test/java/org/apache/avro/compiler/TestSpecificCompiler.java
Mon Sep 17 20:42:50 2012
@@ -17,10 +17,13 @@
  */
 package org.apache.avro.compiler;
 
+import static org.junit.Assert.assertTrue;
+
 import java.io.File;
 import java.io.IOException;
 import java.net.URISyntaxException;
 
+import org.apache.avro.AvroTestUtil;
 import org.apache.avro.Schema;
 import org.apache.avro.compiler.specific.SpecificCompiler;
 import org.apache.avro.generic.GenericData.StringType;
@@ -41,10 +44,8 @@ public class TestSpecificCompiler {
     SpecificCompiler compiler = new SpecificCompiler(schema);
     compiler.setTemplateDir(velocityTemplateDir);
     compiler.setStringType(StringType.CharSequence);
-    File outputDir = File.createTempFile("avro-tmp", "");
-    outputDir.delete();
-    outputDir.mkdir();
+    File outputDir = AvroTestUtil.tempDirectory(getClass(), "specific-output");
     compiler.compileToDestination(src, outputDir);
-    new File(outputDir, "SimpleRecord.java").delete();
+    assertTrue(new File(outputDir, "SimpleRecord.java").exists());
   }
 }

Modified: avro/trunk/lang/java/ipc/pom.xml
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/pom.xml?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/pom.xml (original)
+++ avro/trunk/lang/java/ipc/pom.xml Mon Sep 17 20:42:50 2012
@@ -78,6 +78,13 @@
     </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
+      <artifactId>avro</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
       <artifactId>avro-compiler</artifactId>
       <version>${project.version}</version>
       <scope>test</scope>

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
(original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
Mon Sep 17 20:42:50 2012
@@ -202,7 +202,7 @@ public class TestSpecificCompiler {
       "{ \"name\": \"Foo\", \"type\": \"record\", " +
       "  \"fields\": [ {\"name\": \"package\", \"type\": \"string\" }," +
       "                {\"name\": \"short\", \"type\": \"Foo\" } ] }";
-    File inputFile = File.createTempFile("input", "avsc");
+    File inputFile = AvroTestUtil.tempFile(getClass(), "input.avsc");
     FileWriter fw = new FileWriter(inputFile);
     fw.write(schema);
     fw.close();
@@ -663,7 +663,7 @@ public class TestSpecificCompiler {
     if (outputs.isEmpty()) {
       return;               // Nothing to compile!
     }
-    File dstDir = AvroTestUtil.tempFile("realCompiler");
+    File dstDir = AvroTestUtil.tempFile(TestSpecificCompiler.class, "realCompiler");
     List<File> javaFiles = new ArrayList<File>();
     for (OutputFile o : outputs) {
       javaFiles.add(o.writeToDestination(null, dstDir));

Modified: avro/trunk/lang/java/tools/pom.xml
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/tools/pom.xml?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/tools/pom.xml (original)
+++ avro/trunk/lang/java/tools/pom.xml Mon Sep 17 20:42:50 2012
@@ -96,6 +96,13 @@
     </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
+      <artifactId>avro</artifactId>
+      <version>${project.version}</version>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
       <artifactId>avro-compiler</artifactId>
       <version>${project.version}</version>
     </dependency>

Modified: avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileTools.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileTools.java?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileTools.java (original)
+++ avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestDataFileTools.java Mon
Sep 17 20:42:50 2012
@@ -56,10 +56,10 @@ public class TestDataFileTools {
 
   @BeforeClass
   public static void writeSampleFile() throws IOException {
-    sampleFile = AvroTestUtil.tempFile(
+    sampleFile = AvroTestUtil.tempFile(TestDataFileTools.class,
       TestDataFileTools.class.getName() + ".avro");
     schema = Schema.create(Type.INT);
-    schemaFile = File.createTempFile("schema-temp", "schema");
+    schemaFile = AvroTestUtil.tempFile(TestDataFileTools.class, "schema-temp.schema");
     FileWriter fw = new FileWriter(schemaFile);
     fw.append(schema.toString());
     fw.close();
@@ -136,7 +136,7 @@ public class TestDataFileTools {
   }
   public void testWrite(String name, List<String> extra, String expectedCodec, String...
extraArgs) 
   throws Exception {
-    File outFile = AvroTestUtil.tempFile(
+    File outFile = AvroTestUtil.tempFile(getClass(),
         TestDataFileTools.class + ".testWrite." + name + ".avro");
     FileOutputStream fout = new FileOutputStream(outFile);
     PrintStream out = new PrintStream(fout);
@@ -218,7 +218,7 @@ public class TestDataFileTools {
   }
   
   public File writeToAvroFile(String testName, String schema, String json) throws Exception
{
-    File outFile = AvroTestUtil.tempFile(
+    File outFile = AvroTestUtil.tempFile(getClass(),
         TestDataFileTools.class + "." + testName + ".avro");
     FileOutputStream fout = new FileOutputStream(outFile);
     PrintStream out = new PrintStream(fout);

Modified: avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestRecodecTool.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestRecodecTool.java?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestRecodecTool.java (original)
+++ avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestRecodecTool.java Mon
Sep 17 20:42:50 2012
@@ -40,7 +40,7 @@ public class TestRecodecTool {
     String metaKey = "myMetaKey";
     String metaValue = "myMetaValue";
     
-    File inputFile = AvroTestUtil.tempFile("input.avro");
+    File inputFile = AvroTestUtil.tempFile(getClass(), "input.avro");
     
     Schema schema = Schema.create(Type.STRING);
     DataFileWriter<String> writer = new DataFileWriter<String>(
@@ -56,11 +56,11 @@ public class TestRecodecTool {
     }
     writer.close();
 
-    File defaultOutputFile = AvroTestUtil.tempFile("default-output.avro");
-    File nullOutputFile = AvroTestUtil.tempFile("null-output.avro");
-    File deflateDefaultOutputFile = AvroTestUtil.tempFile("deflate-default-output.avro");
-    File deflate1OutputFile = AvroTestUtil.tempFile("deflate-1-output.avro");
-    File deflate9OutputFile = AvroTestUtil.tempFile("deflate-9-output.avro");
+    File defaultOutputFile = AvroTestUtil.tempFile(getClass(), "default-output.avro");
+    File nullOutputFile = AvroTestUtil.tempFile(getClass(), "null-output.avro");
+    File deflateDefaultOutputFile = AvroTestUtil.tempFile(getClass(), "deflate-default-output.avro");
+    File deflate1OutputFile = AvroTestUtil.tempFile(getClass(), "deflate-1-output.avro");
+    File deflate9OutputFile = AvroTestUtil.tempFile(getClass(), "deflate-9-output.avro");
     
     new RecodecTool().run(new FileInputStream(inputFile), new PrintStream(defaultOutputFile),
null, new ArrayList<String>());
     new RecodecTool().run(new FileInputStream(inputFile), new PrintStream(nullOutputFile),
null, asList("--codec=null"));

Modified: avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java?rev=1386824&r1=1386823&r2=1386824&view=diff
==============================================================================
--- avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java (original)
+++ avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java Mon
Sep 17 20:42:50 2012
@@ -62,7 +62,7 @@ public class TestTextFileTools {
   public static void writeRandomFile() throws IOException {
     schema = Schema.create(Type.BYTES);
     lines = new ByteBuffer[COUNT];
-    linesFile = AvroTestUtil.tempFile("random.lines");
+    linesFile = AvroTestUtil.tempFile(TestTextFileTools.class, "random.lines");
 
     OutputStream out =
       new BufferedOutputStream(new FileOutputStream(linesFile));
@@ -84,7 +84,7 @@ public class TestTextFileTools {
   }
   
   private void fromText(String name, String... args) throws Exception {
-    File avroFile = AvroTestUtil.tempFile(name + ".avro");
+    File avroFile = AvroTestUtil.tempFile(getClass(), name + ".avro");
 
     ArrayList<String> arglist = new ArrayList<String>();
     arglist.addAll(Arrays.asList(args));
@@ -120,8 +120,8 @@ public class TestTextFileTools {
   }
 
   private static void toText(String name) throws Exception {
-    File avroFile = AvroTestUtil.tempFile(name + ".avro");
-    File outFile = AvroTestUtil.tempFile(name + ".lines");
+    File avroFile = AvroTestUtil.tempFile(TestTextFileTools.class, name + ".avro");
+    File outFile = AvroTestUtil.tempFile(TestTextFileTools.class, name + ".lines");
 
     ArrayList<String> arglist = new ArrayList<String>();
     arglist.add(avroFile.toString());



Mime
View raw message