diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java b/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java index 53c9cc8e56a..a28bd9dd3af 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java @@ -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)}. *

Warning: This tool may reorder documents if the index was partially * 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 @@ -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 = new ArrayList<>(); - if (random().nextBoolean()) { - args.add("-verbose"); - } - if (random().nextBoolean()) { - args.add("-delete-prior-commits"); - } - if (random().nextBoolean()) { - // TODO: need to better randomize this, but ... - // - LuceneTestCase.FS_DIRECTORIES is private - // - newFSDirectory returns BaseDirectoryWrapper - // - BaseDirectoryWrapper doesn't expose delegate - Class dirImpl = random().nextBoolean() ? - SimpleFSDirectory.class : NIOFSDirectory.class; - - args.add("-dir-impl"); - args.add(dirImpl.getName()); - } - args.add(path); - - IndexUpgrader upgrader = null; - try { - upgrader = IndexUpgrader.parseArgs(args.toArray(new String[0])); - } catch (Exception e) { - throw new AssertionError("unable to parse args: " + args, e); - } - upgrader.upgrade(); - - Directory upgradedDir = newFSDirectory(dir); - try { - checkAllSegmentsUpgraded(upgradedDir); - } finally { - upgradedDir.close(); + 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()); + TestUtil.unzip(dataFile, dir); + + String path = dir.getAbsolutePath(); + + List args = new ArrayList<>(); + if (random().nextBoolean()) { + args.add("-verbose"); + } + if (random().nextBoolean()) { + args.add("-delete-prior-commits"); + } + if (random().nextBoolean()) { + // TODO: need to better randomize this, but ... + // - LuceneTestCase.FS_DIRECTORIES is private + // - newFSDirectory returns BaseDirectoryWrapper + // - BaseDirectoryWrapper doesn't expose delegate + Class dirImpl = random().nextBoolean() ? + SimpleFSDirectory.class : NIOFSDirectory.class; + + args.add("-dir-impl"); + args.add(dirImpl.getName()); + } + args.add(path); + + IndexUpgrader upgrader = null; + try { + upgrader = IndexUpgrader.parseArgs(args.toArray(new String[0])); + } catch (Exception e) { + throw new AssertionError("unable to parse args: " + args, e); + } + upgrader.upgrade(); + + Directory upgradedDir = newFSDirectory(dir); + try { + checkAllSegmentsUpgraded(upgradedDir); + } finally { + upgradedDir.close(); + } } + } finally { + System.setOut(savedSystemOut); } } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCrash.java b/lucene/core/src/test/org/apache/lucene/index/TestCrash.java index 67028092f61..dc76df03b2b 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestCrash.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestCrash.java @@ -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. - System.out.println("TEST: initIndex"); + if (VERBOSE) { + System.out.println("TEST: initIndex"); + } IndexWriter writer = initIndex(random(), true); - System.out.println("TEST: done initIndex"); + 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); - System.out.println("TEST: now crash"); + if (VERBOSE) { + System.out.println("TEST: now crash"); + } crash(writer); writer = initIndex(random(), dir, false); writer.shutdown(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java index 3f4def601a7..923566bc08e 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java @@ -279,8 +279,10 @@ public class TestDocValuesIndexing extends LuceneTestCase { fail("didn't hit expected exception"); } catch (IllegalArgumentException expected) { // expected - System.out.println("hit exc:"); - expected.printStackTrace(System.out); + if (VERBOSE) { + System.out.println("hit exc:"); + expected.printStackTrace(System.out); + } } iwriter.shutdown(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java index 0a96b6bfcd0..da00399cf57 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -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 - 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")); } w.rollback();