Ejemplo n.º 1
0
        public void TestBadRequestsDoNotAffectErrorPercentage()
        {
            string key = "cmd-metrics-B";

            HystrixCommand <bool> cmd1    = new SuccessCommand(key, 0);
            HystrixCommandMetrics metrics = cmd1._metrics;

            Assert.True(WaitForHealthCountToUpdate(key, 1000), "Health count stream took to long");
            cmd1.Execute();
            Assert.True(WaitForHealthCountToUpdate(key, 250), "Health count stream took to long");

            output.WriteLine("ReqLog" + "@ " + Time.CurrentTimeMillis + " : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString());
            Assert.Equal(0, metrics.Healthcounts.ErrorPercentage);

            HystrixCommand <bool> cmd2 = new FailureCommand(key, 0);

            cmd2.Execute();
            Assert.True(WaitForHealthCountToUpdate(key, 250), "Health count stream took to long");

            output.WriteLine("ReqLog" + "@ " + Time.CurrentTimeMillis + " : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString());
            Assert.Equal(50, metrics.Healthcounts.ErrorPercentage);

            HystrixCommand <bool> cmd3 = new BadRequestCommand(key, 0);
            HystrixCommand <bool> cmd4 = new BadRequestCommand(key, 0);

            try
            {
                cmd3.Execute();
            }
            catch (HystrixBadRequestException)
            {
                output.WriteLine("ReqLog" + "@ " + Time.CurrentTimeMillis + " : " + "Caught expected HystrixBadRequestException from cmd3");
            }

            try
            {
                cmd4.Execute();
            }
            catch (HystrixBadRequestException)
            {
                output.WriteLine("ReqLog" + "@ " + Time.CurrentTimeMillis + " : " + "Caught expected HystrixBadRequestException from cmd4");
            }

            Assert.True(WaitForHealthCountToUpdate(key, 250), "Health count stream took to long");

            output.WriteLine("ReqLog" + "@ " + Time.CurrentTimeMillis + " : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString());
            Assert.Equal(50, metrics.Healthcounts.ErrorPercentage);

            HystrixCommand <bool> cmd5 = new FailureCommand(key, 0);
            HystrixCommand <bool> cmd6 = new FailureCommand(key, 0);

            cmd5.Execute();
            cmd6.Execute();
            Assert.True(WaitForHealthCountToUpdate(key, 250), "Health count stream took to long");

            output.WriteLine("ReqLog" + "@ " + Time.CurrentTimeMillis + " : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString());
            Assert.Equal(75, metrics.Healthcounts.ErrorPercentage);
        }
        public void TestBadRequestsDoNotAffectErrorPercentage()
        {
            string key = "cmd-metrics-B";

            HystrixCommand <bool> cmd1    = new SuccessCommand(key, 1);
            HystrixCommandMetrics metrics = cmd1._metrics;

            cmd1.Execute();
            Time.Wait(200);

            output.WriteLine("ReqLog : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString());
            Assert.Equal(0, metrics.Healthcounts.ErrorPercentage);

            HystrixCommand <bool> cmd2 = new FailureCommand(key, 1);

            cmd2.Execute();
            Time.Wait(200);

            output.WriteLine("ReqLog : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString());
            Assert.Equal(50, metrics.Healthcounts.ErrorPercentage);

            HystrixCommand <bool> cmd3 = new BadRequestCommand(key, 1);
            HystrixCommand <bool> cmd4 = new BadRequestCommand(key, 1);

            try
            {
                cmd3.Execute();
            }
            catch (HystrixBadRequestException)
            {
                output.WriteLine("Caught expected HystrixBadRequestException from cmd3");
            }

            try
            {
                cmd4.Execute();
            }
            catch (HystrixBadRequestException)
            {
                output.WriteLine("Caught expected HystrixBadRequestException from cmd4");
            }

            Time.Wait(200);

            output.WriteLine("ReqLog : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString());
            Assert.Equal(50, metrics.Healthcounts.ErrorPercentage);

            HystrixCommand <bool> cmd5 = new FailureCommand(key, 1);
            HystrixCommand <bool> cmd6 = new FailureCommand(key, 1);

            cmd5.Execute();
            cmd6.Execute();
            Time.Wait(200);

            output.WriteLine("ReqLog : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString());
            Assert.Equal(75, metrics.Healthcounts.ErrorPercentage);
        }