示例#1
0
		public void TestHuge()
		{
			using (var b = new ThreadSafeWriteQueue(1024))
			{
				var pos = b.Allocate(1024 - 2);
				b.Commit(pos);
				var a = b.ReadMessage();
				Assert.AreEqual(pos, a);
				Assert.AreEqual(-1, b.ReadMessage());

				pos = b.Allocate(1024 - 2);
				b.Commit(pos);
				a = b.ReadMessage();
				Assert.AreEqual(pos, a);
				Assert.AreEqual(-1, b.ReadMessage());

				Assert.Throws<OverflowException>(() => b.Allocate(1024 - 1));
			}
		}
示例#2
0
		public void TestSafeRead()
		{
			using (var b = new ThreadSafeWriteQueue(8))
			{
				b.Commit(b.Allocate(2));
				b.Commit(b.Allocate(2));
				b.ReadMessage();
				Assert.Throws<OverflowException>(() => b.Allocate(2));
				b.ReadMessage();
				b.Commit(b.Allocate(2));
			}
		}
示例#3
0
		public void TestOverflow()
		{
			using (var b = new ThreadSafeWriteQueue(1024))
			{
				int i = 1024 / (2);
				while (i > 1)
				{
					b.Commit(b.Allocate(1));
					--i;
				}
				Assert.Throws<OverflowException>(() => b.Allocate(1));
			}
		}