You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2010/08/24 00:54:27 UTC

svn commit: r988346 - in /lucene/dev/trunk/lucene/src/test/org/apache/lucene: index/TestDeletionPolicy.java index/TestIndexWriter.java index/TestPersistentSnapshotDeletionPolicy.java store/MockDirectoryWrapper.java

Author: mikemccand
Date: Mon Aug 23 22:54:26 2010
New Revision: 988346

URL: http://svn.apache.org/viewvc?rev=988346&view=rev
Log:
LUCENE-2598: fix tests to pass w/ -Dtests.directory=SimpleFSDirectory

Modified:
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java?rev=988346&r1=988345&r2=988346&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java Mon Aug 23 22:54:26 2010
@@ -179,7 +179,6 @@ public class TestDeletionPolicy extends 
       // Any commit older than expireTime should be deleted:
       double expireTime = dir.fileModified(lastCommit.getSegmentsFileName())/1000.0 - expirationTimeSeconds;
 
-
       for (final IndexCommit commit : commits) {
         double modTime = dir.fileModified(commit.getSegmentsFileName())/1000.0;
         if (commit != lastCommit && modTime < expireTime) {
@@ -211,8 +210,10 @@ public class TestDeletionPolicy extends 
     IndexWriter writer = new IndexWriter(dir, conf);
     writer.close();
 
+    final int ITER = 8;
+
     long lastDeleteTime = 0;
-    for(int i=0;i<7;i++) {
+    for(int i=0;i<ITER;i++) {
       // Record last time when writer performed deletes of
       // past commits
       lastDeleteTime = System.currentTimeMillis();
@@ -228,9 +229,11 @@ public class TestDeletionPolicy extends 
       }
       writer.close();
 
-      // Make sure to sleep long enough so that some commit
-      // points will be deleted:
-      Thread.sleep((int) (1000.0*(SECONDS/5.0)));
+      if (i < ITER-1) {
+        // Make sure to sleep long enough so that some commit
+        // points will be deleted:
+        Thread.sleep((int) (1000.0*(SECONDS/5.0)));
+      }
     }
 
     // First, make sure the policy in fact deleted something:
@@ -246,6 +249,9 @@ public class TestDeletionPolicy extends 
                                                             "",
                                                             gen);
     dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
+
+    boolean oneSecondResolution = true;
+
     while(gen > 0) {
       try {
         IndexReader reader = IndexReader.open(dir, true);
@@ -253,8 +259,15 @@ public class TestDeletionPolicy extends 
         fileName = IndexFileNames.fileNameFromGeneration(IndexFileNames.SEGMENTS,
                                                          "",
                                                          gen);
+
+        // if we are on a filesystem that seems to have only
+        // 1 second resolution, allow +1 second in commit
+        // age tolerance:
         long modTime = dir.fileModified(fileName);
-        assertTrue("commit point was older than " + SECONDS + " seconds (" + (lastDeleteTime - modTime) + " msec) but did not get deleted", lastDeleteTime - modTime <= (SECONDS*1000));
+        oneSecondResolution &= (modTime % 1000) == 0;
+        final long leeway = (long) ((SECONDS + (oneSecondResolution ? 1.0:0.0))*1000);
+
+        assertTrue("commit point was older than " + SECONDS + " seconds (" + (lastDeleteTime - modTime) + " msec) but did not get deleted ", lastDeleteTime - modTime <= leeway);
       } catch (IOException e) {
         // OK
         break;

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=988346&r1=988345&r2=988346&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Mon Aug 23 22:54:26 2010
@@ -5009,20 +5009,31 @@ public class TestIndexWriter extends Luc
     IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(random, 
         TEST_VERSION_CURRENT, new MockAnalyzer())
         .setMaxBufferedDocs(2));
-    // Creating over empty dir should not create any files.
-    assertEquals(0, dir.listAll().length);
+    String[] files = dir.listAll();
+
+    // Creating over empty dir should not create any files,
+    // or, at most the write.lock file
+    final int extraFileCount;
+    if (files.length == 1) {
+      assertEquals("write.lock", files[0]);
+      extraFileCount = 1;
+    } else {
+      assertEquals(0, files.length);
+      extraFileCount = 0;
+    }
+
     Document doc = new Document();
     // create as many files as possible
     doc.add(new Field("c", "val", Store.YES, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));
     writer.addDocument(doc);
     // Adding just one document does not call flush yet.
-    assertEquals("only the stored and term vector files should exist in the directory", 5, dir.listAll().length);
+    assertEquals("only the stored and term vector files should exist in the directory", 5 + extraFileCount, dir.listAll().length);
     
     doc = new Document();
     doc.add(new Field("c", "val", Store.YES, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));
     writer.addDocument(doc);
     // The second document should cause a flush.
-    assertTrue("flush should have occurred and files created", dir.listAll().length > 5);
+    assertTrue("flush should have occurred and files created", dir.listAll().length > 5 + extraFileCount);
    
     // After rollback, IW should remove all files
     writer.rollback();

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java?rev=988346&r1=988345&r2=988346&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java Mon Aug 23 22:54:26 2010
@@ -51,7 +51,8 @@ public class TestPersistentSnapshotDelet
   
   @Override
   protected SnapshotDeletionPolicy getDeletionPolicy() throws IOException {
-    IndexWriter.unlock(snapshotDir);
+    snapshotDir.close();
+    snapshotDir = newDirectory(random);
     return new PersistentSnapshotDeletionPolicy(
         new KeepOnlyLastCommitDeletionPolicy(), snapshotDir, OpenMode.CREATE,
         TEST_VERSION_CURRENT);

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java?rev=988346&r1=988345&r2=988346&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java Mon Aug 23 22:54:26 2010
@@ -20,7 +20,6 @@ package org.apache.lucene.store;
 import java.io.IOException;
 import java.io.FileNotFoundException;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.Random;
 import java.util.Map;
@@ -95,6 +94,11 @@ public class MockDirectoryWrapper extend
     delegate.sync(names);
   }
   
+  @Override
+  public String toString() {
+    return "MockDirWrapper(" + delegate + ")";
+  }
+
   public synchronized final long sizeInBytes() throws IOException {
     if (delegate instanceof RAMDirectory)
       return ((RAMDirectory) delegate).sizeInBytes();