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 2014/09/14 04:31:31 UTC
svn commit: r1624800 - in /lucene/dev/trunk/lucene:
analysis/common/src/test/org/apache/lucene/analysis/hunspell/
benchmark/src/java/org/apache/lucene/benchmark/quality/trec/ core/
test-framework/src/java/org/apache/lucene/analysis/ tools/forbiddenApis/
Author: rmuir
Date: Sun Sep 14 02:31:31 2014
New Revision: 1624800
URL: http://svn.apache.org/r1624800
Log:
LUCENE-5945: more test cleanups
Modified:
lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java
lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java
lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java
lucene/dev/trunk/lucene/core/build.xml
lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java
lucene/dev/trunk/lucene/tools/forbiddenApis/lucene.txt
Modified: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java?rev=1624800&r1=1624799&r2=1624800&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java (original)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java Sun Sep 14 02:31:31 2014
@@ -18,17 +18,16 @@ package org.apache.lucene.analysis.hunsp
*/
import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
import org.apache.lucene.analysis.hunspell.Dictionary;
+import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
import org.apache.lucene.util.RamUsageTester;
+import org.apache.lucene.util.TestUtil;
import org.junit.Ignore;
/**
@@ -157,18 +156,22 @@ public class TestAllDictionaries extends
};
public void test() throws Exception {
+ Path tmp = LuceneTestCase.createTempDir();
+
for (int i = 0; i < tests.length; i += 3) {
Path f = DICTIONARY_HOME.resolve(tests[i]);
assert Files.exists(f);
- try (ZipFile zip = new ZipFile(f.toFile(), StandardCharsets.UTF_8)) {
- ZipEntry dicEntry = zip.getEntry(tests[i+1]);
- assert dicEntry != null;
- ZipEntry affEntry = zip.getEntry(tests[i+2]);
- assert affEntry != null;
+ IOUtils.rm(tmp);
+ Files.createDirectory(tmp);
- try (InputStream dictionary = zip.getInputStream(dicEntry);
- InputStream affix = zip.getInputStream(affEntry)) {
+ try (InputStream in = Files.newInputStream(f)) {
+ TestUtil.unzip(in, tmp);
+ Path dicEntry = tmp.resolve(tests[i+1]);
+ Path affEntry = tmp.resolve(tests[i+2]);
+
+ try (InputStream dictionary = Files.newInputStream(dicEntry);
+ InputStream affix = Files.newInputStream(affEntry)) {
Dictionary dic = new Dictionary(affix, dictionary);
System.out.println(tests[i] + "\t" + RamUsageTester.humanSizeOf(dic) + "\t(" +
"words=" + RamUsageTester.humanSizeOf(dic.words) + ", " +
@@ -184,22 +187,26 @@ public class TestAllDictionaries extends
}
public void testOneDictionary() throws Exception {
+ Path tmp = LuceneTestCase.createTempDir();
+
String toTest = "zu_ZA.zip";
for (int i = 0; i < tests.length; i++) {
if (tests[i].equals(toTest)) {
Path f = DICTIONARY_HOME.resolve(tests[i]);
assert Files.exists(f);
- try (ZipFile zip = new ZipFile(f.toFile(), StandardCharsets.UTF_8)) {
- ZipEntry dicEntry = zip.getEntry(tests[i+1]);
- assert dicEntry != null;
- ZipEntry affEntry = zip.getEntry(tests[i+2]);
- assert affEntry != null;
+ IOUtils.rm(tmp);
+ Files.createDirectory(tmp);
+
+ try (InputStream in = Files.newInputStream(f)) {
+ TestUtil.unzip(in, tmp);
+ Path dicEntry = tmp.resolve(tests[i+1]);
+ Path affEntry = tmp.resolve(tests[i+2]);
- try (InputStream dictionary = zip.getInputStream(dicEntry);
- InputStream affix = zip.getInputStream(affEntry)) {
- new Dictionary(affix, dictionary);
- }
+ try (InputStream dictionary = Files.newInputStream(dicEntry);
+ InputStream affix = Files.newInputStream(affEntry)) {
+ new Dictionary(affix, dictionary);
+ }
}
}
}
Modified: lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java?rev=1624800&r1=1624799&r2=1624800&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java (original)
+++ lucene/dev/trunk/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java Sun Sep 14 02:31:31 2014
@@ -18,16 +18,15 @@ package org.apache.lucene.analysis.hunsp
*/
import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
import org.apache.lucene.analysis.hunspell.Dictionary;
+import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.RamUsageTester;
+import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
import org.junit.Ignore;
@@ -172,18 +171,22 @@ public class TestAllDictionaries2 extend
};
public void test() throws Exception {
+ Path tmp = LuceneTestCase.createTempDir();
+
for (int i = 0; i < tests.length; i += 3) {
Path f = DICTIONARY_HOME.resolve(tests[i]);
assert Files.exists(f);
- try (ZipFile zip = new ZipFile(f.toFile(), StandardCharsets.UTF_8)) {
- ZipEntry dicEntry = zip.getEntry(tests[i+1]);
- assert dicEntry != null;
- ZipEntry affEntry = zip.getEntry(tests[i+2]);
- assert affEntry != null;
+ IOUtils.rm(tmp);
+ Files.createDirectory(tmp);
- try (InputStream dictionary = zip.getInputStream(dicEntry);
- InputStream affix = zip.getInputStream(affEntry)) {
+ try (InputStream in = Files.newInputStream(f)) {
+ TestUtil.unzip(in, tmp);
+ Path dicEntry = tmp.resolve(tests[i+1]);
+ Path affEntry = tmp.resolve(tests[i+2]);
+
+ try (InputStream dictionary = Files.newInputStream(dicEntry);
+ InputStream affix = Files.newInputStream(affEntry)) {
Dictionary dic = new Dictionary(affix, dictionary);
System.out.println(tests[i] + "\t" + RamUsageTester.humanSizeOf(dic) + "\t(" +
"words=" + RamUsageTester.humanSizeOf(dic.words) + ", " +
@@ -199,22 +202,26 @@ public class TestAllDictionaries2 extend
}
public void testOneDictionary() throws Exception {
+ Path tmp = LuceneTestCase.createTempDir();
+
String toTest = "hungarian_dictionary-1.6.1.1-fx+tb+sm+fn.xpi";
for (int i = 0; i < tests.length; i++) {
if (tests[i].equals(toTest)) {
Path f = DICTIONARY_HOME.resolve(tests[i]);
assert Files.exists(f);
- try (ZipFile zip = new ZipFile(f.toFile(), StandardCharsets.UTF_8)) {
- ZipEntry dicEntry = zip.getEntry(tests[i+1]);
- assert dicEntry != null;
- ZipEntry affEntry = zip.getEntry(tests[i+2]);
- assert affEntry != null;
+ IOUtils.rm(tmp);
+ Files.createDirectory(tmp);
+
+ try (InputStream in = Files.newInputStream(f)) {
+ TestUtil.unzip(in, tmp);
+ Path dicEntry = tmp.resolve(tests[i+1]);
+ Path affEntry = tmp.resolve(tests[i+2]);
- try (InputStream dictionary = zip.getInputStream(dicEntry);
- InputStream affix = zip.getInputStream(affEntry)) {
+ try (InputStream dictionary = Files.newInputStream(dicEntry);
+ InputStream affix = Files.newInputStream(affEntry)) {
new Dictionary(affix, dictionary);
- }
+ }
}
}
}
Modified: lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java?rev=1624800&r1=1624799&r2=1624800&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java (original)
+++ lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/quality/trec/QueryDriver.java Sun Sep 14 02:31:31 2014
@@ -24,7 +24,6 @@ import org.apache.lucene.index.Directory
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.FSDirectory;
-import org.apache.lucene.util.IOUtils;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
@@ -55,7 +54,8 @@ public class QueryDriver {
Path topicsFile = Paths.get(args[0]);
Path qrelsFile = Paths.get(args[1]);
- SubmissionReport submitLog = new SubmissionReport(new PrintWriter(args[2], IOUtils.UTF_8 /* huh, no nio.Charset ctor? */), "lucene");
+ Path submissionFile = Paths.get(args[2]);
+ SubmissionReport submitLog = new SubmissionReport(new PrintWriter(Files.newBufferedWriter(submissionFile, StandardCharsets.UTF_8)), "lucene");
FSDirectory dir = FSDirectory.open(Paths.get(args[3]));
String fieldSpec = args.length == 5 ? args[4] : "T"; // default to Title-only if not specified.
IndexReader reader = DirectoryReader.open(dir);
Modified: lucene/dev/trunk/lucene/core/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/build.xml?rev=1624800&r1=1624799&r2=1624800&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/build.xml (original)
+++ lucene/dev/trunk/lucene/core/build.xml Sun Sep 14 02:31:31 2014
@@ -30,13 +30,15 @@
org/apache/lucene/util/PrintStreamInfoStream.class
"/>
- <property name="forbidden-rue-excludes" value="
- org/apache/lucene/util/RamUsageEstimator.class
+ <!-- Needs to start a process -->
+ <property name="forbidden-tests-excludes" value="
+ org/apache/lucene/index/TestIndexWriterOnJRECrash.class
"/>
<!-- TODO: maybe let people get closedchannel if they cancel(true) -->
<property name="forbidden-base-excludes" value="
org/apache/lucene/store/SimpleFSDirectory.class
+ org/apache/lucene/store/SimpleFSDirectory$SimpleFSIndexInput.class
"/>
<import file="../common-build.xml"/>
Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java?rev=1624800&r1=1624799&r2=1624800&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java Sun Sep 14 02:31:31 2014
@@ -22,11 +22,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.zip.ZipFile;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
import org.junit.Assert;
/** Utility class for doing vocabulary-based stemming tests */
@@ -62,21 +64,24 @@ public class VocabularyAssert {
/** Run a vocabulary test against two data files inside a zip file */
public static void assertVocabulary(Analyzer a, Path zipFile, String voc, String out) throws IOException {
- ZipFile zip = new ZipFile(zipFile.toFile());
- InputStream v = zip.getInputStream(zip.getEntry(voc));
- InputStream o = zip.getInputStream(zip.getEntry(out));
- assertVocabulary(a, v, o);
- v.close();
- o.close();
- zip.close();
+ Path tmp = LuceneTestCase.createTempDir();
+ try (InputStream in = Files.newInputStream(zipFile)) {
+ TestUtil.unzip(in, tmp);
+ }
+ try (InputStream v = Files.newInputStream(tmp.resolve(voc));
+ InputStream o = Files.newInputStream(tmp.resolve(out))) {
+ assertVocabulary(a, v, o);
+ }
}
/** Run a vocabulary test against a tab-separated data file inside a zip file */
public static void assertVocabulary(Analyzer a, Path zipFile, String vocOut) throws IOException {
- ZipFile zip = new ZipFile(zipFile.toFile());
- InputStream vo = zip.getInputStream(zip.getEntry(vocOut));
- assertVocabulary(a, vo);
- vo.close();
- zip.close();
+ Path tmp = LuceneTestCase.createTempDir();
+ try (InputStream in = Files.newInputStream(zipFile)) {
+ TestUtil.unzip(in, tmp);
+ }
+ try (InputStream in = Files.newInputStream(tmp.resolve(vocOut))) {
+ assertVocabulary(a, in);
+ }
}
}
Modified: lucene/dev/trunk/lucene/tools/forbiddenApis/lucene.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/tools/forbiddenApis/lucene.txt?rev=1624800&r1=1624799&r2=1624800&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/tools/forbiddenApis/lucene.txt (original)
+++ lucene/dev/trunk/lucene/tools/forbiddenApis/lucene.txt Sun Sep 14 02:31:31 2014
@@ -17,4 +17,10 @@
java.io.File
java.io.FileInputStream
java.io.FileOutputStream
-# TODO: all kinds of other stuff taking "String" but making a file itself...
+java.io.PrintStream#<init>(java.lang.String,java.lang.String)
+java.io.PrintWriter#<init>(java.lang.String,java.lang.String)
+java.util.Formatter#<init>(java.lang.String,java.lang.String,java.util.Locale)
+java.io.RandomAccessFile
+java.nio.file.Path#toFile()
+java.util.jar.JarFile
+java.util.zip.ZipFile