-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get CodaHale metrics working by starting up the stream consumers #1586
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ | |
|
||
import java.util.Map; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class HystrixCodaHaleMetricsPublisherCommandTest { | ||
private final MetricRegistry metricRegistry = new MetricRegistry(); | ||
|
||
|
@@ -20,27 +23,28 @@ public void setup() { | |
HystrixPlugins.getInstance().registerMetricsPublisher(new HystrixCodaHaleMetricsPublisher(metricRegistry)); | ||
} | ||
|
||
@After | ||
public void teardown() { | ||
HystrixPlugins.reset(); | ||
@Test | ||
public void testCommandSuccess() throws InterruptedException { | ||
Command command = new Command(); | ||
command.execute(); | ||
|
||
Thread.sleep(1000); | ||
|
||
assertThat((Long) metricRegistry.getGauges().get("test.test.countSuccess").getValue(), is(1L)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm ... should this also test the other gauges ? RollingCommandEventCounterStream Which stream to timeouts happen on ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, more test coverage here would be great. Would you like to submit a PR? |
||
|
||
} | ||
|
||
@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(); | ||
private static class Command extends HystrixCommand<Void> { | ||
final static HystrixCommandKey hystrixCommandKey = HystrixCommandKey.Factory.asKey("test"); | ||
final static HystrixCommandGroupKey hystrixCommandGroupKey = HystrixCommandGroupKey.Factory.asKey("test"); | ||
|
||
Command() { | ||
super(Setter.withGroupKey(hystrixCommandGroupKey).andCommandKey(hystrixCommandKey)); | ||
} | ||
|
||
@Override | ||
protected Void run() throws Exception { | ||
return null; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
surely you can use await here instead of sleep from https://github.com/awaitility/awaitility
such as
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could, but then I introduce an extra dependency for this specific test. You could argue that a utility like this should be applied across all of the unit tests. My personal opinions is that the current state isn't enhanced by that much by a wholesale change to this style, but I'm happy to be convinced otherwise