public void RequestLog_FailWithFallbackFailure() { HystrixRequestContext context = HystrixRequestContext.InitializeContext(); try { // 1 failure try { new TestCommand("A", true, true).Execute(); } catch (Exception) { } // 1 failure from cache try { new TestCommand("A", true, true).Execute(); } catch (Exception) { } String log = HystrixRequestLog.GetCurrentRequest().GetExecutedCommandsAsString(); // strip the actual count so we can compare reliably log = Regex.Replace(log, "\\[\\d*", "["); Assert.AreEqual("TestCommand[Failure, FallbackFailure][ms], TestCommand[Failure, FallbackFailure, ResponseFromCache][ms]", log); } finally { context.Shutdown(); } }
public void RequestLog_Success() { HystrixRequestContext context = HystrixRequestContext.InitializeContext(); try { new TestCommand("A", false, true).Execute(); String log = HystrixRequestLog.GetCurrentRequest().GetExecutedCommandsAsString(); // strip the actual count so we can compare reliably log = Regex.Replace(log, "\\[\\d*", "["); Assert.AreEqual("TestCommand[Success][ms]", log); } finally { context.Shutdown(); } }
public void RequestLog_MultipleCommands() { HystrixRequestContext context = HystrixRequestContext.InitializeContext(); try { // 1 success new TestCommand("GetData", "A", false, false).Execute(); // 1 success new TestCommand("PutData", "B", false, false).Execute(); // 1 success new TestCommand("GetValues", "C", false, false).Execute(); // 1 success from cache new TestCommand("GetValues", "C", false, false).Execute(); // 1 failure try { new TestCommand("A", true, true).Execute(); } catch (Exception) { } // 1 failure from cache try { new TestCommand("A", true, true).Execute(); } catch (Exception) { } String log = HystrixRequestLog.GetCurrentRequest().GetExecutedCommandsAsString(); // strip the actual count so we can compare reliably log = Regex.Replace(log, "\\[\\d*", "["); Assert.AreEqual("GetData[Success][ms], PutData[Success][ms], GetValues[Success][ms], GetValues[Success, ResponseFromCache][ms], TestCommand[Failure, FallbackFailure][ms], TestCommand[Failure, FallbackFailure, ResponseFromCache][ms]", log); } finally { context.Shutdown(); } }
public void RequestLog_MaxLimit() { HystrixRequestContext context = HystrixRequestContext.InitializeContext(); try { for (int i = 0; i < HystrixRequestLog.MaxStorage; i++) { new TestCommand("A", false, true).Execute(); } // then execute again some more for (int i = 0; i < 10; i++) { new TestCommand("A", false, true).Execute(); } Assert.AreEqual(HystrixRequestLog.MaxStorage, HystrixRequestLog.GetCurrentRequest().ExecutedCommands.Count()); } finally { context.Shutdown(); } }