1
1
package com .github .containersolutions .operator ;
2
2
3
3
import com .github .containersolutions .operator .sample .TestCustomResource ;
4
- import com .github .containersolutions .operator .sample .TestCustomResourceSpec ;
5
4
import io .fabric8 .kubernetes .api .model .ConfigMap ;
6
- import io .fabric8 .kubernetes .api .model .ObjectMetaBuilder ;
7
5
import org .awaitility .Awaitility ;
8
6
import org .junit .jupiter .api .*;
9
7
10
8
import java .util .List ;
11
9
import java .util .concurrent .TimeUnit ;
12
10
11
+ import static com .github .containersolutions .operator .IntegrationTestSupport .TEST_CUSTOM_RESOURCE_PREFIX ;
12
+ import static com .github .containersolutions .operator .IntegrationTestSupport .TEST_NAMESPACE ;
13
13
import static org .assertj .core .api .Assertions .assertThat ;
14
14
15
15
@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
16
16
public class ConcurrencyTest {
17
17
18
- private IntegrationTest integrationTest = new IntegrationTest ();
18
+ public static final int NUMBER_OF_RESOURCES_CREATED = 35 ;
19
+ public static final int NUMBER_OF_RESOURCES_DELETED = 10 ;
20
+ public static final int NUMBER_OF_RESOURCES_UPDATED = 15 ;
21
+ public static final String UPDATED_SUFFIX = "_updated" ;
22
+ private IntegrationTestSupport integrationTest = new IntegrationTestSupport ();
19
23
20
24
@ BeforeAll
21
25
public void setup () {
22
- integrationTest .setup ();
26
+ integrationTest .initialize ();
23
27
}
24
28
25
29
@ BeforeEach
@@ -32,70 +36,60 @@ public void teardown() {
32
36
integrationTest .teardown ();
33
37
}
34
38
39
+
35
40
@ Test
36
- public void manyResourcesGetCreatedAndUpdated () {
37
- for (int i = 0 ; i < 35 ; i ++) {
38
- TestCustomResource tcr = createTCR (String .valueOf (i ));
39
- integrationTest .crOperations .inNamespace (IntegrationTest .TEST_NAMESPACE ).create (tcr );
40
- // if (i % 3 == 0) {
41
- // TestCustomResource newTcr = createTCR(String.valueOf(i));
42
- // integrationTest.crOperations.inNamespace(IntegrationTest.TEST_NAMESPACE).createOrReplace(newTcr);
43
- // }
41
+ public void manyResourcesGetCreatedUpdatedAndDeleted () {
42
+ for (int i = 0 ; i < NUMBER_OF_RESOURCES_CREATED ; i ++) {
43
+ TestCustomResource tcr = integrationTest .createTestCustomResource (String .valueOf (i ));
44
+ integrationTest .getCrOperations ().inNamespace (TEST_NAMESPACE ).create (tcr );
44
45
}
46
+
45
47
Awaitility .await ().atMost (1 , TimeUnit .MINUTES )
46
48
.untilAsserted (() -> {
47
- List <ConfigMap > items = integrationTest .k8sClient .configMaps ()
48
- .inNamespace (IntegrationTest . TEST_NAMESPACE )
49
+ List <ConfigMap > items = integrationTest .getK8sClient () .configMaps ()
50
+ .inNamespace (TEST_NAMESPACE )
49
51
.list ().getItems ();
50
52
assertThat (items ).hasSize (35 );
51
53
});
52
- }
53
-
54
54
55
- @ Test
56
- public void manyResourcesGetCreatedUpdatedAndDeleted () {
57
- for (int i = 0 ; i < 35 ; i ++) {
58
- TestCustomResource tcr = createTCR (String .valueOf (i ));
59
- integrationTest .crOperations .inNamespace (IntegrationTest .TEST_NAMESPACE ).create (tcr );
60
- // if (i % 3 == 0) {
61
- // TestCustomResource newTcr = createTCR(String.valueOf(i));
62
- // integrationTest.crOperations.inNamespace(IntegrationTest.TEST_NAMESPACE).createOrReplace(newTcr);
63
- // }
55
+ // update some resources
56
+ for (int i = 0 ; i < NUMBER_OF_RESOURCES_UPDATED ; i ++) {
57
+ TestCustomResource tcr = integrationTest .createTestCustomResource (String .valueOf (i ));
58
+ tcr .getSpec ().setValue (i + UPDATED_SUFFIX );
59
+ integrationTest .getCrOperations ().inNamespace (TEST_NAMESPACE ).createOrReplace (tcr );
64
60
}
65
61
66
62
Awaitility .await ().atMost (1 , TimeUnit .MINUTES )
67
63
.untilAsserted (() -> {
68
- List <ConfigMap > items = integrationTest .k8sClient . configMaps ()
69
- .inNamespace (IntegrationTest . TEST_NAMESPACE )
64
+ List <TestCustomResource > crs = integrationTest .getCrOperations ()
65
+ .inNamespace (TEST_NAMESPACE )
70
66
.list ().getItems ();
71
- assertThat (items ).hasSize (35 );
67
+ for (int i = 0 ; i < NUMBER_OF_RESOURCES_UPDATED ; i ++) {
68
+ final int k = i ;
69
+ TestCustomResource testCustomResource = crs .stream ().filter (c -> c .getMetadata ().getName ().equals (TEST_CUSTOM_RESOURCE_PREFIX + k )).findFirst ().get ();
70
+ assertThat (testCustomResource .getSpec ().getValue ()).isEqualTo (i + UPDATED_SUFFIX );
71
+ }
72
72
});
73
73
74
- for (int i = 0 ; i < 10 ; i ++) {
75
- TestCustomResource tcr = createTCR (String .valueOf (i ));
76
- integrationTest .crOperations .inNamespace (IntegrationTest .TEST_NAMESPACE ).delete (tcr );
74
+ // deleting some resources
75
+ for (int i = 0 ; i < NUMBER_OF_RESOURCES_DELETED ; i ++) {
76
+ TestCustomResource tcr = integrationTest .createTestCustomResource (String .valueOf (i ));
77
+ integrationTest .getCrOperations ().inNamespace (TEST_NAMESPACE ).delete (tcr );
77
78
}
78
79
79
80
Awaitility .await ().atMost (1 , TimeUnit .MINUTES )
80
81
.untilAsserted (() -> {
81
- List <ConfigMap > items = integrationTest .k8sClient .configMaps ()
82
- .inNamespace (IntegrationTest .TEST_NAMESPACE )
82
+ List <ConfigMap > items = integrationTest .getK8sClient ().configMaps ()
83
+ .inNamespace (TEST_NAMESPACE )
84
+ .list ().getItems ();
85
+ assertThat (items ).hasSize (NUMBER_OF_RESOURCES_CREATED - NUMBER_OF_RESOURCES_DELETED );
86
+
87
+ List <TestCustomResource > crs = integrationTest .getCrOperations ()
88
+ .inNamespace (TEST_NAMESPACE )
83
89
.list ().getItems ();
84
- assertThat (items ).hasSize (25 );
90
+ assertThat (crs ).hasSize (NUMBER_OF_RESOURCES_CREATED - NUMBER_OF_RESOURCES_DELETED );
85
91
});
86
92
}
87
93
88
- private TestCustomResource createTCR (String id ) {
89
- TestCustomResource resource = new TestCustomResource ();
90
- resource .setMetadata (new ObjectMetaBuilder ()
91
- .withName ("test-custom-resource-" + id )
92
- .withNamespace (IntegrationTest .TEST_NAMESPACE )
93
- .build ());
94
- resource .setKind ("CustomService" );
95
- resource .setSpec (new TestCustomResourceSpec ());
96
- resource .getSpec ().setConfigMapName ("test-config-map-" + id );
97
- resource .getSpec ().setKey ("test-key" );
98
- resource .getSpec ().setValue (id );
99
- return resource ;
100
- }
94
+
101
95
}
0 commit comments