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:
Robert Muir 2014-04-22 12:19:37 +00:00
parent d3e43ba112
commit ae38f96887
5 changed files with 87 additions and 62 deletions

View File

@ -22,6 +22,7 @@ import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.CommandLineUtil;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.PrintStreamInfoStream;
import org.apache.lucene.util.Version;
import java.io.File;
@ -42,7 +43,7 @@ import java.util.Collection;
* refuses to run by default. Specify {@code -delete-prior-commits}
* 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
* {@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
* upgraded before execution (e.g., documents were added). If your application relies
* on &quot;monotonicity&quot; 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 {
String path = null;
boolean deletePriorCommits = false;
PrintStream out = null;
InfoStream out = null;
String dirImpl = null;
int i = 0;
while (i<args.length) {
@ -84,7 +85,7 @@ public final class IndexUpgrader {
if ("-delete-prior-commits".equals(arg)) {
deletePriorCommits = true;
} else if ("-verbose".equals(arg)) {
out = System.out;
out = new PrintStreamInfoStream(System.out);
} else if ("-dir-impl".equals(arg)) {
if (i == args.length - 1) {
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
* {@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. */
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);
if (null != infoStream) {
this.iwc.setInfoStream(infoStream);

View File

@ -61,6 +61,7 @@ import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.StringHelper;
@ -213,7 +214,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
switch (choice) {
case 0: 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);
default: fail("case statement didn't get updated when random bounds changed");
}
@ -876,6 +877,9 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
public void testCommandLineArgs() throws Exception {
PrintStream savedSystemOut = System.out;
System.setOut(new PrintStream(new ByteArrayOutputStream(), false, "UTF-8"));
try {
for (String name : oldIndexDirs.keySet()) {
File dir = createTempDir(name);
File dataFile = new File(TestBackwardsCompatibility.class.getResource("index." + name + ".zip").toURI());
@ -918,6 +922,9 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
upgradedDir.close();
}
}
} finally {
System.setOut(savedSystemOut);
}
}
public void testUpgradeOldSingleSegmentIndexWithAdditions() throws Exception {

View File

@ -93,9 +93,13 @@ public class TestCrash extends LuceneTestCase {
// 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
// before any documents were added.
if (VERBOSE) {
System.out.println("TEST: initIndex");
}
IndexWriter writer = initIndex(random(), true);
if (VERBOSE) {
System.out.println("TEST: done initIndex");
}
MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
// We create leftover files because merging could be
@ -103,7 +107,9 @@ public class TestCrash extends LuceneTestCase {
dir.setAssertNoUnrefencedFilesOnClose(false);
dir.setPreventDoubleWrite(false);
if (VERBOSE) {
System.out.println("TEST: now crash");
}
crash(writer);
writer = initIndex(random(), dir, false);
writer.shutdown();

View File

@ -279,9 +279,11 @@ public class TestDocValuesIndexing extends LuceneTestCase {
fail("didn't hit expected exception");
} catch (IllegalArgumentException expected) {
// expected
if (VERBOSE) {
System.out.println("hit exc:");
expected.printStackTrace(System.out);
}
}
iwriter.shutdown();
directory.close();

View File

@ -17,8 +17,11 @@ package org.apache.lucene.index;
* limitations under the License.
*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -990,6 +993,8 @@ public class TestIndexWriter extends LuceneTestCase {
volatile boolean allowInterrupt = false;
final Random random;
final Directory adder;
final ByteArrayOutputStream bytesLog = new ByteArrayOutputStream();
final PrintStream log = new PrintStream(bytesLog, true, IOUtils.UTF_8);
IndexerThreadInterrupt() throws IOException {
this.random = new Random(random().nextLong());
@ -1126,27 +1131,27 @@ public class TestIndexWriter extends LuceneTestCase {
// on!! This test doesn't repro easily so when
// Jenkins hits a fail we need to study where the
// interrupts struck!
System.out.println("TEST: got interrupt");
re.printStackTrace(System.out);
log.println("TEST: got interrupt");
re.printStackTrace(log);
Throwable e = re.getCause();
assertTrue(e instanceof InterruptedException);
if (finish) {
break;
}
} catch (Throwable t) {
System.out.println("FAILED; unexpected exception");
t.printStackTrace(System.out);
log.println("FAILED; unexpected exception");
t.printStackTrace(log);
failed = true;
break;
}
}
if (VERBOSE) {
System.out.println("TEST: now finish failed=" + failed);
log.println("TEST: now finish failed=" + failed);
}
if (!failed) {
if (VERBOSE) {
System.out.println("TEST: now rollback");
log.println("TEST: now rollback");
}
// clear interrupt state:
Thread.interrupted();
@ -1162,8 +1167,8 @@ public class TestIndexWriter extends LuceneTestCase {
TestUtil.checkIndex(dir);
} catch (Exception e) {
failed = true;
System.out.println("CheckIndex FAILED: unexpected exception");
e.printStackTrace(System.out);
log.println("CheckIndex FAILED: unexpected exception");
e.printStackTrace(log);
}
try {
IndexReader r = DirectoryReader.open(dir);
@ -1171,8 +1176,8 @@ public class TestIndexWriter extends LuceneTestCase {
r.close();
} catch (Exception e) {
failed = true;
System.out.println("DirectoryReader.open FAILED: unexpected exception");
e.printStackTrace(System.out);
log.println("DirectoryReader.open FAILED: unexpected exception");
e.printStackTrace(log);
}
}
try {
@ -1216,7 +1221,9 @@ public class TestIndexWriter extends LuceneTestCase {
}
t.finish = true;
t.join();
assertFalse(t.failed);
if (t.failed) {
fail(new String(t.bytesLog.toString("UTF-8")));
}
}
/** testThreadInterruptDeadlock but with 2 indexer threads */
@ -2499,7 +2506,9 @@ public class TestIndexWriter extends LuceneTestCase {
fail("didn't hit exception");
} catch (RuntimeException re) {
// expected
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"));
}
w.rollback();