@Test
public void testMissingCommits() throws Exception {
// Tests the behavior of SDP when commits that are given at ctor are missing
// on onInit().
Directory dir = newDirectory();
SnapshotDeletionPolicy sdp = getDeletionPolicy();
IndexWriter writer = new IndexWriter(dir, getConfig(random, sdp));
writer.addDocument(new Document());
writer.commit();
IndexCommit ic = sdp.snapshot("s1");
// create another commit, not snapshotted.
writer.addDocument(new Document());
writer.close();
// open a new writer w/ KeepOnlyLastCommit policy, so it will delete "s1"
// commit.
new IndexWriter(dir, getConfig(random, null)).close();
assertFalse("snapshotted commit should not exist", dir.fileExists(ic.getSegmentsFileName()));
// Now reinit SDP from the commits in the index - the snapshot id should not
// exist anymore.
sdp = getDeletionPolicy(sdp.getSnapshots());
new IndexWriter(dir, getConfig(random, sdp)).close();
try {
sdp.getSnapshot("s1");
fail("snapshot s1 should not exist");
} catch (IllegalStateException e) {
// expected.
}
dir.close();