예제 #1
0
        public ChaosListener(IListener inner, ChaosConfiguration configuration, Random random, ChaosConnector connector)
            : base(inner)
        {
            this.connector = connector;
            bool abort = random.NextDouble() < configuration.Abort.Percentage;

            if (!abort)
            {
                return;
            }

            Timestamp?abortAfter = null;

            if (configuration.Abort.Duration != null)
            {
                var abortTimeSpan = GetRandomValue(random, configuration.Abort.Duration);
                abortAfter = Timestamp.Create() + abortTimeSpan;
            }
            long?abortUpstreamBytes = null;

            if (configuration.Abort.UpstreamBytes != null)
            {
                abortUpstreamBytes = GetRandomValue(random, configuration.Abort.UpstreamBytes);
            }
            long?abortDownstreamBytes = null;

            if (configuration.Abort.DownstreamBytes != null)
            {
                abortDownstreamBytes = GetRandomValue(random, configuration.Abort.DownstreamBytes);
            }

            upstream   = new Channel(abortAfter, abortUpstreamBytes);
            downstream = new Channel(abortAfter, abortDownstreamBytes);
        }
예제 #2
0
 /// <summary>
 /// Initializes a new <see cref="ChaosConnector"/>.
 /// </summary>
 /// <param name="configuration">The configuration associated with the connector.</param>
 /// <param name="inner">The inner connector used to get the upstream endpoint
 /// and listener.</param>
 public ChaosConnector(ChaosConfiguration configuration, IConnector inner)
 {
     this.configuration = configuration;
     this.inner         = inner;
 }