/// <summary> /// index 1 document and commit. /// prepare for crashing. /// index 1 more document, and upon commit, creation of segments_2 will crash. /// </summary> private void IndexAndCrashOnCreateOutputSegments2() { Directory realDirectory = FSDirectory.Open(Path); CrashAfterCreateOutput crashAfterCreateOutput = new CrashAfterCreateOutput(realDirectory); // NOTE: cannot use RandomIndexWriter because it // sometimes commits: IndexWriter indexWriter = new IndexWriter(crashAfterCreateOutput, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))); indexWriter.AddDocument(Document); // writes segments_1: indexWriter.Commit(); crashAfterCreateOutput.GetCrashAfterCreateOutput = "segments_2"; indexWriter.AddDocument(Document); try { // tries to write segments_2 but hits fake exc: indexWriter.Commit(); Assert.Fail("should have hit CrashingException"); } #pragma warning disable 168 catch (CrashingException e) #pragma warning restore 168 { // expected } // writes segments_3 indexWriter.Dispose(); Assert.IsFalse(SlowFileExists(realDirectory, "segments_2")); crashAfterCreateOutput.Dispose(); }
/// <summary> /// index 1 document and commit. /// prepare for crashing. /// index 1 more document, and upon commit, creation of segments_2 will crash. /// </summary> private void IndexAndCrashOnCreateOutputSegments2() { Directory realDirectory = FSDirectory.Open(Path); CrashAfterCreateOutput crashAfterCreateOutput = new CrashAfterCreateOutput(realDirectory); // NOTE: cannot use RandomIndexWriter because it // sometimes commits: IndexWriter indexWriter = new IndexWriter(crashAfterCreateOutput, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))); indexWriter.AddDocument(Document); // writes segments_1: indexWriter.Commit(); crashAfterCreateOutput.GetCrashAfterCreateOutput = "segments_2"; indexWriter.AddDocument(Document); try { // tries to write segments_2 but hits fake exc: indexWriter.Commit(); Assert.Fail("should have hit CrashingException"); } catch (CrashingException e) { // expected } // writes segments_3 indexWriter.Dispose(); Assert.IsFalse(SlowFileExists(realDirectory, "segments_2")); crashAfterCreateOutput.Dispose(); }