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 TryMarkCheckpoint(bool isTimeCheck) { lock (_lock) { var lowest = _outstandingMessages.GetLowestPosition(); //TODO? COMPETING better to make -1? as of now we are inclusive of checkpoint. var lowestBufferedRetry = _streamBuffer.GetLowestRetry(); lowest = Math.Min(lowest, lowestBufferedRetry); if (lowest == int.MinValue) { lowest = _lastKnownMessage; } //no outstanding messages. in this case we can say that the last known //event would be our checkpoint place (we have already completed it) var difference = lowest - _lastCheckPoint; var now = DateTime.Now; var timedifference = now - _lastCheckPointTime; if (timedifference < _settings.CheckPointAfter && difference < _settings.MaxCheckPointCount) { return; } if ((difference >= _settings.MinCheckPointCount && isTimeCheck) || difference >= _settings.MaxCheckPointCount) { _lastCheckPointTime = now; _lastCheckPoint = lowest; _settings.CheckpointWriter.BeginWriteState(lowest); _statistics.SetLastCheckPoint(lowest); } } }
public void TryMarkCheckpoint(bool isTimeCheck) { lock (_lock) { var lowest = _outstandingMessages.GetLowestPosition() - 1; // Subtract 1 from retry and outstanding as those messages have not been processed yet. var lowestBufferedRetry = StreamBuffer.GetLowestRetry() - 1; lowest = Math.Min(lowest, lowestBufferedRetry); if (lowest == long.MaxValue - 1) { lowest = _lastKnownMessage; } if (lowest == -1) { return; } //no outstanding messages. in this case we can say that the last known //event would be our checkpoint place (we have already completed it) var difference = lowest - _lastCheckPoint; var now = DateTime.UtcNow; var timedifference = now - _lastCheckPointTime; if (timedifference < _settings.CheckPointAfter && difference < _settings.MaxCheckPointCount) { return; } if ((difference >= _settings.MinCheckPointCount && isTimeCheck) || difference >= _settings.MaxCheckPointCount) { _lastCheckPointTime = now; _lastCheckPoint = lowest; _settings.CheckpointWriter.BeginWriteState(lowest); _statistics.SetLastCheckPoint(lowest); } } }
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 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()); }