public void lowest_works_on_add() { var id = Guid.NewGuid(); var cache = new OutstandingMessageCache(); cache.StartMessage(new OutstandingMessage(id, null, Helper.BuildFakeEvent(id, "type", "name", 10), 0), DateTime.Now); Assert.AreEqual(10, cache.GetLowestPosition()); }
public void adding_an_item_causes_count_to_go_up() { var id = Guid.NewGuid(); var cache = new OutstandingMessageCache(); cache.StartMessage(new OutstandingMessage(id, null, Helper.BuildFakeEvent(id, "type", "name", 0), 0), DateTime.Now); Assert.AreEqual(1, cache.Count); Assert.AreEqual(0, cache.GetLowestPosition()); }
public void can_remove_existing_item() { var id = Guid.NewGuid(); var cache = new OutstandingMessageCache(); cache.StartMessage(new OutstandingMessage(id, null, Helper.BuildFakeEvent(id, "type", "name", 0), 0), DateTime.Now); cache.Remove(id); Assert.AreEqual(0, cache.Count); }
public PersistentSubscription(PersistentSubscriptionParams persistentSubscriptionParams) { Ensure.NotNull(persistentSubscriptionParams.StreamReader, "eventLoader"); Ensure.NotNull(persistentSubscriptionParams.CheckpointReader, "checkpointReader"); Ensure.NotNull(persistentSubscriptionParams.CheckpointWriter, "checkpointWriter"); Ensure.NotNull(persistentSubscriptionParams.MessageParker, "messageParker"); Ensure.NotNull(persistentSubscriptionParams.SubscriptionId, "subscriptionId"); Ensure.NotNull(persistentSubscriptionParams.EventStreamId, "eventStreamId"); Ensure.NotNull(persistentSubscriptionParams.GroupName, "groupName"); _lastPulledEvent = 0; _totalTimeWatch = new Stopwatch(); _settings = persistentSubscriptionParams; _totalTimeWatch.Start(); _statistics = new PersistentSubscriptionStats(this, _settings, _totalTimeWatch); _outstandingMessages = new OutstandingMessageCache(); InitAsNew(); }
public PersistentSubscription(PersistentSubscriptionParams persistentSubscriptionParams) { Ensure.NotNull(persistentSubscriptionParams.StreamReader, "eventLoader"); Ensure.NotNull(persistentSubscriptionParams.CheckpointReader, "checkpointReader"); Ensure.NotNull(persistentSubscriptionParams.CheckpointWriter, "checkpointWriter"); Ensure.NotNull(persistentSubscriptionParams.MessageParker, "messageParker"); Ensure.NotNull(persistentSubscriptionParams.SubscriptionId, "subscriptionId"); Ensure.NotNull(persistentSubscriptionParams.EventStreamId, "eventStreamId"); Ensure.NotNull(persistentSubscriptionParams.GroupName, "groupName"); _lastPulledEvent = 0; _totalTimeWatch = new Stopwatch(); _settings = persistentSubscriptionParams; _totalTimeWatch.Start(); _statistics = new PersistentSubscriptionStats(this, _settings, _totalTimeWatch); _outstandingMessages = new OutstandingMessageCache(); InitAsNew(); }
public PersistentSubscription(PersistentSubscriptionParams persistentSubscriptionParams) { Ensure.NotNull(persistentSubscriptionParams.StreamReader, "eventLoader"); Ensure.NotNull(persistentSubscriptionParams.CheckpointReader, "checkpointReader"); Ensure.NotNull(persistentSubscriptionParams.CheckpointWriter, "checkpointWriter"); Ensure.NotNull(persistentSubscriptionParams.MessageParker, "messageParker"); Ensure.NotNull(persistentSubscriptionParams.SubscriptionId, "subscriptionId"); Ensure.NotNull(persistentSubscriptionParams.EventStreamId, "eventStreamId"); Ensure.NotNull(persistentSubscriptionParams.GroupName, "groupName"); _nextEventToPullFrom = 0; _totalTimeWatch = new Stopwatch(); _settings = persistentSubscriptionParams; _totalTimeWatch.Start(); _statistics = new PersistentSubscriptionStats(this, _settings, _totalTimeWatch); _outstandingMessages = new OutstandingMessageCache(); _streamBufferSource = new TaskCompletionSource <StreamBuffer>(TaskCreationOptions.RunContinuationsAsynchronously); InitAsNew(); }
public PersistentSubscription(PersistentSubscriptionParams persistentSubscriptionParams) { Ensure.NotNull(persistentSubscriptionParams.StreamReader, "eventLoader"); Ensure.NotNull(persistentSubscriptionParams.CheckpointReader, "checkpointReader"); Ensure.NotNull(persistentSubscriptionParams.CheckpointWriter, "checkpointWriter"); Ensure.NotNull(persistentSubscriptionParams.MessageParker, "messageParker"); Ensure.NotNull(persistentSubscriptionParams.SubscriptionId, "subscriptionId"); Ensure.NotNull(persistentSubscriptionParams.EventStreamId, "eventStreamId"); Ensure.NotNull(persistentSubscriptionParams.GroupName, "groupName"); if (persistentSubscriptionParams.ReadBatchSize >= persistentSubscriptionParams.BufferSize) { throw new ArgumentOutOfRangeException($"{nameof(persistentSubscriptionParams.ReadBatchSize)} may not be greater than or equal to {nameof(persistentSubscriptionParams.BufferSize)}"); } _nextEventToPullFrom = 0; _totalTimeWatch = new Stopwatch(); _settings = persistentSubscriptionParams; _totalTimeWatch.Start(); _statistics = new PersistentSubscriptionStats(this, _settings, _totalTimeWatch); _outstandingMessages = new OutstandingMessageCache(); _streamBufferSource = new TaskCompletionSource <StreamBuffer>(TaskCreationOptions.RunContinuationsAsynchronously); InitAsNew(); }
public void message_that_expires_is_included_in_expired_list() { var id = Guid.NewGuid(); var cache = new OutstandingMessageCache(); cache.StartMessage(new OutstandingMessage(id, null, Helper.BuildFakeEvent(id, "type", "name", 0), 0), DateTime.Now.AddSeconds(-1)); var expired = cache.GetMessagesExpiringBefore(DateTime.Now).ToList(); Assert.AreEqual(1, expired.Count()); Assert.AreEqual(id, expired.FirstOrDefault().EventId); }
public void get_expired_messages_returns_min_value_on_empty_cache() { var cache = new OutstandingMessageCache(); Assert.AreEqual(0, cache.GetMessagesExpiringBefore(DateTime.Now).Count()); Assert.AreEqual(int.MinValue, cache.GetLowestPosition()); }
public void lowest_on_empty_cache_returns_min() { var cache = new OutstandingMessageCache(); Assert.AreEqual(int.MinValue, cache.GetLowestPosition()); }
public void can_remove_non_existing_item() { var cache = new OutstandingMessageCache(); Assert.DoesNotThrow(() => cache.Remove(Guid.NewGuid())); }
public void when_created_has_zero_count() { var cache = new OutstandingMessageCache(); Assert.AreEqual(0, cache.Count); }