LUCENE-5945: more test cleanups

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1624800 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-09-14 02:31:31 +00:00
parent af287593c8
commit 535454eb25
6 changed files with 82 additions and 55 deletions

View File

@ -18,17 +18,16 @@ package org.apache.lucene.analysis.hunspell;
*/
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 LuceneTestCase {
};
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 LuceneTestCase {
}
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 dictionary = zip.getInputStream(dicEntry);
InputStream affix = zip.getInputStream(affEntry)) {
new Dictionary(affix, dictionary);
}
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)) {
new Dictionary(affix, dictionary);
}
}
}
}

View File

@ -18,16 +18,15 @@ package org.apache.lucene.analysis.hunspell;
*/
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 extends LuceneTestCase {
};
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 extends LuceneTestCase {
}
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 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)) {
new Dictionary(affix, dictionary);
}
}
}
}
}

View File

@ -24,7 +24,6 @@ import org.apache.lucene.index.DirectoryReader;
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);

View File

@ -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"/>

View File

@ -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);
}
}
}

View File

@ -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