File tree Expand file tree Collapse file tree 2 files changed +5
-32
lines changed
main/java/com/yammer/metrics
test/java/com/yammer/metrics/tests Expand file tree Collapse file tree 2 files changed +5
-32
lines changed Original file line number Diff line number Diff line change 1
1
package com .yammer .metrics ;
2
2
3
- import com .yammer .metrics .core .HealthCheck ;
4
- import com .yammer .metrics .core .HealthCheck .Result ;
5
3
import com .yammer .metrics .core .HealthCheckRegistry ;
6
4
7
- import java .util .Map ;
8
-
9
5
/**
10
- * A manager class for health checks .
6
+ * A default health check registry .
11
7
*/
12
8
public class HealthChecks {
13
9
private static final HealthCheckRegistry DEFAULT_REGISTRY = new HealthCheckRegistry ();
14
10
15
11
private HealthChecks () { /* unused */ }
16
12
17
- /**
18
- * Registers an application {@link HealthCheck} with a given name.
19
- *
20
- * @param healthCheck the {@link HealthCheck} instance
21
- */
22
- public static void register (HealthCheck healthCheck ) {
23
- DEFAULT_REGISTRY .register (healthCheck );
24
- }
25
-
26
- /**
27
- * Runs the registered health checks and returns a map of the results.
28
- *
29
- * @return a map of the health check results
30
- */
31
- public static Map <String , Result > runHealthChecks () {
32
- return DEFAULT_REGISTRY .runHealthChecks ();
33
- }
34
-
35
13
/**
36
14
* Returns the (static) default registry.
37
15
*
Original file line number Diff line number Diff line change 8
8
9
9
import java .util .Map ;
10
10
11
- import static org .hamcrest .Matchers .instanceOf ;
12
11
import static org .hamcrest .Matchers .is ;
13
12
import static org .junit .Assert .assertThat ;
14
13
15
14
public class HealthChecksTest {
15
+ private final HealthCheckRegistry registry = HealthChecks .defaultRegistry ();
16
+
16
17
private static class ExampleHealthCheck extends HealthCheck {
17
18
private ExampleHealthCheck () {
18
19
super ("example" );
@@ -26,20 +27,14 @@ protected Result check() throws Exception {
26
27
27
28
@ Before
28
29
public void setUp () throws Exception {
29
- HealthChecks .register (new ExampleHealthCheck ());
30
+ registry .register (new ExampleHealthCheck ());
30
31
}
31
32
32
33
@ Test
33
34
public void runsRegisteredHealthChecks () throws Exception {
34
- final Map <String , HealthCheck .Result > results = HealthChecks .runHealthChecks ();
35
+ final Map <String , HealthCheck .Result > results = registry .runHealthChecks ();
35
36
36
37
assertThat (results .get ("example" ),
37
38
is (HealthCheck .Result .healthy ("whee" )));
38
39
}
39
-
40
- @ Test
41
- public void hasADefaultRegistry () throws Exception {
42
- assertThat (HealthChecks .defaultRegistry (),
43
- is (instanceOf (HealthCheckRegistry .class )));
44
- }
45
40
}
You can’t perform that action at this time.
0 commit comments