예제 #1
0
        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]);
        }
예제 #2
0
        public void oldest_user_alive_timestamp_returns_correct_value()
        {
            // initially a time of instance creation must be returned
            var tracker = new TimestampTracker(PremiumCricketProducer, new [] { MessageInterest.HighPriorityMessages, MessageInterest.LowPriorityMessages }, 20, 20);

            Assert.AreEqual(SdkInfo.ToEpochTime(_timeProvider.Now), tracker.OldestUserAliveTimestamp);

            var alive1 = MessageBuilder.BuildAlive();

            // let move the time forward, so the alive above is 4 seconds old
            _timeProvider.AddSeconds(4);
            tracker.ProcessUserMessage(MessageInterest.HighPriorityMessages, alive1);
            Assert.AreEqual(SdkInfo.ToEpochTime(_timeProvider.Now - TimeSpan.FromSeconds(4)), tracker.OldestUserAliveTimestamp);

            // lets create an alive 8 seconds old
            var alive2 = MessageBuilder.BuildAlive(null, _timeProvider.Now - TimeSpan.FromSeconds(8));

            tracker.ProcessUserMessage(MessageInterest.LowPriorityMessages, alive2);
            Assert.AreEqual(SdkInfo.ToEpochTime(_timeProvider.Now - TimeSpan.FromSeconds(8)), tracker.OldestUserAliveTimestamp);

            // lets override the alive above (8 seconds old) with a newer message
            var alive3 = MessageBuilder.BuildAlive();

            tracker.ProcessUserMessage(MessageInterest.LowPriorityMessages, alive3);
            Assert.AreEqual(SdkInfo.ToEpochTime(_timeProvider.Now - TimeSpan.FromSeconds(4)), tracker.OldestUserAliveTimestamp);
        }
예제 #3
0
        public void user_alive_resets_behind_caused_by_non_alive()
        {
            var tracker    = new TimestampTracker(PremiumCricketProducer, Interests, 20, 20);
            var oddsChange = MessageBuilder.BuildOddsChange(null, _timeProvider.Now - TimeSpan.FromSeconds(25));

            tracker.ProcessUserMessage(MessageInterest.AllMessages, oddsChange);
            Assert.IsTrue(tracker.IsBehind);
            tracker.ProcessUserMessage(MessageInterest.AllMessages, MessageBuilder.BuildAlive());
            Assert.IsFalse(tracker.IsBehind);
        }
예제 #4
0
        public void not_delayed_message_resets_is_behind()
        {
            var tracker    = new TimestampTracker(PremiumCricketProducer, Interests, 20, 20);
            var oddsChange = MessageBuilder.BuildOddsChange(null, _timeProvider.Now - TimeSpan.FromSeconds(25));

            tracker.ProcessUserMessage(MessageInterest.AllMessages, oddsChange);
            Assert.IsTrue(tracker.IsBehind);
            tracker.ProcessUserMessage(MessageInterest.AllMessages, MessageBuilder.BuildBetStop());
            Assert.IsFalse(tracker.IsBehind);
        }
예제 #5
0
        public void user_alives_on_all_sessions_are_required_to_reset_is_behind()
        {
            var tracker = new TimestampTracker(PremiumCricketProducer, new [] { MessageInterest.LiveMessagesOnly, MessageInterest.PrematchMessagesOnly }, 20, 20);

            _timeProvider.AddSeconds(25);
            var alive = MessageBuilder.BuildAlive();

            tracker.ProcessUserMessage(MessageInterest.LiveMessagesOnly, alive);
            Assert.IsTrue(tracker.IsBehind);
            tracker.ProcessUserMessage(MessageInterest.PrematchMessagesOnly, alive);
            _timeProvider.AddSeconds(6);
            Assert.IsFalse(tracker.IsBehind);
        }
예제 #6
0
        public void oldest_alive_timestamp_gives_correct_value()
        {
            var tracker = new TimestampTracker(PremiumCricketProducer, new [] { MessageInterest.LiveMessagesOnly, MessageInterest.PrematchMessagesOnly }, 20, 20);

            Assert.AreEqual(SdkInfo.ToEpochTime(_timeProvider.Now), tracker.OldestUserAliveTimestamp);

            _timeProvider.AddSeconds(5);
            tracker.ProcessUserMessage(MessageInterest.LiveMessagesOnly, MessageBuilder.BuildAlive());
            Assert.AreEqual(SdkInfo.ToEpochTime(_timeProvider.Now - TimeSpan.FromSeconds(5)), tracker.OldestUserAliveTimestamp);

            _timeProvider.AddSeconds(5);
            tracker.ProcessUserMessage(MessageInterest.PrematchMessagesOnly, MessageBuilder.BuildAlive());
            Assert.AreEqual(SdkInfo.ToEpochTime(_timeProvider.Now - TimeSpan.FromSeconds(5)), tracker.OldestUserAliveTimestamp);
        }
예제 #7
0
        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]);
        }