Ejemplo n.º 1
0
        private static Task <HttpResponseMessage> GetHttpResponseMessage(Context context, CancellationToken token)
        {
            OperationChaosSetting chaosSettings = context.GetOperationChaosSettings();

            if (chaosSettings == null)
            {
                return(NoHttpResponse);
            }

            int statusCode = chaosSettings.StatusCode;

            if (statusCode < 200)
            {
                return(NoHttpResponse);
            }

            try
            {
                return(Task.FromResult(new HttpResponseMessage((HttpStatusCode)statusCode)));
            }
            catch
            {
                return(NoHttpResponse);
            }
        }
Ejemplo n.º 2
0
        private static Task <Double> GetInjectionRate(Context context, CancellationToken token)
        {
            OperationChaosSetting chaosSettings = context.GetOperationChaosSettings();

            if (chaosSettings == null)
            {
                return(NoInjectionRate);
            }

            return(Task.FromResult(chaosSettings.InjectionRate));
        }
Ejemplo n.º 3
0
        private static Task <bool> GetEnabled(Context context, CancellationToken token)
        {
            OperationChaosSetting chaosSettings = context.GetOperationChaosSettings();

            if (chaosSettings == null)
            {
                return(NotEnabled);
            }

            return(Task.FromResult(chaosSettings.Enabled));
        }
Ejemplo n.º 4
0
        private static Task <TimeSpan> GetLatency(Context context, CancellationToken token)
        {
            OperationChaosSetting chaosSettings = context.GetOperationChaosSettings();

            if (chaosSettings == null)
            {
                return(NoLatency);
            }

            int milliseconds = chaosSettings.LatencyMs;

            if (milliseconds <= 0)
            {
                return(NoLatency);
            }

            return(Task.FromResult(TimeSpan.FromMilliseconds(milliseconds)));
        }
Ejemplo n.º 5
0
        private static Task <Exception> GetException(Context context, CancellationToken token)
        {
            OperationChaosSetting chaosSettings = context.GetOperationChaosSettings();

            if (chaosSettings == null)
            {
                return(NoExceptionResult);
            }

            string exceptionName = chaosSettings.Exception;

            if (String.IsNullOrWhiteSpace(exceptionName))
            {
                return(NoExceptionResult);
            }

            try
            {
                Type exceptionType = Type.GetType(exceptionName);
                if (exceptionType == null)
                {
                    return(NoExceptionResult);
                }

                if (!typeof(Exception).IsAssignableFrom(exceptionType))
                {
                    return(NoExceptionResult);
                }

                var instance = Activator.CreateInstance(exceptionType);
                return(Task.FromResult(instance as Exception));
            }
            catch
            {
                return(NoExceptionResult);
            }
        }