Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 3
0
        public virtual void TestCrashAfterCloseNoWait()
        {
            IndexWriter          writer = InitIndex(Random, false);
            MockDirectoryWrapper dir    = (MockDirectoryWrapper)writer.Directory;

            writer.Dispose(false);

            dir.Crash();

            /*
             * String[] l = dir.list();
             * Arrays.sort(l);
             * for(int i=0;i<l.Length;i++)
             * System.out.println("file " + i + " = " + l[i] + " " + dir.FileLength(l[i]) + " bytes");
             */
            IndexReader reader = DirectoryReader.Open(dir);

            Assert.AreEqual(157, reader.NumDocs);
            reader.Dispose();
            dir.Dispose();
        }
Ejemplo n.º 4
0
        public virtual void TestCrashAfterCloseNoWait(
            [ValueSource(typeof(ConcurrentMergeSchedulerFactories), "Values")] Func <IConcurrentMergeScheduler> newScheduler)
        {
            IndexWriter          writer = InitIndex(newScheduler, Random(), false);
            MockDirectoryWrapper dir    = (MockDirectoryWrapper)writer.Directory;

            writer.Dispose(false);

            dir.Crash();

            /*
             * String[] l = dir.list();
             * Arrays.sort(l);
             * for(int i=0;i<l.Length;i++)
             * System.out.println("file " + i + " = " + l[i] + " " + dir.FileLength(l[i]) + " bytes");
             */
            IndexReader reader = DirectoryReader.Open(dir);

            Assert.AreEqual(157, reader.NumDocs);
            reader.Dispose();
            dir.Dispose();
        }