diff --git a/hystrix-contrib/hystrix-codahale-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/codahalemetricspublisher/HystrixCodaHaleMetricsPublisherCommand.java b/hystrix-contrib/hystrix-codahale-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/codahalemetricspublisher/HystrixCodaHaleMetricsPublisherCommand.java index 09f4f0e2a..88bbef9c3 100644 --- a/hystrix-contrib/hystrix-codahale-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/codahalemetricspublisher/HystrixCodaHaleMetricsPublisherCommand.java +++ b/hystrix-contrib/hystrix-codahale-metrics-publisher/src/main/java/com/netflix/hystrix/contrib/codahalemetricspublisher/HystrixCodaHaleMetricsPublisherCommand.java @@ -273,7 +273,7 @@ public HystrixRollingNumberEvent call() { } }); // the rolling number of MaxConcurrentExecutionCount. Can be used to determine saturation - safelyCreateRollingCountForEvent("rollingMaxConcurentExecutionCount", new Func0() { + safelyCreateRollingCountForEvent("rollingMaxConcurrentExecutionCount", new Func0() { @Override public HystrixRollingNumberEvent call() { return HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE; diff --git a/hystrix-contrib/hystrix-codahale-metrics-publisher/src/test/java/com/netflix/hystrix/contrib/codahalemetricspublisher/HystrixCodaHaleMetricsPublisherCommandTest.java b/hystrix-contrib/hystrix-codahale-metrics-publisher/src/test/java/com/netflix/hystrix/contrib/codahalemetricspublisher/HystrixCodaHaleMetricsPublisherCommandTest.java new file mode 100644 index 000000000..9cc95e16f --- /dev/null +++ b/hystrix-contrib/hystrix-codahale-metrics-publisher/src/test/java/com/netflix/hystrix/contrib/codahalemetricspublisher/HystrixCodaHaleMetricsPublisherCommandTest.java @@ -0,0 +1,46 @@ +package com.netflix.hystrix.contrib.codahalemetricspublisher; + +import com.codahale.metrics.Gauge; +import com.codahale.metrics.MetricRegistry; +import com.netflix.hystrix.HystrixCommand; +import com.netflix.hystrix.HystrixCommandGroupKey; +import com.netflix.hystrix.HystrixCommandKey; +import com.netflix.hystrix.strategy.HystrixPlugins; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.Map; + +public class HystrixCodaHaleMetricsPublisherCommandTest { + private final MetricRegistry metricRegistry = new MetricRegistry(); + + @Before + public void setup() { + HystrixPlugins.getInstance().registerMetricsPublisher(new HystrixCodaHaleMetricsPublisher(metricRegistry)); + } + + @After + public void teardown() { + HystrixPlugins.reset(); + } + + @Test + public void commandMaxActiveGauge() { + final HystrixCommandKey hystrixCommandKey = HystrixCommandKey.Factory.asKey("test"); + final HystrixCommandGroupKey hystrixCommandGroupKey = HystrixCommandGroupKey.Factory.asKey("test"); + + new HystrixCommand(HystrixCommand.Setter + .withGroupKey(hystrixCommandGroupKey) + .andCommandKey(hystrixCommandKey)) { + @Override + protected Void run() throws Exception { + return null; + } + }.execute(); + + for (Map.Entry entry : metricRegistry.getGauges().entrySet()) { + entry.getValue().getValue(); + } + } +} diff --git a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixEventType.java b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixEventType.java index e29798b26..0bf9a04d4 100644 --- a/hystrix-core/src/main/java/com/netflix/hystrix/HystrixEventType.java +++ b/hystrix-core/src/main/java/com/netflix/hystrix/HystrixEventType.java @@ -42,7 +42,8 @@ public enum HystrixEventType { EXCEPTION_THROWN(false), RESPONSE_FROM_CACHE(true), CANCELLED(true), - COLLAPSED(false); + COLLAPSED(false), + COMMAND_MAX_ACTIVE(false); private final boolean isTerminal; @@ -72,6 +73,7 @@ public static HystrixEventType from(HystrixRollingNumberEvent event) { case RESPONSE_FROM_CACHE: return RESPONSE_FROM_CACHE; case COLLAPSED: return COLLAPSED; case BAD_REQUEST: return BAD_REQUEST; + case COMMAND_MAX_ACTIVE: return COMMAND_MAX_ACTIVE; default: throw new RuntimeException("Not an event that can be converted to HystrixEventType : " + event); }