public void ShouldUseObjectEqualityToCompareKeys() { var buffer = new CoalescingRingBuffer <String, Object>(2); buffer.Offer("boo", new Object()); buffer.Offer("boo", new Object()); Assert.AreEqual(1, buffer.Size()); }
public void ShouldBeAbleToReuseCapacity() { ICoalescingBuffer <int, String> buffer = new CoalescingRingBuffer <int, String>(32); var producer = new Thread( () => { for (var run = 0; run < 1000000; run++) { for (var message = 0; message < 10; message++) { var success = buffer.Offer(message, message.ToString()); if (!success) { _hasOverflowed = true; buffer.Offer(PoisonPill); return; } } } buffer.Offer(PoisonPill); }); var consumer = new Thread( () => { var values = new List <String>(CAPACITY); while (true) { buffer.Poll(values, CAPACITY); if (values.Contains(PoisonPill)) { return; } } }); producer.Start(); consumer.Start(); producer.Join(); Assert.IsFalse(_hasOverflowed, "ring buffer has overflowed"); }
public void ShouldBeAbleToReuseCapacity() { ICoalescingBuffer<int, String> buffer = new CoalescingRingBuffer<int, String>(32); var producer = new Thread( () => { for (var run = 0; run < 1000000; run++) { for (var message = 0; message < 10; message++) { var success = buffer.Offer(message, message.ToString()); if (!success) { _hasOverflowed = true; buffer.Offer(PoisonPill); return; } } } buffer.Offer(PoisonPill); }); var consumer = new Thread( () => { var values = new List<String>(CAPACITY); while (true) { buffer.Poll(values, CAPACITY); if (values.Contains(PoisonPill)) { return; } } }); producer.Start(); consumer.Start(); producer.Join(); Assert.IsFalse(_hasOverflowed, "ring buffer has overflowed"); }
public void ShouldCountRejections() { var buffer2 = new CoalescingRingBuffer <int, Object>(2); Assert.AreEqual(0, buffer2.RejectionCount()); buffer2.Offer(new Object()); Assert.AreEqual(0, buffer2.RejectionCount()); buffer2.Offer(1, new Object()); Assert.AreEqual(0, buffer2.RejectionCount()); buffer2.Offer(1, new Object()); Assert.AreEqual(0, buffer2.RejectionCount()); buffer2.Offer(new Object()); Assert.AreEqual(1, buffer2.RejectionCount()); buffer2.Offer(2, new Object()); Assert.AreEqual(2, buffer2.RejectionCount()); }
public void RunMemoryLeakTest() { ICoalescingBuffer<CountingKey, CountingValue> buffer = new CoalescingRingBuffer<CountingKey, CountingValue>(16); buffer.Offer(new CountingValue()); buffer.Offer(new CountingKey(1), new CountingValue()); buffer.Offer(new CountingKey(2), new CountingValue()); buffer.Offer(new CountingKey(1), new CountingValue()); buffer.Offer(new CountingValue()); Assert.AreEqual(4, buffer.Size()); buffer.Poll(new List<CountingValue>(), 1); buffer.Poll(new List<CountingValue>()); Assert.True(buffer.IsEmpty()); buffer.Offer(null); // to trigger the clean }
public void RunMemoryLeakTest() { ICoalescingBuffer <CountingKey, CountingValue> buffer = new CoalescingRingBuffer <CountingKey, CountingValue>(16); buffer.Offer(new CountingValue()); buffer.Offer(new CountingKey(1), new CountingValue()); buffer.Offer(new CountingKey(2), new CountingValue()); buffer.Offer(new CountingKey(1), new CountingValue()); buffer.Offer(new CountingValue()); Assert.AreEqual(4, buffer.Size()); buffer.Poll(new List <CountingValue>(), 1); buffer.Poll(new List <CountingValue>()); Assert.True(buffer.IsEmpty()); buffer.Offer(null); // to trigger the clean }
public void ShouldUseObjectEqualityToCompareKeys() { var buffer = new CoalescingRingBuffer<String, Object>(2); buffer.Offer("boo", new Object()); buffer.Offer("boo", new Object()); Assert.AreEqual(1, buffer.Size()); }
public void ShouldCountRejections() { var buffer2 = new CoalescingRingBuffer<int, Object>(2); Assert.AreEqual(0, buffer2.RejectionCount()); buffer2.Offer(new Object()); Assert.AreEqual(0, buffer2.RejectionCount()); buffer2.Offer(1, new Object()); Assert.AreEqual(0, buffer2.RejectionCount()); buffer2.Offer(1, new Object()); Assert.AreEqual(0, buffer2.RejectionCount()); buffer2.Offer(new Object()); Assert.AreEqual(1, buffer2.RejectionCount()); buffer2.Offer(2, new Object()); Assert.AreEqual(2, buffer2.RejectionCount()); }