Exemple #1
0
        public virtual void  TestDisableLocks()
        {
            System.IO.FileInfo indexDirName = _TestUtil.GetTempDir("index.TestLockFactory4");

            Assert.IsTrue(!FSDirectory.GetDisableLocks(), "Locks are already disabled");
            FSDirectory.SetDisableLocks(true);

            IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);

            Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(writer.GetDirectory().GetLockFactory()), "FSDirectory did not use correct default LockFactory: got " + writer.GetDirectory().GetLockFactory());

            // Should be no error since locking is disabled:
            IndexWriter writer2 = null;

            try
            {
                writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
            }
            catch (System.IO.IOException e)
            {
                System.Console.Out.WriteLine(e.StackTrace);
                Assert.Fail("Should not have hit an IOException with locking disabled");
            }

            FSDirectory.SetDisableLocks(false);
            writer.Close();
            if (writer2 != null)
            {
                writer2.Close();
            }
            // Cleanup
            _TestUtil.RmDir(indexDirName);
        }