Apache Lucene open-source search software
LUCENE-1375: added IndexCommit.getTimestamp method
Michael McCandlesse6dcf1462061
diff --git a/CHANGES.txt b/CHANGES.txtindex ff5a4e4989b..46a12913bc7 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -145,6 +145,10 @@ API Changesconstructor and fields from package to protected. (Shai Ereravia Doron Cohen)+24. LUCENE-1375: Added convencience method IndexCommit.getTimestamp,+ which is equivalent to+ getDirectory().fileModified(getSegmentsFileName()). (Mike McCandless)+Bug fixes1. LUCENE-1134: Fixed BooleanQuery.rewrite to only optimize a singlediff --git a/src/java/org/apache/lucene/index/IndexCommit.java b/src/java/org/apache/lucene/index/IndexCommit.javaindex 8836d719316..eb5146764a9 100644--- a/src/java/org/apache/lucene/index/IndexCommit.java+++ b/src/java/org/apache/lucene/index/IndexCommit.java@@ -112,4 +112,12 @@ public abstract class IndexCommit implements IndexCommitPoint {public long getGeneration() {throw new UnsupportedOperationException("This IndexCommit does not support this method.");}++ /** Convenience method that returns the last modified time+ * of the segments_N file corresponding to this index+ * commit, equivalent to+ * getDirectory().fileModified(getSegmentsFileName()). */+ public long getTimestamp() throws IOException {+ return getDirectory().fileModified(getSegmentsFileName());+ }}diff --git a/src/test/org/apache/lucene/index/TestDeletionPolicy.java b/src/test/org/apache/lucene/index/TestDeletionPolicy.javaindex a50f595ff63..a3ca5a8cd59 100644--- a/src/test/org/apache/lucene/index/TestDeletionPolicy.java+++ b/src/test/org/apache/lucene/index/TestDeletionPolicy.java@@ -42,19 +42,24 @@ import org.apache.lucene.util.LuceneTestCase;public class TestDeletionPolicy extends LuceneTestCase{- private void verifyCommitOrder(List commits) {+ private void verifyCommitOrder(List commits) throws IOException {final IndexCommit firstCommit = ((IndexCommit) commits.get(0));long last = SegmentInfos.generationFromSegmentsFileName(firstCommit.getSegmentsFileName());assertEquals(last, firstCommit.getGeneration());long lastVersion = firstCommit.getVersion();+ long lastTimestamp = firstCommit.getTimestamp();for(int i=1;i<commits.size();i++) {final IndexCommit commit = ((IndexCommit) commits.get(i));long now = SegmentInfos.generationFromSegmentsFileName(commit.getSegmentsFileName());long nowVersion = commit.getVersion();+ long nowTimestamp = commit.getTimestamp();assertTrue("SegmentInfos commits are out-of-order", now > last);assertTrue("SegmentInfos versions are out-of-order", nowVersion > lastVersion);+ assertTrue("SegmentInfos timestamps are out-of-order: now=" + nowTimestamp + " vs last=" + lastTimestamp, nowTimestamp >= lastTimestamp);assertEquals(now, commit.getGeneration());last = now;+ lastVersion = nowVersion;+ lastTimestamp = nowTimestamp;}}@@ -62,7 +67,7 @@ public class TestDeletionPolicy extends LuceneTestCaseint numOnInit;int numOnCommit;Directory dir;- public void onInit(List commits) {+ public void onInit(List commits) throws IOException {verifyCommitOrder(commits);numOnInit++;}@@ -83,7 +88,7 @@ public class TestDeletionPolicy extends LuceneTestCaseclass KeepNoneOnInitDeletionPolicy implements IndexDeletionPolicy {int numOnInit;int numOnCommit;- public void onInit(List commits) {+ public void onInit(List commits) throws IOException {verifyCommitOrder(commits);numOnInit++;// On init, delete all commit points:@@ -94,7 +99,7 @@ public class TestDeletionPolicy extends LuceneTestCaseassertTrue(commit.isDeleted());}}- public void onCommit(List commits) {+ public void onCommit(List commits) throws IOException {verifyCommitOrder(commits);int size = commits.size();// Delete all but last one:@@ -116,14 +121,14 @@ public class TestDeletionPolicy extends LuceneTestCasethis.numToKeep = numToKeep;}- public void onInit(List commits) {+ public void onInit(List commits) throws IOException {verifyCommitOrder(commits);numOnInit++;// do no deletions on initdoDeletes(commits, false);}- public void onCommit(List commits) {+ public void onCommit(List commits) throws IOException {verifyCommitOrder(commits);doDeletes(commits, true);}