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


C# IConnectionPool.CreateView方法代码示例

本文整理汇总了C#中IConnectionPool.CreateView方法的典型用法代码示例。如果您正苦于以下问题:C# IConnectionPool.CreateView方法的具体用法?C# IConnectionPool.CreateView怎么用?C# IConnectionPool.CreateView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConnectionPool的用法示例。


在下文中一共展示了IConnectionPool.CreateView方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssertCreateView

		public void AssertCreateView(IConnectionPool pool)
		{
			/**
			* Here we have setup a static connection pool seeded with 10 nodes. We force randomization OnStartup to false
			* so that we can test the nodes being returned are int the order we expect them to.
			* So what order we expect? Imagine the following:
			*
			* Thread A calls GetNext first without a local cursor and takes the current from the internal global cursor which is 0.
			* Thread B calls GetNext() second without a local cursor and therefor starts at 1.
			* After this each thread should walk the nodes in successive order using their local cursor
			* e.g Thread A might get 0,1,2,3,5 and thread B will get 1,2,3,4,0.
			*/
			var startingPositions = Enumerable.Range(0, NumberOfNodes)
				.Select(i => pool.CreateView().First())
				.Select(n => n.Uri.Port)
				.ToList();

			var expectedOrder = Enumerable.Range(9200, NumberOfNodes);
			startingPositions.Should().ContainInOrder(expectedOrder);

			/**
			* What the above code just proved is that each call to GetNext(null) gets assigned the next available node.
			*
			* Lets up the ante:
			* - call get next over `NumberOfNodes * 2` threads
			* - on each thread call getnext `NumberOfNodes * 10` times using a local cursor.
			* We'll validate that each thread sees all the nodes and they they wrap over e.g after node 9209
			* comes 9200 again
			*/
			var threadedStartPositions = new ConcurrentBag<int>();
			var threads = Enumerable.Range(0, 20)
				.Select(i => CreateThreadCallingGetNext(pool, threadedStartPositions))
				.ToList();

			foreach (var t in threads) t.Start();
			foreach (var t in threads) t.Join();

			/**
			* Each thread reported the first node it started off lets make sure we see each node twice as the first node
			* because we started `NumberOfNodes * 2` threads
			*/
			var grouped = threadedStartPositions.GroupBy(p => p).ToList();
			grouped.Count().Should().Be(NumberOfNodes);
			grouped.Select(p => p.Count()).Should().OnlyContain(p => p == 2);
		}
开发者ID:RossLieberman,项目名称:NEST,代码行数:45,代码来源:RoundRobin.doc.cs

示例2: CallGetNext

		private IEnumerable<int> CallGetNext(IConnectionPool pool)
		{
			foreach (var n in pool.CreateView()) yield return n.Uri.Port;
		}
开发者ID:emohebi,项目名称:elasticsearch-net,代码行数:4,代码来源:VolatileUpdates.doc.cs


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