lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1393090 - in /lucene/dev/branches/lucene4456/lucene/core/src: java/org/apache/lucene/index/IndexWriter.java test/org/apache/lucene/index/TestCrash.java
Date Tue, 02 Oct 2012 18:43:35 GMT
Author: mikemccand
Date: Tue Oct  2 18:43:35 2012
New Revision: 1393090

URL: http://svn.apache.org/viewvc?rev=1393090&view=rev
Log:
LUCENE-4456: fix TestCrash

Modified:
    lucene/dev/branches/lucene4456/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/dev/branches/lucene4456/lucene/core/src/test/org/apache/lucene/index/TestCrash.java

Modified: lucene/dev/branches/lucene4456/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4456/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java?rev=1393090&r1=1393089&r2=1393090&view=diff
==============================================================================
--- lucene/dev/branches/lucene4456/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
(original)
+++ lucene/dev/branches/lucene4456/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
Tue Oct  2 18:43:35 2012
@@ -2145,7 +2145,7 @@ public class IndexWriter implements Clos
         // Now build compound file
         Collection<String> oldFiles = createCompoundFile(infoStream, directory, MergeState.CheckAbort.NONE,
newSegment.info, context);
         newSegment.info.setUseCompoundFile(true);
-        
+
         synchronized(this) {
           deleter.deleteNewFiles(oldFiles);
         }

Modified: lucene/dev/branches/lucene4456/lucene/core/src/test/org/apache/lucene/index/TestCrash.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4456/lucene/core/src/test/org/apache/lucene/index/TestCrash.java?rev=1393090&r1=1393089&r2=1393090&view=diff
==============================================================================
--- lucene/dev/branches/lucene4456/lucene/core/src/test/org/apache/lucene/index/TestCrash.java
(original)
+++ lucene/dev/branches/lucene4456/lucene/core/src/test/org/apache/lucene/index/TestCrash.java
Tue Oct  2 18:43:35 2012
@@ -20,12 +20,13 @@ package org.apache.lucene.index;
 import java.io.IOException;
 import java.util.Random;
 
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.store.NoLockFactory;
-import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.document.Document;
+import org.apache.lucene.util.LuceneTestCase;
 
 public class TestCrash extends LuceneTestCase {
 
@@ -67,20 +68,42 @@ public class TestCrash extends LuceneTes
     // before any documents were added.
     IndexWriter writer = initIndex(random(), true);
     MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
+
+    // We create leftover files because merging could be
+    // running when we crash:
+    dir.setAssertNoUnrefencedFilesOnClose(false);
+
     crash(writer);
+
     IndexReader reader = DirectoryReader.open(dir);
     assertTrue(reader.numDocs() < 157);
     reader.close();
+
+    // Make a new dir, copying from the crashed dir, and
+    // open IW on it, to confirm IW "recovers" after a
+    // crash:
+    Directory dir2 = newDirectory(dir);
     dir.close();
+
+    new RandomIndexWriter(random(), dir2).close();
+    dir2.close();
   }
 
   public void testWriterAfterCrash() throws IOException {
     // 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");
     IndexWriter writer = initIndex(random(), true);
+    System.out.println("TEST: done initIndex");
     MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
+
+    // We create leftover files because merging could be
+    // running / store files could be open when we crash:
+    dir.setAssertNoUnrefencedFilesOnClose(false);
+
     dir.setPreventDoubleWrite(false);
+    System.out.println("TEST: now crash");
     crash(writer);
     writer = initIndex(random(), dir, false);
     writer.close();
@@ -88,12 +111,25 @@ public class TestCrash extends LuceneTes
     IndexReader reader = DirectoryReader.open(dir);
     assertTrue(reader.numDocs() < 314);
     reader.close();
+
+    // Make a new dir, copying from the crashed dir, and
+    // open IW on it, to confirm IW "recovers" after a
+    // crash:
+    Directory dir2 = newDirectory(dir);
     dir.close();
+
+    new RandomIndexWriter(random(), dir2).close();
+    dir2.close();
   }
 
   public void testCrashAfterReopen() throws IOException {
     IndexWriter writer = initIndex(random(), false);
     MockDirectoryWrapper dir = (MockDirectoryWrapper) writer.getDirectory();
+
+    // We create leftover files because merging could be
+    // running when we crash:
+    dir.setAssertNoUnrefencedFilesOnClose(false);
+
     writer.close();
     writer = initIndex(random(), dir, false);
     assertEquals(314, writer.maxDoc());
@@ -111,7 +147,15 @@ public class TestCrash extends LuceneTes
     IndexReader reader = DirectoryReader.open(dir);
     assertTrue(reader.numDocs() >= 157);
     reader.close();
+
+    // Make a new dir, copying from the crashed dir, and
+    // open IW on it, to confirm IW "recovers" after a
+    // crash:
+    Directory dir2 = newDirectory(dir);
     dir.close();
+
+    new RandomIndexWriter(random(), dir2).close();
+    dir2.close();
   }
 
   public void testCrashAfterClose() throws IOException {



Mime
View raw message