public void Command_ExecutionHookRunFailureWithoutFallback() { /* test with Execute() */ TestHystrixCommand<bool> command = new UnknownFailureTestCommandWithoutFallback(); 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 Assert.IsNull(command.Builder.ExecutionHook.RunSuccessResponse); // we should have an exception 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 is not implemented Assert.IsNull(command.Builder.ExecutionHook.FallbackSuccessResponse); // not null since it's not implemented and throws an exception Assert.IsNotNull(command.Builder.ExecutionHook.FallbackFailureException); // the Execute() method was used Assert.AreEqual(1, command.Builder.ExecutionHook.StartExecute); // we should not have a response from Execute() since we do not have a fallback and run() failed Assert.IsNull(command.Builder.ExecutionHook.EndExecuteSuccessResponse); // we should have an exception since run() failed 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 UnknownFailureTestCommandWithoutFallback(); 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 Assert.IsNull(command.Builder.ExecutionHook.RunSuccessResponse); // we should have an exception 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 is not implemented Assert.IsNull(command.Builder.ExecutionHook.FallbackSuccessResponse); // not null since it's not implemented and throws an exception Assert.IsNotNull(command.Builder.ExecutionHook.FallbackFailureException); // the queue() method was used Assert.AreEqual(1, command.Builder.ExecutionHook.StartExecute); // we should not have a response from queue() since we do not have a fallback and run() failed Assert.IsNull(command.Builder.ExecutionHook.EndExecuteSuccessResponse); // we should have an exception since run() failed 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(); }
public void Command_ExecutionUnknownFailureWithNoFallback() { TestHystrixCommand<bool> command = new UnknownFailureTestCommandWithoutFallback(); try { command.Execute(); Assert.Fail("we shouldn't get here"); } catch (HystrixRuntimeException e) { Assert.IsNotNull(e.FallbackException); Assert.IsNotNull(e.CommandType); } catch (Exception) { Assert.Fail("We should always get an HystrixRuntimeException when an error occurs."); } 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(0, 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(); }