本文整理汇总了C#中Lucene.Net.Store.RAMDirectory.SetLockFactory方法的典型用法代码示例。如果您正苦于以下问题:C# RAMDirectory.SetLockFactory方法的具体用法?C# RAMDirectory.SetLockFactory怎么用?C# RAMDirectory.SetLockFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Store.RAMDirectory
的用法示例。
在下文中一共展示了RAMDirectory.SetLockFactory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRAMDirectoryNoLocking
public virtual void TestRAMDirectoryNoLocking()
{
Directory dir = new RAMDirectory();
dir.SetLockFactory(NoLockFactory.GetNoLockFactory());
Assert.IsTrue(typeof(NoLockFactory).IsInstanceOfType(dir.GetLockFactory()), "RAMDirectory.setLockFactory did not take");
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
// Create a 2nd IndexWriter. This is normally not allowed but it should run through since we're not
// using any locks:
IndexWriter writer2 = null;
try
{
writer2 = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
}
catch (System.Exception e)
{
System.Console.Out.WriteLine(e.StackTrace);
Assert.Fail("Should not have hit an IOException with no locking");
}
writer.Close();
if (writer2 != null)
{
writer2.Close();
}
}
示例2: TestCustomLockFactory
public virtual void TestCustomLockFactory()
{
Directory dir = new RAMDirectory();
MockLockFactory lf = new MockLockFactory(this);
dir.SetLockFactory(lf);
// Lock prefix should have been set:
Assert.IsTrue(lf.lockPrefixSet, "lock prefix was not set by the RAMDirectory");
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
// add 100 documents (so that commit lock is used)
for (int i = 0; i < 100; i++)
{
AddDoc(writer);
}
// Both write lock and commit lock should have been created:
Assert.AreEqual(1, lf.locksCreated.Count, "# of unique locks created (after instantiating IndexWriter)");
Assert.IsTrue(lf.makeLockCount >= 1, "# calls to makeLock is 0 (after instantiating IndexWriter)");
for (System.Collections.IEnumerator e = lf.locksCreated.Keys.GetEnumerator(); e.MoveNext(); )
{
System.String lockName = (System.String) e.Current;
MockLockFactory.MockLock lock_Renamed = (MockLockFactory.MockLock) lf.locksCreated[lockName];
Assert.IsTrue(lock_Renamed.lockAttempts > 0, "# calls to Lock.obtain is 0 (after instantiating IndexWriter)");
}
writer.Close();
}