Apache Lucene open-source search software
LUCENE-2598: fix tests to pass w/ -Dtests.directory=SimpleFSDirectory
Michael McCandless05655d8c82bd
diff --git a/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java b/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.javaindex 749dbb37576..7aef3a40fa5 100644--- a/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java+++ b/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java@@ -179,7 +179,6 @@ public class TestDeletionPolicy extends LuceneTestCase {// 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 LuceneTestCase {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 commitslastDeleteTime = System.currentTimeMillis();@@ -228,9 +229,11 @@ public class TestDeletionPolicy extends LuceneTestCase {}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 LuceneTestCase {"",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 LuceneTestCase {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) {// OKbreak;diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.javaindex aaa7787e3f8..c6db561f78f 100644--- a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java+++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java@@ -5009,20 +5009,31 @@ public class TestIndexWriter extends LuceneTestCase {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 possibledoc.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 fileswriter.rollback();diff --git a/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java b/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.javaindex 3a93fe72da8..118eb0e5682 100644--- a/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java+++ b/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java@@ -51,7 +51,8 @@ public class TestPersistentSnapshotDeletionPolicy extends TestSnapshotDeletionPo@Overrideprotected SnapshotDeletionPolicy getDeletionPolicy() throws IOException {- IndexWriter.unlock(snapshotDir);+ snapshotDir.close();+ snapshotDir = newDirectory(random);return new PersistentSnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy(), snapshotDir, OpenMode.CREATE,TEST_VERSION_CURRENT);diff --git a/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.javaindex 918ea315af9..2b5fe0fcbb5 100644--- a/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java+++ b/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java@@ -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 extends Directory {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();