HystrixCommandMetrics extends HystrixMetrics { public int getCurrentConcurrentExecutionCount() { return concurrentExecutionCount.get(); } HystrixCommandMetrics(final HystrixCommandKey key, HystrixCommandGroupKey commandGroup, HystrixThreadPoolKey threadPoolKey, HystrixCommandProperties properties, HystrixEventNotifier eventNotifier); static HystrixCommandMetrics getInstance(HystrixCommandKey key, HystrixCommandGroupKey commandGroup, HystrixCommandProperties properties); static HystrixCommandMetrics getInstance(HystrixCommandKey key, HystrixCommandGroupKey commandGroup, HystrixThreadPoolKey threadPoolKey, HystrixCommandProperties properties); static HystrixCommandMetrics getInstance(HystrixCommandKey key); static Collection<HystrixCommandMetrics> getInstances(); HystrixCommandKey getCommandKey(); HystrixCommandGroupKey getCommandGroup(); HystrixThreadPoolKey getThreadPoolKey(); HystrixCommandProperties getProperties(); long getRollingCount(HystrixEventType eventType); long getCumulativeCount(HystrixEventType eventType); @Override long getCumulativeCount(HystrixRollingNumberEvent event); @Override long getRollingCount(HystrixRollingNumberEvent event); int getExecutionTimePercentile(double percentile); int getExecutionTimeMean(); int getTotalTimePercentile(double percentile); int getTotalTimeMean(); long getRollingMaxConcurrentExecutions(); int getCurrentConcurrentExecutionCount(); HealthCounts getHealthCounts(); static final Func2<long[], HystrixCommandCompletion, long[]> appendEventToBucket; static final Func2<long[], long[], long[]> bucketAggregator; }
@Test public void testCurrentConcurrentExecutionCount() throws InterruptedException { String key = "cmd-metrics-C"; HystrixCommandMetrics metrics = null; List<Observable<Boolean>> cmdResults = new ArrayList<Observable<Boolean>>(); int NUM_CMDS = 8; for (int i = 0; i < NUM_CMDS; i++) { HystrixCommand<Boolean> cmd = new SuccessCommand(key, 900); if (metrics == null) { metrics = cmd.metrics; } Observable<Boolean> eagerObservable = cmd.observe(); cmdResults.add(eagerObservable); } try { Thread.sleep(150); } catch (InterruptedException ie) { fail(ie.getMessage()); } System.out.println("ReqLog: " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString()); assertEquals(NUM_CMDS, metrics.getCurrentConcurrentExecutionCount()); final CountDownLatch latch = new CountDownLatch(1); Observable.merge(cmdResults).subscribe(new Subscriber<Boolean>() { @Override public void onCompleted() { System.out.println("All commands done"); latch.countDown(); } @Override public void onError(Throwable e) { System.out.println("Error duing command execution"); e.printStackTrace(); latch.countDown(); } @Override public void onNext(Boolean aBoolean) { } }); latch.await(10000, TimeUnit.MILLISECONDS); assertEquals(0, metrics.getCurrentConcurrentExecutionCount()); }