Ejemplo n.º 1
0
        public void Command_QueueFailureWithFallbackFailure()
        {
            TestHystrixCommand<bool> command = new KnownFailureTestCommandWithFallbackFailure();
            try
            {
                command.Queue().Get();
                Assert.Fail("we shouldn't get here");
            }
            catch (Exception e)
            {
                if (e.InnerException is HystrixRuntimeException)
                {
                    HystrixRuntimeException de = (HystrixRuntimeException)e.InnerException;

                    Assert.IsNotNull(de.FallbackException);
                }
                else
                {
                    Assert.Fail("the cause should be HystrixRuntimeException");
                }
            }

            Assert.IsTrue(command.ExecutionTimeInMilliseconds > -1);
            Assert.IsTrue(command.IsFailedExecution);

            Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.Success));
            Assert.AreEqual(1, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.ExceptionThrown));
            Assert.AreEqual(1, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.Failure));
            Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.FallbackRejection));
            Assert.AreEqual(1, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.FallbackFailure));
            Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.FallbackSuccess));
            Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.SemaphoreRejected));
            Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.ShortCircuited));
            Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.ThreadPoolRejected));
            Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.Timeout));
            Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.ResponseFromCache));

            Assert.AreEqual(100, command.Builder.Metrics.GetHealthCounts().ErrorPercentage);

            Assert.AreEqual(1, HystrixRequestLog.GetCurrentRequest().ExecutedCommands.Count());

            Hystrix.Reset();
        }
Ejemplo n.º 2
0
        public void Command_ExecutionHookRunFailureWithFallbackFailure()
        {
            /* test with Execute() */
            TestHystrixCommand<bool> command = new KnownFailureTestCommandWithFallbackFailure();
            try
            {
                command.Execute();
                Assert.Fail("Expecting exception");
            }
            catch (Exception)
            {
                // ignore
            }

            // the run() method should run as we're not short-circuited or rejected
            Assert.AreEqual(1, command.Builder.ExecutionHook.StartRun);
            // we should not have a response because run() and fallback fail
            Assert.IsNull(command.Builder.ExecutionHook.RunSuccessResponse);
            // we should have an exception because run() and fallback fail
            Assert.IsNotNull(command.Builder.ExecutionHook.RunFailureException);

            // the fallback() method should be run since run() failed
            Assert.AreEqual(1, command.Builder.ExecutionHook.StartFallback);
            // no response since fallback fails
            Assert.IsNull(command.Builder.ExecutionHook.FallbackSuccessResponse);
            // not null since it's implemented but fails
            Assert.IsNotNull(command.Builder.ExecutionHook.FallbackFailureException);

            // the Execute() method was used
            Assert.AreEqual(1, command.Builder.ExecutionHook.StartExecute);
            // we should not have a response because run() and fallback fail
            Assert.IsNull(command.Builder.ExecutionHook.EndExecuteSuccessResponse);
            // we should have an exception because run() and fallback fail
            Assert.IsNotNull(command.Builder.ExecutionHook.EndExecuteFailureException);
            // run() failure
            Assert.AreEqual(FailureType.CommandException, command.Builder.ExecutionHook.EndExecuteFailureType);

            // thread execution
            Assert.AreEqual(1, command.Builder.ExecutionHook.ThreadStart);
            Assert.AreEqual(1, command.Builder.ExecutionHook.ThreadComplete);

            /* test with queue() */
            command = new KnownFailureTestCommandWithFallbackFailure();
            try
            {
                command.Queue().Get();
                Assert.Fail("Expecting exception");
            }
            catch (Exception)
            {
                // ignore
            }

            // the run() method should run as we're not short-circuited or rejected
            Assert.AreEqual(1, command.Builder.ExecutionHook.StartRun);
            // we should not have a response because run() and fallback fail
            Assert.IsNull(command.Builder.ExecutionHook.RunSuccessResponse);
            // we should have an exception because run() and fallback fail
            Assert.IsNotNull(command.Builder.ExecutionHook.RunFailureException);

            // the fallback() method should be run since run() failed
            Assert.AreEqual(1, command.Builder.ExecutionHook.StartFallback);
            // no response since fallback fails
            Assert.IsNull(command.Builder.ExecutionHook.FallbackSuccessResponse);
            // not null since it's implemented but fails
            Assert.IsNotNull(command.Builder.ExecutionHook.FallbackFailureException);

            // the queue() method was used
            Assert.AreEqual(1, command.Builder.ExecutionHook.StartExecute);
            // we should not have a response because run() and fallback fail
            Assert.IsNull(command.Builder.ExecutionHook.EndExecuteSuccessResponse);
            // we should have an exception because run() and fallback fail
            Assert.IsNotNull(command.Builder.ExecutionHook.EndExecuteFailureException);
            // run() failure
            Assert.AreEqual(FailureType.CommandException, command.Builder.ExecutionHook.EndExecuteFailureType);

            // thread execution
            Assert.AreEqual(1, command.Builder.ExecutionHook.ThreadStart);
            Assert.AreEqual(1, command.Builder.ExecutionHook.ThreadComplete);
            Hystrix.Reset();
        }