Beispiel #1
0
        public void violated_gives_correct_value()
        {
            var alive = new alive();

            _timeProvider.Now = DateTime.Now;
            var tracker = new TimestampTracker(PremiumCricketProducer, Interests, 20, 20);

            Assert.IsFalse(tracker.IsAliveViolated);
            _timeProvider.AddSeconds(10);
            Assert.IsFalse(tracker.IsAliveViolated);

            alive.timestamp = SdkInfo.ToEpochTime(_timeProvider.Now);
            tracker.ProcessSystemAlive(alive);
            Assert.IsFalse(tracker.IsAliveViolated);
            _timeProvider.AddSeconds(15);
            Assert.IsFalse(tracker.IsAliveViolated);
            _timeProvider.AddSeconds(10);
            Assert.IsTrue(tracker.IsAliveViolated);

            alive.timestamp = SdkInfo.ToEpochTime(_timeProvider.Now);
            tracker.ProcessSystemAlive(alive);
            Assert.IsFalse(tracker.IsAliveViolated);
            _timeProvider.AddSeconds(10);
            Assert.IsFalse(tracker.IsAliveViolated);
            _timeProvider.AddSeconds(15);
            Assert.IsTrue(tracker.IsAliveViolated);
        }
Beispiel #2
0
        public IAlive MapAlive(alive message)
        {
            Contract.Requires(message != null);
            Contract.Ensures(Contract.Result <IAlive>() != null);

            return(Contract.Result <IAlive>());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AliveEventArgs"/> class
        /// </summary>
        /// <param name="messageMapper">A <see cref="IFeedMessageMapper"/> used to map feed message to the one dispatched to the user</param>
        /// <param name="feedMessage">A <see cref="alive"/> message received from the feed</param>
        /// <param name="rawMessage">A raw message received from the feed</param>
        internal AliveEventArgs(IFeedMessageMapper messageMapper, alive feedMessage, byte[] rawMessage)
        {
            Guard.Argument(messageMapper, nameof(messageMapper)).NotNull();
            Guard.Argument(feedMessage, nameof(feedMessage)).NotNull();

            _messageMapper = messageMapper;
            _feedMessage   = feedMessage;
            _rawMessage    = rawMessage;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AliveEventArgs"/> class
        /// </summary>
        /// <param name="messageMapper">A <see cref="IFeedMessageMapper"/> used to map feed message to the one dispatched to the user</param>
        /// <param name="feedMessage">A <see cref="alive"/> message received from the feed</param>
        /// <param name="rawMessage">A raw message received from the feed</param>
        internal AliveEventArgs(IFeedMessageMapper messageMapper, alive feedMessage, byte[] rawMessage)
        {
            Contract.Requires(messageMapper != null);
            Contract.Requires(feedMessage != null);

            _messageMapper = messageMapper;
            _feedMessage   = feedMessage;
            _rawMessage    = rawMessage;
        }
Beispiel #5
0
        /// <summary>
        /// Validates the provided <see cref="alive" /> message
        /// </summary>
        /// <param name="message">The <see cref="alive" /> message to validate</param>
        /// <returns>The <see cref="ValidationResult" /> specifying the result of validation</returns>
        protected ValidationResult ValidateAlive(alive message)
        {
            Contract.Requires(message != null);

            ValidateMessageProducer(message);

            if (!ValidateMessage(message))
            {
                return(ValidationResult.FAILURE);
            }

            if (message.subscribed >= 0)
            {
                return(ValidationResult.SUCCESS);
            }
            LogWarning(message, "subscribed", message.subscribed);
            return(ValidationResult.PROBLEMS_DETECTED);
        }
        /// <summary>
        /// Validates the provided <see cref="alive" /> message
        /// </summary>
        /// <param name="message">The <see cref="alive" /> message to validate</param>
        /// <returns>The <see cref="ValidationResult" /> specifying the result of validation</returns>
        protected ValidationResult ValidateAlive(alive message)
        {
            Guard.Argument(message, nameof(message)).NotNull();

            ValidateMessageProducer(message);

            if (!ValidateMessage(message))
            {
                return(ValidationResult.FAILURE);
            }

            if (message.subscribed >= 0)
            {
                return(ValidationResult.SUCCESS);
            }
            LogWarning(message, "subscribed", message.subscribed);
            return(ValidationResult.PROBLEMS_DETECTED);
        }
 /// <summary>
 /// Records the provided <see cref="alive"/> message timing info received on the system session
 /// </summary>
 /// <param name="alive">The <see cref="alive"/> message received on a system session</param>
 public void ProcessSystemAlive(alive alive)
 {
     _systemAliveTimingInfo.Update(alive.timestamp);
 }
 /// <summary>
 /// Maps (converts) the provided <see cref="alive"/> instance to the <see cref="IAlive"/> instance
 /// </summary>
 /// <param name="message">A <see cref="alive"/> instance to be mapped (converted)</param>
 /// <returns>A <see cref="IAlive"/> instance constructed from information in the provided <see cref="alive"/></returns>
 public IAlive MapAlive(alive message)
 {
     return(new Alive(new MessageTimestamp(message.GeneratedAt, message.SentAt, message.ReceivedAt, SdkInfo.ToEpochTime(DateTime.Now)), _producerManager.Get(message.product), message.subscribed != 0));
 }
 private void TestEntityValues(IAlive entity, alive message, AssertHelper assertHelper)
 {
     TestMessageProperties(assertHelper, entity, message.timestamp, message.product);
     assertHelper.AreEqual(() => entity.Subscribed, message.subscribed == 1);
 }