public void PeekingDoesNotChangeState() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { buffer.Enqueue(new[] { Some.Bytes(140) }); var contents = buffer.Peek((int)DefaultBufferSize); Assert.Equal(1, contents.Length); var remainder = buffer.Peek((int)DefaultBufferSize); Assert.Equal(1, remainder.Length); } }
public void AtLeastOneEventIsAlwaysDequeued() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { byte[] a1 = Some.Bytes(140), a2 = Some.Bytes(140), a3 = Some.Bytes(140); buffer.Enqueue(new[] { a1, a2, a3 }); var contents = buffer.Peek(30); Assert.Equal(1, contents.Length); Assert.Equal(a1, contents[0].Value); } }
public void SizeHintLimitsDequeuedEventCount() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { byte[] a1 = Some.Bytes(140), a2 = Some.Bytes(140), a3 = Some.Bytes(140); buffer.Enqueue(new[] { a1, a2, a3 }); var contents = buffer.Peek(300); Assert.Equal(2, contents.Length); Assert.Equal(a1, contents[0].Value); Assert.Equal(a2, contents[1].Value); } }
public void EntriesOverLimitArePurgedFifo() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), 4096)) { byte[] a1 = Some.Bytes(140), a2 = Some.Bytes(140), a3 = Some.Bytes(140); buffer.Enqueue(new[] { a1, a2, a3 }); var contents = buffer.Peek((int)DefaultBufferSize); Assert.Equal(2, contents.Length); Assert.Equal(a2, contents[0].Value); Assert.Equal(a3, contents[1].Value); } }
public void GivingTheLastSeenEventKeyRemovesPrecedingEvents() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { byte[] a1 = Some.Bytes(140), a2 = Some.Bytes(140), a3 = Some.Bytes(140); buffer.Enqueue(new[] { a1, a2, a3 }); var contents = buffer.Peek(420); Assert.Equal(3, contents.Length); buffer.Dequeue(contents[2].Key); var remaining = buffer.Peek(420); Assert.Equal(0, remaining.Length); } }
public void EnumerationIsInOrder() { using (var temp = TempFolder.ForCaller()) using (var buffer = new LogBuffer(temp.AllocateFilename("mdb"), DefaultBufferSize)) { byte[] a1 = Some.Bytes(140), a2 = Some.Bytes(140), a3 = Some.Bytes(140); buffer.Enqueue(new[] { a1, a2, a3 }); var contents = new List <byte[]>(); buffer.Enumerate((k, v) => { contents.Add(v); }); Assert.Equal(3, contents.Count); Assert.Equal(new[] { a1, a2, a3 }, contents); } }
public void EntriesSurviveReloads() { var apiKey = Some.ApiKey(); var value = Some.Bytes(100); using (var tmp = new TempFolder("Buffer")) { using (var map = CreateActiveLogBufferMap(tmp)) { map.GetLogBuffer(null).Enqueue(new[] { value }); map.GetLogBuffer(apiKey).Enqueue(new[] { value }); } using (var map = CreateActiveLogBufferMap(tmp)) { var first = map.GetLogBuffer(null).Peek(0).Single(); var second = map.GetLogBuffer(apiKey).Peek(0).Single(); Assert.Equal(value, first.Value); Assert.Equal(value, second.Value); } } }