public virtual void TestBasicSnapshots()
{
int numSnapshots = 3;
// Create 3 snapshots: snapshot0, snapshot1, snapshot2
Directory dir = NewDirectory();
IndexWriter writer = new IndexWriter(dir, GetConfig(Random(), DeletionPolicy));
SnapshotDeletionPolicy sdp = (SnapshotDeletionPolicy)writer.Config.DelPolicy;
PrepareIndexAndSnapshots(sdp, writer, numSnapshots);
writer.Dispose();
Assert.AreEqual(numSnapshots, sdp.Snapshots.Count);
Assert.AreEqual(numSnapshots, sdp.SnapshotCount);
AssertSnapshotExists(dir, sdp, numSnapshots, true);
// open a reader on a snapshot - should succeed.
DirectoryReader.Open(Snapshots[0]).Dispose();
// open a new IndexWriter w/ no snapshots to keep and assert that all snapshots are gone.
sdp = DeletionPolicy;
writer = new IndexWriter(dir, GetConfig(Random(), sdp));
writer.DeleteUnusedFiles();
writer.Dispose();
Assert.AreEqual(1, DirectoryReader.ListCommits(dir).Count, "no snapshots should exist");
dir.Dispose();
}