You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2010/12/31 05:39:59 UTC

svn commit: r1054053 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java lucene/backwards/src/test/org/apache/lucene/util/LuceneTestCase.java lucene/common-build.xml solr/

Author: rmuir
Date: Fri Dec 31 04:39:59 2010
New Revision: 1054053

URL: http://svn.apache.org/viewvc?rev=1054053&view=rev
Log:
enforce resource handling, prevent test interference by running in a jvm-unique CWD (under build/, same as tempDir)

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/util/LuceneTestCase.java
    lucene/dev/branches/branch_3x/lucene/common-build.xml
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?rev=1054053&r1=1054052&r2=1054053&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Fri Dec 31 04:39:59 2010
@@ -78,13 +78,11 @@ public class TestBackwardsCompatibility 
 
   /* Unzips dirName + ".zip" --> dirName, removing dirName
      first */
-  public void unzip(String zipName, String destDirName) throws IOException {
+  public void unzip(File zipName, String destDirName) throws IOException {
 
-    Enumeration entries;
-    ZipFile zipFile;
-    zipFile = new ZipFile(zipName + ".zip");
+    ZipFile zipFile = new ZipFile(zipName);
 
-    entries = zipFile.entries();
+    Enumeration<? extends ZipEntry> entries = zipFile.entries();
 
     String dirName = fullDir(destDirName);
 
@@ -94,7 +92,7 @@ public class TestBackwardsCompatibility 
     fileDir.mkdir();
 
     while (entries.hasMoreElements()) {
-      ZipEntry entry = (ZipEntry) entries.nextElement();
+      ZipEntry entry = entries.nextElement();
 
       InputStream in = zipFile.getInputStream(entry);
       OutputStream out = new BufferedOutputStream(new FileOutputStream(new File(fileDir, entry.getName())));
@@ -209,8 +207,7 @@ public class TestBackwardsCompatibility 
     int hasTested29 = 0;
     
     for(int i=0;i<oldNames.length;i++) {
-      String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
-      unzip(dirName, oldNames[i]);
+      unzip(getDataFile("index." + oldNames[i] + ".zip"), oldNames[i]);
       String fullPath = fullDir(oldNames[i]);
       Directory dir = FSDirectory.open(new File(fullPath));
 
@@ -239,8 +236,7 @@ public class TestBackwardsCompatibility 
 
   public void testSearchOldIndex() throws IOException {
     for(int i=0;i<oldNames.length;i++) {
-      String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
-      unzip(dirName, oldNames[i]);
+      unzip(getDataFile("index." + oldNames[i] + ".zip"), oldNames[i]);
       searchIndex(oldNames[i], oldNames[i]);
       rmDir(oldNames[i]);
     }
@@ -248,8 +244,7 @@ public class TestBackwardsCompatibility 
 
   public void testIndexOldIndexNoAdds() throws IOException {
     for(int i=0;i<oldNames.length;i++) {
-      String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
-      unzip(dirName, oldNames[i]);
+      unzip(getDataFile("index." + oldNames[i] + ".zip"), oldNames[i]);
       changeIndexNoAdds(oldNames[i]);
       rmDir(oldNames[i]);
     }
@@ -257,8 +252,7 @@ public class TestBackwardsCompatibility 
 
   public void testIndexOldIndex() throws IOException {
     for(int i=0;i<oldNames.length;i++) {
-      String dirName = "src/test/org/apache/lucene/index/index." + oldNames[i];
-      unzip(dirName, oldNames[i]);
+      unzip(getDataFile("index." + oldNames[i] + ".zip"), oldNames[i]);
       changeIndexWithAdds(oldNames[i]);
       rmDir(oldNames[i]);
     }

Modified: lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/util/LuceneTestCase.java?rev=1054053&r1=1054052&r2=1054053&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/branches/branch_3x/lucene/backwards/src/test/org/apache/lucene/util/LuceneTestCase.java Fri Dec 31 04:39:59 2010
@@ -17,6 +17,8 @@ package org.apache.lucene.util;
  * limitations under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
 import java.io.PrintStream;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -266,4 +268,17 @@ public abstract class LuceneTestCase ext
   
   // static members
   private static final Random seedRnd = new Random();
+  
+  /** Gets a resource from the classpath as {@link File}. This method should only be used,
+   * if a real file is needed. To get a stream, code should prefer
+   * {@link Class#getResourceAsStream} using {@code this.getClass()}.
+   */
+  
+  protected File getDataFile(String name) throws IOException {
+    try {
+      return new File(this.getClass().getResource(name).toURI());
+    } catch (Exception e) {
+      throw new IOException("Cannot find resource: " + name);
+    }
+  }
 }

Modified: lucene/dev/branches/branch_3x/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/common-build.xml?rev=1054053&r1=1054052&r2=1054053&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/common-build.xml (original)
+++ lucene/dev/branches/branch_3x/lucene/common-build.xml Fri Dec 31 04:39:59 2010
@@ -74,7 +74,6 @@
   <property name="tests.linedocsfile" value="europarl.lines.txt.gz" />
   <property name="tests.iter" value="1" />
   <property name="tests.seed" value="random" />
-  <property name="tests.userdir" value="."/>
   <property name="tests.loggingfile" value="/dev/null"/>
   <property name="tests.nightly" value="false" />
     
@@ -442,7 +441,7 @@
 	    -->
     	<touch file="@{tempDir}/@{threadNum}/quiet.ant" verbose="false" mkdirs="true"/>
 	    <junit printsummary="off" haltonfailure="no" maxmemory="512M" tempdir="@{tempDir}/@{threadNum}"
-	      errorProperty="tests.failed" failureProperty="tests.failed" forkmode="perBatch" dir="${tests.userdir}">
+	      errorProperty="tests.failed" failureProperty="tests.failed" forkmode="perBatch" dir="@{tempDir}/@{threadNum}">
 	      <classpath refid="@{junit.classpath}"/>
 	      <assertions>
 	        <enable package="org.apache.lucene"/>