Skip to content

Commit

Permalink
Fixing Netflix#1508
Browse files Browse the repository at this point in the history
  • Loading branch information
cgray committed Mar 23, 2017
1 parent c1d4bb6 commit fc24382
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public HystrixRollingNumberEvent call() {
}
});
// the rolling number of MaxConcurrentExecutionCount. Can be used to determine saturation
safelyCreateRollingCountForEvent("rollingMaxConcurentExecutionCount", new Func0<HystrixRollingNumberEvent>() {
safelyCreateRollingCountForEvent("rollingMaxConcurrentExecutionCount", new Func0<HystrixRollingNumberEvent>() {
@Override
public HystrixRollingNumberEvent call() {
return HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Void>(HystrixCommand.Setter
.withGroupKey(hystrixCommandGroupKey)
.andCommandKey(hystrixCommandKey)) {
@Override
protected Void run() throws Exception {
return null;
}
}.execute();

for (Map.Entry<String, Gauge> entry : metricRegistry.getGauges().entrySet()) {
entry.getValue().getValue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit fc24382

Please sign in to comment.