Пример #1
0
        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);
        }
Пример #2
0
 internal void AddExecutedCommand(IHystrixInvokableInfo command)
 {
     if (!_allExecutedCommands.TryAdd(command))
     {
         // see RequestLog: Reduce Chance of Memory Leak https://github.com/Netflix/Hystrix/issues/53
         // logger.warn("RequestLog ignoring command after reaching limit of " + MAX_STORAGE + ". See https://github.com/Netflix/Hystrix/issues/53 for more information.");
     }
 }
 private void LogHC <T>(IHystrixInvokable command, T response)
 {
     if (command is IHystrixInvokableInfo)
     {
         IHystrixInvokableInfo commandInfo = (IHystrixInvokableInfo)command;
         HystrixCommandMetrics metrics     = commandInfo.Metrics;
         //output.WriteLine("cb/error-count/%/total: "
         //        + commandInfo.IsCircuitBreakerOpen + " "
         //        + metrics.Healthcounts.ErrorCount + " "
         //        + metrics.Healthcounts.ErrorPercentage + " "
         //        + metrics.Healthcounts.TotalRequests + "  => " + response + "  " + commandInfo.ExecutionEvents);
     }
 }
Пример #4
0
        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 AssertCommandExecutionEvents(IHystrixInvokableInfo command, params HystrixEventType[] expectedEventTypes)
        {
            bool emitExpected      = false;
            int  expectedEmitCount = 0;

            bool fallbackEmitExpected      = false;
            int  expectedFallbackEmitCount = 0;

            List <HystrixEventType> condensedEmitExpectedEventTypes = new List <HystrixEventType>();

            foreach (HystrixEventType expectedEventType in expectedEventTypes)
            {
                if (expectedEventType.Equals(HystrixEventType.EMIT))
                {
                    if (!emitExpected)
                    {
                        // first EMIT encountered, add it to condensedEmitExpectedEventTypes
                        condensedEmitExpectedEventTypes.Add(HystrixEventType.EMIT);
                    }

                    emitExpected = true;
                    expectedEmitCount++;
                }
                else if (expectedEventType.Equals(HystrixEventType.FALLBACK_EMIT))
                {
                    if (!fallbackEmitExpected)
                    {
                        // first FALLBACK_EMIT encountered, add it to condensedEmitExpectedEventTypes
                        condensedEmitExpectedEventTypes.Add(HystrixEventType.FALLBACK_EMIT);
                    }

                    fallbackEmitExpected = true;
                    expectedFallbackEmitCount++;
                }
                else
                {
                    condensedEmitExpectedEventTypes.Add(expectedEventType);
                }
            }

            List <HystrixEventType> actualEventTypes = command.ExecutionEvents;

            Assert.Equal(expectedEmitCount, command.NumberEmissions);
            Assert.Equal(expectedFallbackEmitCount, command.NumberFallbackEmissions);
            Assert.Equal(condensedEmitExpectedEventTypes, actualEventTypes);
        }
Пример #6
0
 public static ExecutionSignature From(IHystrixInvokableInfo execution, string cacheKey, int cachedCount)
 {
     return(new ExecutionSignature(execution.CommandKey, execution.EventCounts, cacheKey, cachedCount, execution.OriginatingCollapserKey, execution.NumberCollapsed));
 }
Пример #7
0
 public static ExecutionSignature From(IHystrixInvokableInfo execution)
 {
     return(new ExecutionSignature(execution.CommandKey, execution.EventCounts, null, 0, execution.OriginatingCollapserKey, execution.NumberCollapsed));
 }