public void Command_ExecutionSuccess() { TestHystrixCommand<bool> command = new SuccessfulTestCommand(); Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.Failure)); Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.Timeout)); Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.Success)); Assert.AreEqual(true, command.Execute()); Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.Failure)); Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.Timeout)); Assert.AreEqual(1, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.Success)); Assert.AreEqual(null, command.FailedExecutionException); Assert.IsTrue(command.ExecutionTimeInMilliseconds > -1); Assert.IsTrue(command.IsSuccessfulExecution); Assert.AreEqual(0, command.Builder.Metrics.GetRollingCount(HystrixRollingNumberEvent.ExceptionThrown)); 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.ResponseFromCache)); Assert.AreEqual(0, command.Builder.Metrics.GetHealthCounts().ErrorPercentage); Assert.AreEqual(1, HystrixRequestLog.GetCurrentRequest().ExecutedCommands.Count()); Hystrix.Reset(); }
public void Command_ExecutionMultipleTimes() { SuccessfulTestCommand command = new SuccessfulTestCommand(); Assert.IsFalse(command.IsExecutionComplete); // first should succeed Assert.AreEqual(true, command.Execute()); Assert.IsTrue(command.IsExecutionComplete); Assert.IsTrue(command.IsExecutedInThread); Assert.IsTrue(command.ExecutionTimeInMilliseconds > -1); Assert.IsTrue(command.IsSuccessfulExecution); try { // second should fail command.Execute(); Assert.Fail("we should not allow this ... it breaks the state of request logs"); } catch (Exception) { // we want to get here } try { // queue should also fail command.Queue(); Assert.Fail("we should not allow this ... it breaks the state of request logs"); } catch (Exception) { // we want to get here } Hystrix.Reset(); }
public void Command_ExecutionHookSuccessfulCommand() { /* test with Execute() */ TestHystrixCommand<bool> command = new SuccessfulTestCommand(); command.Execute(); // the run() method should run as we're not short-circuited or rejected Assert.AreEqual(1, command.Builder.ExecutionHook.StartRun); // we expect a successful response from run() Assert.IsNotNull(command.Builder.ExecutionHook.RunSuccessResponse); // we do not expect an exception Assert.IsNull(command.Builder.ExecutionHook.RunFailureException); // the fallback() method should not be run as we were successful Assert.AreEqual(0, command.Builder.ExecutionHook.StartFallback); // null since it didn't run Assert.IsNull(command.Builder.ExecutionHook.FallbackSuccessResponse); // null since it didn't run Assert.IsNull(command.Builder.ExecutionHook.FallbackFailureException); // the Execute() method was used Assert.AreEqual(1, command.Builder.ExecutionHook.StartExecute); // we should have a response from Execute() since run() succeeded Assert.IsNotNull(command.Builder.ExecutionHook.EndExecuteSuccessResponse); // we should not have an exception since run() succeeded Assert.IsNull(command.Builder.ExecutionHook.EndExecuteFailureException); // thread execution Assert.AreEqual(1, command.Builder.ExecutionHook.ThreadStart); Assert.AreEqual(1, command.Builder.ExecutionHook.ThreadComplete); /* test with queue() */ command = new SuccessfulTestCommand(); try { command.Queue().Get(); } catch (Exception e) { throw new Exception("Unexpected exception.", e); } // the run() method should run as we're not short-circuited or rejected Assert.AreEqual(1, command.Builder.ExecutionHook.StartRun); // we expect a successful response from run() Assert.IsNotNull(command.Builder.ExecutionHook.RunSuccessResponse); // we do not expect an exception Assert.IsNull(command.Builder.ExecutionHook.RunFailureException); // the fallback() method should not be run as we were successful Assert.AreEqual(0, command.Builder.ExecutionHook.StartFallback); // null since it didn't run Assert.IsNull(command.Builder.ExecutionHook.FallbackSuccessResponse); // null since it didn't run Assert.IsNull(command.Builder.ExecutionHook.FallbackFailureException); // the queue() method was used Assert.AreEqual(1, command.Builder.ExecutionHook.StartExecute); // we should have a response from queue() since run() succeeded Assert.IsNotNull(command.Builder.ExecutionHook.EndExecuteSuccessResponse); // we should not have an exception since run() succeeded Assert.IsNull(command.Builder.ExecutionHook.EndExecuteFailureException); // thread execution Assert.AreEqual(1, command.Builder.ExecutionHook.ThreadStart); Assert.AreEqual(1, command.Builder.ExecutionHook.ThreadComplete); Hystrix.Reset(); }
public void Command_BasicExecutionWorksWithoutRequestVariable() { try { /* force the RequestVariable to not be initialized */ HystrixRequestContext.ContextForCurrentThread = null; TestHystrixCommand<bool> command = new SuccessfulTestCommand(); Assert.AreEqual(true, command.Execute()); TestHystrixCommand<bool> command2 = new SuccessfulTestCommand(); Assert.AreEqual(true, command2.Queue().Get()); // we should be able to execute without a RequestVariable if ... // 1) We don't have a cacheKey // 2) We don't ask for the RequestLog // 3) We don't do collapsing } catch (Exception e) { Assert.Fail("We received an exception => " + e.Message); } Hystrix.Reset(); }