Esempio n. 1
0
        private bool ShouldInjectError(Message message)
        {
            if (!errorInjection || message.Direction != Message.Directions.Request)
            {
                return(false);
            }

            double r = random.NextDouble() * 100;

            if (!(r < errorInjectionRate))
            {
                return(false);
            }

            if (r < rejectionInjectionRate)
            {
                return(true);
            }

            if (logger.IsVerbose)
            {
                logger.Verbose(ErrorCode.Dispatcher_InjectingMessageLoss, "Injecting a message loss");
            }
            // else do nothing and intentionally drop message on the floor to inject a message loss
            return(true);
        }
Esempio n. 2
0
        public static TimeSpan NextTimeSpan(this SafeRandom random, TimeSpan timeSpan)
        {
            if (timeSpan <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("timeSpan", timeSpan, "SafeRandom.NextTimeSpan timeSpan must be a positive number.");
            }
            double ticksD = ((double)timeSpan.Ticks) * random.NextDouble();
            long   ticks  = checked ((long)ticksD);

            return(TimeSpan.FromTicks(ticks));
        }