@@ -29,38 +29,22 @@ public class GracefulStopIT {
29
29
30
30
@ Test
31
31
void stopsGracefullyWIthTimeout () {
32
- var testRes = operator .create (testResource1 ());
33
- await ().untilAsserted (() -> {
34
- var r = operator .get (GracefulStopTestCustomResource .class , TEST_1 );
35
- assertThat (r .getStatus ()).isNotNull ();
36
- assertThat (r .getStatus ().getObservedGeneration ()).isEqualTo (1 );
37
- assertThat (operator .getReconcilerOfType (GracefulStopTestReconciler .class )
38
- .getNumberOfExecutions ()).isEqualTo (1 );
39
- });
40
-
41
- testRes .getSpec ().setValue (2 );
42
- operator .replace (testRes );
43
-
44
- await ().pollDelay (Duration .ofMillis (50 )).untilAsserted (
45
- () -> assertThat (operator .getReconcilerOfType (GracefulStopTestReconciler .class )
46
- .getNumberOfExecutions ()).isEqualTo (2 ));
47
-
48
- operator .getOperator ().stop (Duration .ofMillis (RECONCILER_SLEEP ));
49
-
50
- await ().untilAsserted (() -> {
51
- var r = operator .get (GracefulStopTestCustomResource .class , TEST_1 );
52
- assertThat (r .getStatus ()).isNotNull ();
53
- assertThat (r .getStatus ().getObservedGeneration ()).isEqualTo (2 );
54
- });
32
+ testGracefulStop (TEST_1 , RECONCILER_SLEEP , 2 );
55
33
}
56
34
57
35
@ Test
58
36
void stopsGracefullyWithExpiredTimeout () {
59
- var testRes = operator .create (testResource2 ());
37
+ testGracefulStop (TEST_2 , RECONCILER_SLEEP / 5 , 1 );
38
+ }
39
+
40
+ private void testGracefulStop (String resourceName , int stopTimeout , int expectedFinalGeneration ) {
41
+ var testRes = operator .create (testResource (resourceName ));
60
42
await ().untilAsserted (() -> {
61
- var r = operator .get (GracefulStopTestCustomResource .class , TEST_2 );
43
+ var r = operator .get (GracefulStopTestCustomResource .class , resourceName );
62
44
assertThat (r .getStatus ()).isNotNull ();
63
45
assertThat (r .getStatus ().getObservedGeneration ()).isEqualTo (1 );
46
+ assertThat (operator .getReconcilerOfType (GracefulStopTestReconciler .class )
47
+ .getNumberOfExecutions ()).isEqualTo (1 );
64
48
});
65
49
66
50
testRes .getSpec ().setValue (2 );
@@ -70,23 +54,15 @@ void stopsGracefullyWithExpiredTimeout() {
70
54
() -> assertThat (operator .getReconcilerOfType (GracefulStopTestReconciler .class )
71
55
.getNumberOfExecutions ()).isEqualTo (2 ));
72
56
73
- operator .getOperator ().stop (Duration .ofMillis (RECONCILER_SLEEP / 5 ));
57
+ operator .getOperator ().stop (Duration .ofMillis (stopTimeout ));
74
58
75
- await ().pollDelay ( Duration . ofMillis ( RECONCILER_SLEEP )). untilAsserted (() -> {
76
- var r = operator .get (GracefulStopTestCustomResource .class , TEST_2 );
59
+ await ().untilAsserted (() -> {
60
+ var r = operator .get (GracefulStopTestCustomResource .class , resourceName );
77
61
assertThat (r .getStatus ()).isNotNull ();
78
- assertThat (r .getStatus ().getObservedGeneration ()).isEqualTo (1 );
62
+ assertThat (r .getStatus ().getObservedGeneration ()).isEqualTo (expectedFinalGeneration );
79
63
});
80
64
}
81
65
82
- public GracefulStopTestCustomResource testResource1 () {
83
- return testResource (TEST_1 );
84
- }
85
-
86
- public GracefulStopTestCustomResource testResource2 () {
87
- return testResource (TEST_2 );
88
- }
89
-
90
66
public GracefulStopTestCustomResource testResource (String name ) {
91
67
GracefulStopTestCustomResource resource =
92
68
new GracefulStopTestCustomResource ();
0 commit comments