public void adding_read_message_in_correct_order() { var buffer = new StreamBuffer(10, 10, -1, true); var id = Guid.NewGuid(); buffer.AddReadMessage(BuildMessageAt(id, 0)); Assert.AreEqual(1, buffer.BufferCount); OutstandingMessage message = buffer.Scan().First().Message; Assert.AreEqual(id, message.EventId); Assert.IsFalse(buffer.Live); }
public void adding_messages_to_read_after_same_on_live_switches_to_live() { var buffer = new StreamBuffer(10, 10, -1, true); var id1 = Guid.NewGuid(); buffer.AddLiveMessage(BuildMessageAt(id1, 0)); buffer.AddReadMessage(BuildMessageAt(id1, 0)); Assert.IsTrue(buffer.Live); Assert.AreEqual(1, buffer.BufferCount); OutstandingMessage message; Assert.IsTrue(buffer.TryDequeue(out message)); Assert.AreEqual(id1, message.EventId); }
public void adding_multiple_same_read_message() { var buffer = new StreamBuffer(10, 10, -1, true); var id1 = Guid.NewGuid(); buffer.AddReadMessage(BuildMessageAt(id1, 0)); buffer.AddReadMessage(BuildMessageAt(id1, 0)); Assert.AreEqual(2, buffer.BufferCount); OutstandingMessage message; Assert.IsTrue(buffer.TryDequeue(out message)); Assert.AreEqual(id1, message.EventId); Assert.IsTrue(buffer.TryDequeue(out message)); Assert.AreEqual(id1, message.EventId); Assert.IsFalse(buffer.Live); }
public void adding_multiple_same_read_message() { var buffer = new StreamBuffer(10, 10, -1, true); var id1 = Guid.NewGuid(); buffer.AddReadMessage(BuildMessageAt(id1, 0)); buffer.AddReadMessage(BuildMessageAt(id1, 0)); Assert.AreEqual(2, buffer.BufferCount); var messagePointer = buffer.Scan().First(); Assert.AreEqual(id1, messagePointer.Message.EventId); messagePointer.MarkSent(); Assert.AreEqual(1, buffer.BufferCount); messagePointer = buffer.Scan().First(); Assert.AreEqual(id1, messagePointer.Message.EventId); messagePointer.MarkSent(); Assert.AreEqual(0, buffer.BufferCount); Assert.IsFalse(buffer.Live); }
private void OnCheckpointLoaded(int? checkpoint) { lock (_lock) { _state = PersistentSubscriptionState.Behind; if (!checkpoint.HasValue) { Log.Debug(string.Format("Subscription {0}: read no checksum.", _settings.SubscriptionId)); Log.Debug("strtfrom = " + _settings.StartFrom); _lastPulledEvent = _settings.StartFrom >= 0 ? _settings.StartFrom : 0; _streamBuffer = new StreamBuffer(_settings.BufferSize, _settings.LiveBufferSize, -1, _settings.StartFrom >= 0); TryReadingNewBatch(); } else { _lastPulledEvent = checkpoint.Value; Log.Debug(string.Format("Subscription {0}: read checksum {1}", _settings.SubscriptionId, checkpoint.Value)); _streamBuffer = new StreamBuffer(_settings.BufferSize, _settings.LiveBufferSize, -1, true); TryReadingNewBatch(); } } }
public void adding_messages_to_read_after_same_on_live_switches_to_live() { var buffer = new StreamBuffer(10, 10, -1, true); var id1 = Guid.NewGuid(); buffer.AddLiveMessage(BuildMessageAt(id1, 0)); buffer.AddReadMessage(BuildMessageAt(id1, 0)); Assert.IsTrue(buffer.Live); Assert.AreEqual(1, buffer.BufferCount); var messagePointer = buffer.Scan().First(); Assert.AreEqual(id1, messagePointer.Message.EventId); messagePointer.MarkSent(); Assert.AreEqual(0, buffer.BufferCount); }
public void lowest_retry_doesnt_assume_order() { var buffer = new StreamBuffer(10, 10, -1, true); buffer.AddRetry(BuildMessageAt(Guid.NewGuid(), 4)); buffer.AddRetry(BuildMessageAt(Guid.NewGuid(), 2)); buffer.AddRetry(BuildMessageAt(Guid.NewGuid(), 3)); Assert.AreEqual(2, buffer.GetLowestRetry()); }
public void retried_messages_appear_in_version_order() { var buffer = new StreamBuffer(10, 10, -1, true); var id1 = Guid.NewGuid(); buffer.AddReadMessage(BuildMessageAt(id1, 0)); var id2 = Guid.NewGuid(); var id3 = Guid.NewGuid(); var id4 = Guid.NewGuid(); var id5 = Guid.NewGuid(); buffer.AddRetry(BuildMessageAt(id2, 2)); buffer.AddRetry(BuildMessageAt(id3, 3)); buffer.AddRetry(BuildMessageAt(id4, 1)); buffer.AddRetry(BuildMessageAt(id5, 2)); var messagePointer = buffer.Scan().First(); Assert.AreEqual(id4, messagePointer.Message.EventId); messagePointer.MarkSent(); messagePointer = buffer.Scan().First(); Assert.AreEqual(id2, messagePointer.Message.EventId); messagePointer.MarkSent(); messagePointer = buffer.Scan().First(); Assert.AreEqual(id5, messagePointer.Message.EventId); messagePointer.MarkSent(); messagePointer = buffer.Scan().First(); Assert.AreEqual(id3, messagePointer.Message.EventId); messagePointer.MarkSent(); }
public void retried_messages_appear_first() { var buffer = new StreamBuffer(10, 10, -1, true); var id1 = Guid.NewGuid(); buffer.AddReadMessage(BuildMessageAt(id1, 0)); var id2 = Guid.NewGuid(); buffer.AddRetry(BuildMessageAt(id2, 2)); Assert.AreEqual(2, buffer.BufferCount); Assert.AreEqual(1, buffer.RetryBufferCount); Assert.AreEqual(1, buffer.ReadBufferCount); var messagePointer = buffer.Scan().First(); Assert.AreEqual(id2, messagePointer.Message.EventId); messagePointer.MarkSent(); Assert.AreEqual(1, buffer.BufferCount); Assert.AreEqual(0, buffer.RetryBufferCount); Assert.AreEqual(1, buffer.ReadBufferCount); messagePointer = buffer.Scan().First(); Assert.AreEqual(id1, messagePointer.Message.EventId); messagePointer.MarkSent(); Assert.AreEqual(0, buffer.BufferCount); Assert.AreEqual(0, buffer.RetryBufferCount); Assert.AreEqual(0, buffer.ReadBufferCount); Assert.IsFalse(buffer.Live); }
public void skipped_messages_are_not_removed() { var buffer = new StreamBuffer(10, 10, -1, true); var id1 = Guid.NewGuid(); buffer.AddReadMessage(BuildMessageAt(id1, 0)); var id2 = Guid.NewGuid(); buffer.AddReadMessage(BuildMessageAt(id2, 1)); var id3 = Guid.NewGuid(); buffer.AddReadMessage(BuildMessageAt(id3, 2)); Assert.AreEqual(3, buffer.BufferCount); var messagePointer2 = buffer.Scan().Skip(1).First(); // Skip the first message. Assert.AreEqual(id2, messagePointer2.Message.EventId); messagePointer2.MarkSent(); Assert.AreEqual(2, buffer.BufferCount); var messagePointers = buffer.Scan().ToArray(); Assert.AreEqual(id1, messagePointers[0].Message.EventId); Assert.AreEqual(id3, messagePointers[1].Message.EventId); }
public void adding_messages_with_lower_in_live() { var buffer = new StreamBuffer(10, 10, -1, true); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); buffer.AddLiveMessage(BuildMessageAt(id1, 5)); buffer.AddLiveMessage(BuildMessageAt(id1, 6)); buffer.AddLiveMessage(BuildMessageAt(id2, 7)); buffer.AddReadMessage(BuildMessageAt(id1, 7)); Assert.IsTrue(buffer.Live); Assert.AreEqual(1, buffer.BufferCount); var messagePointer = buffer.Scan().First(); Assert.AreEqual(id2, messagePointer.Message.EventId); messagePointer.MarkSent(); Assert.AreEqual(0, buffer.BufferCount); }
public void adding_messages_to_live_without_start_from_beginning() { var buffer = new StreamBuffer(10, 10, -1, false); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); buffer.AddLiveMessage(BuildMessageAt(id1, 6)); buffer.AddLiveMessage(BuildMessageAt(id2, 7)); Assert.IsTrue(buffer.Live); Assert.AreEqual(2, buffer.BufferCount); var messagePointer = buffer.Scan().First(); Assert.AreEqual(id1, messagePointer.Message.EventId); messagePointer.MarkSent(); Assert.AreEqual(1, buffer.BufferCount); messagePointer = buffer.Scan().First(); Assert.AreEqual(id2, messagePointer.Message.EventId); messagePointer.MarkSent(); Assert.AreEqual(0, buffer.BufferCount); }
public void RetrySingleMessage(ResolvedEvent @event) { StreamBuffer.AddRetry(new OutstandingMessage(@event.OriginalEvent.EventId, null, @event, 0)); }
public void adding_messages_with_lower_in_live() { var buffer = new StreamBuffer(10, 10, -1, true); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); buffer.AddLiveMessage(BuildMessageAt(id1, 5)); buffer.AddLiveMessage(BuildMessageAt(id1, 6)); buffer.AddLiveMessage(BuildMessageAt(id2, 7)); buffer.AddReadMessage(BuildMessageAt(id1, 7)); Assert.IsTrue(buffer.Live); Assert.AreEqual(1, buffer.BufferCount); OutstandingMessage message; Assert.IsTrue(buffer.TryDequeue(out message)); Assert.AreEqual(id2, message.EventId); }
public void adding_messages_to_live_without_start_from_beginning() { var buffer = new StreamBuffer(10, 10, -1, false); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); buffer.AddLiveMessage(BuildMessageAt(id1, 6)); buffer.AddLiveMessage(BuildMessageAt(id2, 7)); Assert.IsTrue(buffer.Live); Assert.AreEqual(2, buffer.BufferCount); OutstandingMessage message; Assert.IsTrue(buffer.TryDequeue(out message)); Assert.AreEqual(id1, message.EventId); Assert.IsTrue(buffer.TryDequeue(out message)); Assert.AreEqual(id2, message.EventId); }