mirror of https://github.com/apache/lucene.git
LUCENE-5622: fix noisy tests
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1589104 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d3e43ba112
commit
ae38f96887
|
@ -22,6 +22,7 @@ import org.apache.lucene.store.FSDirectory;
|
||||||
import org.apache.lucene.util.CommandLineUtil;
|
import org.apache.lucene.util.CommandLineUtil;
|
||||||
import org.apache.lucene.util.Constants;
|
import org.apache.lucene.util.Constants;
|
||||||
import org.apache.lucene.util.InfoStream;
|
import org.apache.lucene.util.InfoStream;
|
||||||
|
import org.apache.lucene.util.PrintStreamInfoStream;
|
||||||
import org.apache.lucene.util.Version;
|
import org.apache.lucene.util.Version;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -42,7 +43,7 @@ import java.util.Collection;
|
||||||
* refuses to run by default. Specify {@code -delete-prior-commits}
|
* refuses to run by default. Specify {@code -delete-prior-commits}
|
||||||
* to override this, allowing the tool to delete all but the last commit.
|
* to override this, allowing the tool to delete all but the last commit.
|
||||||
* From Java code this can be enabled by passing {@code true} to
|
* From Java code this can be enabled by passing {@code true} to
|
||||||
* {@link #IndexUpgrader(Directory,Version,PrintStream,boolean)}.
|
* {@link #IndexUpgrader(Directory,Version,InfoStream,boolean)}.
|
||||||
* <p><b>Warning:</b> This tool may reorder documents if the index was partially
|
* <p><b>Warning:</b> This tool may reorder documents if the index was partially
|
||||||
* upgraded before execution (e.g., documents were added). If your application relies
|
* upgraded before execution (e.g., documents were added). If your application relies
|
||||||
* on "monotonicity" of doc IDs (which means that the order in which the documents
|
* on "monotonicity" of doc IDs (which means that the order in which the documents
|
||||||
|
@ -76,7 +77,7 @@ public final class IndexUpgrader {
|
||||||
static IndexUpgrader parseArgs(String[] args) throws IOException {
|
static IndexUpgrader parseArgs(String[] args) throws IOException {
|
||||||
String path = null;
|
String path = null;
|
||||||
boolean deletePriorCommits = false;
|
boolean deletePriorCommits = false;
|
||||||
PrintStream out = null;
|
InfoStream out = null;
|
||||||
String dirImpl = null;
|
String dirImpl = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i<args.length) {
|
while (i<args.length) {
|
||||||
|
@ -84,7 +85,7 @@ public final class IndexUpgrader {
|
||||||
if ("-delete-prior-commits".equals(arg)) {
|
if ("-delete-prior-commits".equals(arg)) {
|
||||||
deletePriorCommits = true;
|
deletePriorCommits = true;
|
||||||
} else if ("-verbose".equals(arg)) {
|
} else if ("-verbose".equals(arg)) {
|
||||||
out = System.out;
|
out = new PrintStreamInfoStream(System.out);
|
||||||
} else if ("-dir-impl".equals(arg)) {
|
} else if ("-dir-impl".equals(arg)) {
|
||||||
if (i == args.length - 1) {
|
if (i == args.length - 1) {
|
||||||
System.out.println("ERROR: missing value for -dir-impl option");
|
System.out.println("ERROR: missing value for -dir-impl option");
|
||||||
|
@ -125,7 +126,7 @@ public final class IndexUpgrader {
|
||||||
/** Creates index upgrader on the given directory, using an {@link IndexWriter} using the given
|
/** Creates index upgrader on the given directory, using an {@link IndexWriter} using the given
|
||||||
* {@code matchVersion}. You have the possibility to upgrade indexes with multiple commit points by removing
|
* {@code matchVersion}. You have the possibility to upgrade indexes with multiple commit points by removing
|
||||||
* all older ones. If {@code infoStream} is not {@code null}, all logging output will be sent to this stream. */
|
* all older ones. If {@code infoStream} is not {@code null}, all logging output will be sent to this stream. */
|
||||||
public IndexUpgrader(Directory dir, Version matchVersion, PrintStream infoStream, boolean deletePriorCommits) {
|
public IndexUpgrader(Directory dir, Version matchVersion, InfoStream infoStream, boolean deletePriorCommits) {
|
||||||
this(dir, new IndexWriterConfig(matchVersion, null), deletePriorCommits);
|
this(dir, new IndexWriterConfig(matchVersion, null), deletePriorCommits);
|
||||||
if (null != infoStream) {
|
if (null != infoStream) {
|
||||||
this.iwc.setInfoStream(infoStream);
|
this.iwc.setInfoStream(infoStream);
|
||||||
|
|
|
@ -61,6 +61,7 @@ import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.Constants;
|
import org.apache.lucene.util.Constants;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
|
import org.apache.lucene.util.InfoStream;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
|
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
|
||||||
import org.apache.lucene.util.StringHelper;
|
import org.apache.lucene.util.StringHelper;
|
||||||
|
@ -213,7 +214,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 0: return new IndexUpgrader(dir, TEST_VERSION_CURRENT);
|
case 0: return new IndexUpgrader(dir, TEST_VERSION_CURRENT);
|
||||||
case 1: return new IndexUpgrader(dir, TEST_VERSION_CURRENT,
|
case 1: return new IndexUpgrader(dir, TEST_VERSION_CURRENT,
|
||||||
streamType ? null : System.err, false);
|
streamType ? null : InfoStream.NO_OUTPUT, false);
|
||||||
case 2: return new IndexUpgrader(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, null), false);
|
case 2: return new IndexUpgrader(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, null), false);
|
||||||
default: fail("case statement didn't get updated when random bounds changed");
|
default: fail("case statement didn't get updated when random bounds changed");
|
||||||
}
|
}
|
||||||
|
@ -876,47 +877,53 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
|
||||||
|
|
||||||
public void testCommandLineArgs() throws Exception {
|
public void testCommandLineArgs() throws Exception {
|
||||||
|
|
||||||
for (String name : oldIndexDirs.keySet()) {
|
PrintStream savedSystemOut = System.out;
|
||||||
File dir = createTempDir(name);
|
System.setOut(new PrintStream(new ByteArrayOutputStream(), false, "UTF-8"));
|
||||||
File dataFile = new File(TestBackwardsCompatibility.class.getResource("index." + name + ".zip").toURI());
|
try {
|
||||||
TestUtil.unzip(dataFile, dir);
|
for (String name : oldIndexDirs.keySet()) {
|
||||||
|
File dir = createTempDir(name);
|
||||||
String path = dir.getAbsolutePath();
|
File dataFile = new File(TestBackwardsCompatibility.class.getResource("index." + name + ".zip").toURI());
|
||||||
|
TestUtil.unzip(dataFile, dir);
|
||||||
List<String> args = new ArrayList<>();
|
|
||||||
if (random().nextBoolean()) {
|
String path = dir.getAbsolutePath();
|
||||||
args.add("-verbose");
|
|
||||||
}
|
List<String> args = new ArrayList<>();
|
||||||
if (random().nextBoolean()) {
|
if (random().nextBoolean()) {
|
||||||
args.add("-delete-prior-commits");
|
args.add("-verbose");
|
||||||
}
|
}
|
||||||
if (random().nextBoolean()) {
|
if (random().nextBoolean()) {
|
||||||
// TODO: need to better randomize this, but ...
|
args.add("-delete-prior-commits");
|
||||||
// - LuceneTestCase.FS_DIRECTORIES is private
|
}
|
||||||
// - newFSDirectory returns BaseDirectoryWrapper
|
if (random().nextBoolean()) {
|
||||||
// - BaseDirectoryWrapper doesn't expose delegate
|
// TODO: need to better randomize this, but ...
|
||||||
Class<? extends FSDirectory> dirImpl = random().nextBoolean() ?
|
// - LuceneTestCase.FS_DIRECTORIES is private
|
||||||
SimpleFSDirectory.class : NIOFSDirectory.class;
|
// - newFSDirectory returns BaseDirectoryWrapper
|
||||||
|
// - BaseDirectoryWrapper doesn't expose delegate
|
||||||
args.add("-dir-impl");
|
Class<? extends FSDirectory> dirImpl = random().nextBoolean() ?
|
||||||
args.add(dirImpl.getName());
|
SimpleFSDirectory.class : NIOFSDirectory.class;
|
||||||
}
|
|
||||||
args.add(path);
|
args.add("-dir-impl");
|
||||||
|
args.add(dirImpl.getName());
|
||||||
IndexUpgrader upgrader = null;
|
}
|
||||||
try {
|
args.add(path);
|
||||||
upgrader = IndexUpgrader.parseArgs(args.toArray(new String[0]));
|
|
||||||
} catch (Exception e) {
|
IndexUpgrader upgrader = null;
|
||||||
throw new AssertionError("unable to parse args: " + args, e);
|
try {
|
||||||
}
|
upgrader = IndexUpgrader.parseArgs(args.toArray(new String[0]));
|
||||||
upgrader.upgrade();
|
} catch (Exception e) {
|
||||||
|
throw new AssertionError("unable to parse args: " + args, e);
|
||||||
Directory upgradedDir = newFSDirectory(dir);
|
}
|
||||||
try {
|
upgrader.upgrade();
|
||||||
checkAllSegmentsUpgraded(upgradedDir);
|
|
||||||
} finally {
|
Directory upgradedDir = newFSDirectory(dir);
|
||||||
upgradedDir.close();
|
try {
|
||||||
|
checkAllSegmentsUpgraded(upgradedDir);
|
||||||
|
} finally {
|
||||||
|
upgradedDir.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
System.setOut(savedSystemOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,9 +93,13 @@ public class TestCrash extends LuceneTestCase {
|
||||||
// This test relies on being able to open a reader before any commit
|
// This test relies on being able to open a reader before any commit
|
||||||
// happened, so we must create an initial commit just to allow that, but
|
// happened, so we must create an initial commit just to allow that, but
|
||||||
// before any documents were added.
|
// before any documents were added.
|
||||||
System.out.println("TEST: initIndex");
|
if (VERBOSE) {
|
||||||
|
System.out.println("TEST: initIndex");
|
||||||
|
}
|
||||||
IndexWriter writer = initIndex(random(), true);
|
IndexWriter writer = initIndex(random(), true);
|
||||||
System.out.println("TEST: done initIndex");
|
if (VERBOSE) {
|
||||||
|
System.out.println("TEST: done initIndex");
|
||||||
|
}
|
||||||
MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
|
MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
|
||||||
|
|
||||||
// We create leftover files because merging could be
|
// We create leftover files because merging could be
|
||||||
|
@ -103,7 +107,9 @@ public class TestCrash extends LuceneTestCase {
|
||||||
dir.setAssertNoUnrefencedFilesOnClose(false);
|
dir.setAssertNoUnrefencedFilesOnClose(false);
|
||||||
|
|
||||||
dir.setPreventDoubleWrite(false);
|
dir.setPreventDoubleWrite(false);
|
||||||
System.out.println("TEST: now crash");
|
if (VERBOSE) {
|
||||||
|
System.out.println("TEST: now crash");
|
||||||
|
}
|
||||||
crash(writer);
|
crash(writer);
|
||||||
writer = initIndex(random(), dir, false);
|
writer = initIndex(random(), dir, false);
|
||||||
writer.shutdown();
|
writer.shutdown();
|
||||||
|
|
|
@ -279,8 +279,10 @@ public class TestDocValuesIndexing extends LuceneTestCase {
|
||||||
fail("didn't hit expected exception");
|
fail("didn't hit expected exception");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (IllegalArgumentException expected) {
|
||||||
// expected
|
// expected
|
||||||
System.out.println("hit exc:");
|
if (VERBOSE) {
|
||||||
expected.printStackTrace(System.out);
|
System.out.println("hit exc:");
|
||||||
|
expected.printStackTrace(System.out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iwriter.shutdown();
|
iwriter.shutdown();
|
||||||
|
|
|
@ -17,8 +17,11 @@ package org.apache.lucene.index;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -990,6 +993,8 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
volatile boolean allowInterrupt = false;
|
volatile boolean allowInterrupt = false;
|
||||||
final Random random;
|
final Random random;
|
||||||
final Directory adder;
|
final Directory adder;
|
||||||
|
final ByteArrayOutputStream bytesLog = new ByteArrayOutputStream();
|
||||||
|
final PrintStream log = new PrintStream(bytesLog, true, IOUtils.UTF_8);
|
||||||
|
|
||||||
IndexerThreadInterrupt() throws IOException {
|
IndexerThreadInterrupt() throws IOException {
|
||||||
this.random = new Random(random().nextLong());
|
this.random = new Random(random().nextLong());
|
||||||
|
@ -1126,27 +1131,27 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
// on!! This test doesn't repro easily so when
|
// on!! This test doesn't repro easily so when
|
||||||
// Jenkins hits a fail we need to study where the
|
// Jenkins hits a fail we need to study where the
|
||||||
// interrupts struck!
|
// interrupts struck!
|
||||||
System.out.println("TEST: got interrupt");
|
log.println("TEST: got interrupt");
|
||||||
re.printStackTrace(System.out);
|
re.printStackTrace(log);
|
||||||
Throwable e = re.getCause();
|
Throwable e = re.getCause();
|
||||||
assertTrue(e instanceof InterruptedException);
|
assertTrue(e instanceof InterruptedException);
|
||||||
if (finish) {
|
if (finish) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
System.out.println("FAILED; unexpected exception");
|
log.println("FAILED; unexpected exception");
|
||||||
t.printStackTrace(System.out);
|
t.printStackTrace(log);
|
||||||
failed = true;
|
failed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VERBOSE) {
|
if (VERBOSE) {
|
||||||
System.out.println("TEST: now finish failed=" + failed);
|
log.println("TEST: now finish failed=" + failed);
|
||||||
}
|
}
|
||||||
if (!failed) {
|
if (!failed) {
|
||||||
if (VERBOSE) {
|
if (VERBOSE) {
|
||||||
System.out.println("TEST: now rollback");
|
log.println("TEST: now rollback");
|
||||||
}
|
}
|
||||||
// clear interrupt state:
|
// clear interrupt state:
|
||||||
Thread.interrupted();
|
Thread.interrupted();
|
||||||
|
@ -1162,8 +1167,8 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
TestUtil.checkIndex(dir);
|
TestUtil.checkIndex(dir);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
failed = true;
|
failed = true;
|
||||||
System.out.println("CheckIndex FAILED: unexpected exception");
|
log.println("CheckIndex FAILED: unexpected exception");
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(log);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
IndexReader r = DirectoryReader.open(dir);
|
IndexReader r = DirectoryReader.open(dir);
|
||||||
|
@ -1171,8 +1176,8 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
r.close();
|
r.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
failed = true;
|
failed = true;
|
||||||
System.out.println("DirectoryReader.open FAILED: unexpected exception");
|
log.println("DirectoryReader.open FAILED: unexpected exception");
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -1216,7 +1221,9 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
t.finish = true;
|
t.finish = true;
|
||||||
t.join();
|
t.join();
|
||||||
assertFalse(t.failed);
|
if (t.failed) {
|
||||||
|
fail(new String(t.bytesLog.toString("UTF-8")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** testThreadInterruptDeadlock but with 2 indexer threads */
|
/** testThreadInterruptDeadlock but with 2 indexer threads */
|
||||||
|
@ -2499,7 +2506,9 @@ public class TestIndexWriter extends LuceneTestCase {
|
||||||
fail("didn't hit exception");
|
fail("didn't hit exception");
|
||||||
} catch (RuntimeException re) {
|
} catch (RuntimeException re) {
|
||||||
// expected
|
// expected
|
||||||
System.out.println("GOT: " + re.getMessage());
|
if (VERBOSE) {
|
||||||
|
System.out.println("GOT: " + re.getMessage());
|
||||||
|
}
|
||||||
assertTrue(re.getMessage().contains("this writer is closed, but some pending changes or running merges were discarded"));
|
assertTrue(re.getMessage().contains("this writer is closed, but some pending changes or running merges were discarded"));
|
||||||
}
|
}
|
||||||
w.rollback();
|
w.rollback();
|
||||||
|
|
Loading…
Reference in New Issue