public void TestRequestCacheSubclassNoOverrides() { HystrixCommand <int> subCmd1 = new SubCommandNoOverride("cache", true); Assert.Equal(1, subCmd1.Execute()); HystrixCommand <int> subCmd2 = new SubCommandNoOverride("cache", true); Assert.Equal(1, subCmd2.Execute()); HystrixCommand <int> subCmd3 = new SubCommandNoOverride("no-cache", true); Assert.Equal(1, subCmd3.Execute()); output.WriteLine("REQ LOG : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString()); HystrixRequestLog reqLog = HystrixRequestLog.CurrentRequestLog; Assert.Equal(3, reqLog.AllExecutedCommands.Count); List <IHystrixInvokableInfo> infos = new List <IHystrixInvokableInfo>(reqLog.AllExecutedCommands); IHystrixInvokableInfo info1 = infos[0]; Assert.Equal("SubCommandNoOverride", info1.CommandKey.Name); Assert.Equal(1, info1.ExecutionEvents.Count); IHystrixInvokableInfo info2 = infos[1]; Assert.Equal("SubCommandNoOverride", info2.CommandKey.Name); Assert.Equal(2, info2.ExecutionEvents.Count); Assert.Equal(HystrixEventType.RESPONSE_FROM_CACHE, info2.ExecutionEvents[1]); IHystrixInvokableInfo info3 = infos[2]; Assert.Equal("SubCommandNoOverride", info3.CommandKey.Name); Assert.Equal(1, info3.ExecutionEvents.Count); }
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 TestRequestLogSubClassNoOverrides() { HystrixCommand <int> subCmd = new SubCommandNoOverride("cache", true); Assert.Equal(1, subCmd.Execute()); output.WriteLine("REQ LOG : " + HystrixRequestLog.CurrentRequestLog.GetExecutedCommandsAsString()); HystrixRequestLog reqLog = HystrixRequestLog.CurrentRequestLog; Assert.Equal(1, reqLog.AllExecutedCommands.Count); IHystrixInvokableInfo info = reqLog.AllExecutedCommands.ToList()[0]; Assert.Equal("SubCommandNoOverride", info.CommandKey.Name); }
protected void AssertSaneHystrixRequestLog(int numCommands) { HystrixRequestLog currentRequestLog = HystrixRequestLog.CurrentRequestLog; try { Assert.Equal(numCommands, currentRequestLog.AllExecutedCommands.Count); Assert.False(currentRequestLog.GetExecutedCommandsAsString().Contains("Executed")); Assert.True(currentRequestLog.AllExecutedCommands.First().ExecutionEvents.Count >= 1); //Most commands should have 1 execution event, but fallbacks / responses from cache can cause more than 1. They should never have 0 } catch (Exception) { //output.WriteLine("Problematic Request log : " + currentRequestLog.GetExecutedCommandsAsString() + " , expected : " + numCommands); throw; } }
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(); } }