private void Crash(IndexWriter writer) { MockDirectoryWrapper dir = (MockDirectoryWrapper)writer.Directory; var cms = (IConcurrentMergeScheduler)writer.Config.MergeScheduler; cms.Sync(); dir.Crash(); cms.Sync(); dir.ClearCrash(); }
public virtual void TestExistingSnapshots() { int numSnapshots = 3; MockDirectoryWrapper dir = NewMockDirectory(); IndexWriter writer = new IndexWriter(dir, GetConfig(Random(), GetDeletionPolicy(dir))); PersistentSnapshotDeletionPolicy psdp = (PersistentSnapshotDeletionPolicy)writer.Config.IndexDeletionPolicy; Assert.IsNull(psdp.LastSaveFile); PrepareIndexAndSnapshots(psdp, writer, numSnapshots); Assert.IsNotNull(psdp.LastSaveFile); writer.Dispose(); // Make sure only 1 save file exists: int count = 0; foreach (string file in dir.ListAll()) { if (file.StartsWith(PersistentSnapshotDeletionPolicy.SNAPSHOTS_PREFIX, StringComparison.Ordinal)) { count++; } } Assert.AreEqual(1, count); // Make sure we fsync: dir.Crash(); dir.ClearCrash(); // Re-initialize and verify snapshots were persisted psdp = new PersistentSnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy(), dir, OpenMode.APPEND); writer = new IndexWriter(dir, GetConfig(Random(), psdp)); psdp = (PersistentSnapshotDeletionPolicy)writer.Config.IndexDeletionPolicy; Assert.AreEqual(numSnapshots, psdp.GetSnapshots().Count); Assert.AreEqual(numSnapshots, psdp.SnapshotCount); AssertSnapshotExists(dir, psdp, numSnapshots, false); writer.AddDocument(new Document()); writer.Commit(); Snapshots.Add(psdp.Snapshot()); Assert.AreEqual(numSnapshots + 1, psdp.GetSnapshots().Count); Assert.AreEqual(numSnapshots + 1, psdp.SnapshotCount); AssertSnapshotExists(dir, psdp, numSnapshots + 1, false); writer.Dispose(); dir.Dispose(); }