diff -r ca6e1405afd6 lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java --- a/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java Mon Aug 23 17:22:37 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/index/TestDeletionPolicy.java Mon Aug 23 17:32:57 2010 -0400 @@ -179,7 +179,6 @@ // 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 @@ 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 0) { try { IndexReader reader = IndexReader.open(dir, true); @@ -253,8 +259,15 @@ 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; diff -r ca6e1405afd6 lucene/src/test/org/apache/lucene/index/TestIndexWriter.java --- a/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Mon Aug 23 17:22:37 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Mon Aug 23 17:32:57 2010 -0400 @@ -5009,20 +5009,31 @@ 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(); diff -r ca6e1405afd6 lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java --- a/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java Mon Aug 23 17:22:37 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/index/TestPersistentSnapshotDeletionPolicy.java Mon Aug 23 17:32:57 2010 -0400 @@ -27,6 +27,7 @@ import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockObtainFailedException; +import org.apache.lucene.store.LockReleaseFailedException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -51,7 +52,8 @@ @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); diff -r ca6e1405afd6 lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java --- a/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java Mon Aug 23 17:22:37 2010 +0000 +++ b/lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java Mon Aug 23 17:32:57 2010 -0400 @@ -95,6 +95,11 @@ 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();