当前位置: 首页>>代码示例>>C#>>正文


C# RAMDirectory.SetLockFactory方法代码示例

本文整理汇总了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();
			}
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:28,代码来源:TestLockFactory.cs

示例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();
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:30,代码来源:TestLockFactory.cs


注:本文中的Lucene.Net.Store.RAMDirectory.SetLockFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。