public void processed_value_are_correctly_stored() { //set to some round date to avoid rounding issues _timeProvider.Now = new DateTime(2000, 1, 1, 1, 1, 1, 0); var tracker = new TimestampTracker(PremiumCricketProducer, new[] { MessageInterest.PrematchMessagesOnly, MessageInterest.LiveMessagesOnly }, 20, 20); tracker.ProcessSystemAlive(MessageBuilder.BuildAlive()); _timeProvider.AddMilliSeconds(2500); tracker.ProcessUserMessage(MessageInterest.LiveMessagesOnly, MessageBuilder.BuildAlive()); _timeProvider.AddMilliSeconds(1000); tracker.ProcessUserMessage(MessageInterest.PrematchMessagesOnly, MessageBuilder.BuildAlive()); _timeProvider.AddMilliSeconds(1500); tracker.ProcessUserMessage(MessageInterest.LiveMessagesOnly, MessageBuilder.BuildBetStop(null, _timeProvider.Now - TimeSpan.FromMilliseconds(6500))); tracker.ProcessUserMessage(MessageInterest.PrematchMessagesOnly, MessageBuilder.BuildOddsChange(null, _timeProvider.Now - TimeSpan.FromMilliseconds(4300))); var trackerState = ParseLogEntry(tracker.ToString()); Assert.IsFalse(trackerState.IsAliveViolated); Assert.IsFalse(trackerState.IsBehind); Assert.AreEqual(TimeSpan.FromMilliseconds(5000), trackerState.SystemAliveAge); Assert.AreEqual(TimeSpan.FromMilliseconds(2500), trackerState.Alives[MessageInterest.LiveMessagesOnly]); Assert.AreEqual(TimeSpan.FromMilliseconds(1500), trackerState.Alives[MessageInterest.PrematchMessagesOnly]); Assert.AreEqual(TimeSpan.FromMilliseconds(6500), trackerState.NonAlives[MessageInterest.LiveMessagesOnly]); Assert.AreEqual(TimeSpan.FromMilliseconds(4300), trackerState.NonAlives[MessageInterest.PrematchMessagesOnly]); }
public void internal_state_on_creation_is_correct() { var tracker = new TimestampTracker(PremiumCricketProducer, new [] { MessageInterest.PrematchMessagesOnly, MessageInterest.LiveMessagesOnly }, 20, 20); var trackerState = ParseLogEntry(tracker.ToString()); Assert.IsFalse(trackerState.IsAliveViolated); Assert.IsFalse(trackerState.IsBehind); Assert.AreEqual(TimeSpan.Zero, trackerState.SystemAliveAge); Assert.AreEqual(TimeSpan.Zero, trackerState.Alives[MessageInterest.PrematchMessagesOnly]); Assert.AreEqual(TimeSpan.Zero, trackerState.Alives[MessageInterest.LiveMessagesOnly]); Assert.AreEqual(TimeSpan.Zero, trackerState.NonAlives[MessageInterest.PrematchMessagesOnly]); Assert.AreEqual(TimeSpan.Zero, trackerState.NonAlives[MessageInterest.LiveMessagesOnly]); }
public void alive_with_lower_latency_overrides_non_alive_with_greater_latency() { //set to some round date to avoid rounding issues _timeProvider.Now = new DateTime(2000, 1, 1, 1, 1, 1, 0); var tracker = new TimestampTracker(PremiumCricketProducer, new[] { MessageInterest.PrematchMessagesOnly, MessageInterest.LiveMessagesOnly }, 20, 20); tracker.ProcessUserMessage(MessageInterest.LiveMessagesOnly, MessageBuilder.BuildBetStop(null, _timeProvider.Now - TimeSpan.FromMilliseconds(5000))); tracker.ProcessUserMessage(MessageInterest.PrematchMessagesOnly, MessageBuilder.BuildOddsChange(null, _timeProvider.Now - TimeSpan.FromMilliseconds(7000))); tracker.ProcessUserMessage(MessageInterest.LiveMessagesOnly, MessageBuilder.BuildAlive(null, _timeProvider.Now - TimeSpan.FromSeconds(4))); tracker.ProcessUserMessage(MessageInterest.PrematchMessagesOnly, MessageBuilder.BuildAlive(null, _timeProvider.Now - TimeSpan.FromSeconds(8))); var trackerState = ParseLogEntry(tracker.ToString()); Assert.IsFalse(trackerState.IsAliveViolated); Assert.IsFalse(trackerState.IsBehind); Assert.AreEqual(TimeSpan.FromSeconds(0), trackerState.SystemAliveAge); Assert.AreEqual(TimeSpan.FromSeconds(4), trackerState.Alives[MessageInterest.LiveMessagesOnly]); Assert.AreEqual(TimeSpan.FromSeconds(8), trackerState.Alives[MessageInterest.PrematchMessagesOnly]); Assert.AreEqual(TimeSpan.FromSeconds(4), trackerState.NonAlives[MessageInterest.LiveMessagesOnly]); Assert.AreEqual(TimeSpan.FromSeconds(7), trackerState.NonAlives[MessageInterest.PrematchMessagesOnly]); }