20
20
import org .junit .jupiter .api .BeforeEach ;
21
21
import org .junit .jupiter .api .Test ;
22
22
23
+ import java .time .Duration ;
24
+
23
25
import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
26
+ import static org .awaitility .Awaitility .await ;
24
27
import static org .junit .jupiter .api .Assumptions .assumeTrue ;
25
28
26
29
/**
@@ -43,21 +46,21 @@ void setup() {
43
46
44
47
@ Test
45
48
void cpuMetrics () {
46
- assertThat (registry .get ("system.cpu.count" ).gauge ().value ()).isGreaterThan ( 0 );
49
+ assertThat (registry .get ("system.cpu.count" ).gauge ().value ()).isPositive ( );
47
50
if (System .getProperty ("os.name" ).toLowerCase ().contains ("win" )) {
48
51
assertThat (registry .find ("system.load.average.1m" ).gauge ()).describedAs ("Not present on windows" ).isNull ();
49
52
}
50
53
else {
51
- assertThat (registry .get ("system.load.average.1m" ).gauge ().value ()).isGreaterThanOrEqualTo ( 0 );
54
+ assertThat (registry .get ("system.load.average.1m" ).gauge ().value ()).isNotNegative ( );
52
55
}
53
56
}
54
57
55
58
@ Test
56
59
void hotspotCpuMetrics () {
57
60
assumeTrue (!isOpenJ9 ());
58
61
59
- assertThat (registry .get ("system.cpu.usage" ).gauge ().value ()).isGreaterThanOrEqualTo ( 0 );
60
- assertThat (registry .get ("process.cpu.usage" ).gauge ().value ()).isGreaterThanOrEqualTo ( 0 );
62
+ assertThat (registry .get ("system.cpu.usage" ).gauge ().value ()).isNotNegative ( );
63
+ assertThat (registry .get ("process.cpu.usage" ).gauge ().value ()).isNotNegative ( );
61
64
}
62
65
63
66
@ Test
@@ -69,11 +72,13 @@ void openJ9CpuMetrics() {
69
72
* value - if supported - on subsequent calls. This holds true for
70
73
* "system.cpu.usage" but not for "process.cpu.usage". The latter needs some
71
74
* milliseconds of sleep before it actually returns a positive value on a
72
- * supported system. Thread.sleep() is flaky, though.
75
+ * supported system.
73
76
*/
74
77
assertThat (registry .get ("system.cpu.usage" ).gauge ().value ()).isGreaterThanOrEqualTo (-1 );
75
- assertThat (registry .get ("system.cpu.usage" ).gauge ().value ()).isGreaterThan ( 0 );
78
+ assertThat (registry .get ("system.cpu.usage" ).gauge ().value ()).isPositive ( );
76
79
assertThat (registry .get ("process.cpu.usage" ).gauge ().value ()).isGreaterThanOrEqualTo (-1 );
80
+ await ().atMost (Duration .ofMillis (200 ))
81
+ .untilAsserted (() -> assertThat (registry .get ("process.cpu.usage" ).gauge ().value ()).isPositive ());
77
82
}
78
83
79
84
private boolean isOpenJ9 () {
0 commit comments