2525
2626public class HystrixThreadPoolMetricsTest {
2727
28- private static final HystrixCommandGroupKey groupKey = HystrixCommandGroupKey .Factory .asKey ("HystrixThreadPoolMetrics-UnitTest" );
29- private static final HystrixThreadPoolKey tpKey = HystrixThreadPoolKey .Factory .asKey ("HystrixThreadPoolMetrics-ThreadPool" );
28+ private static final HystrixCommandGroupKey groupKey = HystrixCommandGroupKey .Factory .asKey ("HystrixThreadPoolMetrics-UnitTest" );
29+ private static final HystrixThreadPoolKey tpKey = HystrixThreadPoolKey .Factory .asKey ("HystrixThreadPoolMetrics-ThreadPool" );
3030
3131 @ Before
3232 public void resetAll () {
33- HystrixThreadPoolMetrics .reset ();
34- }
33+ HystrixThreadPoolMetrics .reset ();
34+ }
3535
36- @ Test
37- public void shouldYieldNoExecutedTasksOnStartup () throws Exception {
38- //given
39- final Collection <HystrixThreadPoolMetrics > instances = HystrixThreadPoolMetrics .getInstances ();
36+ @ Test
37+ public void shouldYieldNoExecutedTasksOnStartup () throws Exception {
38+ //given
39+ final Collection <HystrixThreadPoolMetrics > instances = HystrixThreadPoolMetrics .getInstances ();
4040
41- //then
42- assertEquals (0 , instances .size ());
41+ //then
42+ assertEquals (0 , instances .size ());
4343
44- }
45- @ Test
46- public void shouldReturnOneExecutedTask () throws Exception {
47- //given
48- final Collection <HystrixThreadPoolMetrics > instances = HystrixThreadPoolMetrics .getInstances ();
49- RollingThreadPoolEventCounterStream .getInstance (tpKey , 10 , 100 ).startCachingStreamValuesIfUnstarted ();
44+ }
45+ @ Test
46+ public void shouldReturnOneExecutedTask () throws Exception {
47+ //given
48+ RollingThreadPoolEventCounterStream .getInstance (tpKey , 10 , 100 ).startCachingStreamValuesIfUnstarted ();
5049
51- //when
52- new NoOpHystrixCommand (). execute ( );
50+ new NoOpHystrixCommand (). execute ();
51+ Thread . sleep ( 100 );
5352
54- //then
55- Thread .sleep (100 );
56- assertEquals (1 , instances .size ());
57- assertEquals (1 , instances .iterator ().next ().getRollingCountThreadsExecuted ());
58- }
53+ final Collection <HystrixThreadPoolMetrics > instances = HystrixThreadPoolMetrics .getInstances ();
5954
60- private static class NoOpHystrixCommand extends HystrixCommand <Void > {
61- public NoOpHystrixCommand () {
62- super (Setter .withGroupKey (groupKey )
55+ //then
56+ assertEquals (1 , instances .size ());
57+ HystrixThreadPoolMetrics metrics = instances .iterator ().next ();
58+ assertEquals (1 , instances .iterator ().next ().getRollingCountThreadsExecuted ());
59+ }
60+
61+ private static class NoOpHystrixCommand extends HystrixCommand <Void > {
62+ public NoOpHystrixCommand () {
63+ super (Setter .withGroupKey (groupKey )
6364 .andThreadPoolKey (tpKey )
6465 .andThreadPoolPropertiesDefaults (HystrixThreadPoolProperties .Setter ().withMetricsRollingStatisticalWindowInMilliseconds (100 )));
65- }
66+ }
6667
67- @ Override
68- protected Void run () throws Exception {
69- System .out .println ("Run in thread : " + Thread .currentThread ().getName ());
68+ @ Override
69+ protected Void run () throws Exception {
70+ System .out .println ("Run in thread : " + Thread .currentThread ().getName ());
7071 return null ;
71- }
72- }
73-
74-
72+ }
73+ }
7574}
0 commit comments