Skip to content

Commit

Permalink
Merge pull request #678 from mattrjacobs/fix-current-concurrent-execu…
Browse files Browse the repository at this point in the history
…tion-count

Fix current concurrent execution count
  • Loading branch information
mattrjacobs committed Feb 13, 2015
2 parents 4352de6 + 8fa5106 commit cd7799a
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ final public Observable<R> toObservable() {
public void call(Subscriber<? super R> observer) {
// async record keeping
recordExecutedCommand();
metrics.incrementConcurrentExecutionCount();

// mark that we're starting execution on the ExecutionHook
executionHook.onStart(_this);
Expand Down Expand Up @@ -497,8 +498,6 @@ public void call() {
*/
private Observable<R> getRunObservableDecoratedForMetricsAndErrorHandling() {
final AbstractCommand<R> _self = this;
// allow tracking how many concurrent commands are executing
metrics.incrementConcurrentExecutionCount();

final HystrixRequestContext currentRequestContext = HystrixRequestContext.getContextForCurrentThread();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,43 @@ public void testBadRequestsDoNotAffectErrorPercentage() {
assertEquals(75, metrics.getHealthCounts().getErrorPercentage());
}

@Test
public void testCurrentConcurrentExecutionCount() {
class LatentCommand extends HystrixCommand<Boolean> {

long duration;

public LatentCommand(long duration) {
super(HystrixCommandGroupKey.Factory.asKey("Latent"), HystrixThreadPoolKey.Factory.asKey("Latent"), 1000);
this.duration = duration;
}

@Override
protected Boolean run() throws Exception {
Thread.sleep(duration);
return true;
}

@Override
protected Boolean getFallback() {
return false;
}
}

HystrixCommandMetrics metrics = null;

int NUM_CMDS = 8;
for (int i = 0; i < NUM_CMDS; i++) {
LatentCommand cmd = new LatentCommand(400);
if (metrics == null) {
metrics = cmd.metrics;
}
cmd.queue();
}

assertEquals(NUM_CMDS, metrics.getCurrentConcurrentExecutionCount());
}

/**
* Utility method for creating {@link HystrixCommandMetrics} for unit tests.
*/
Expand Down
Loading

0 comments on commit cd7799a

Please sign in to comment.