16
16
17
17
import com .meterware .httpunit .Base64 ;
18
18
import com .meterware .simplestub .Memento ;
19
- import io .kubernetes .client .openapi .models .V1ObjectMeta ;
20
19
import io .kubernetes .client .openapi .models .V1Service ;
21
- import io .kubernetes .client .openapi .models .V1ServiceSpec ;
20
+ import io .kubernetes .client .openapi .models .V1ServiceBuilder ;
22
21
import oracle .kubernetes .operator .DomainProcessorTestSetup ;
23
22
import oracle .kubernetes .operator .helpers .DomainPresenceInfo ;
24
23
import oracle .kubernetes .operator .helpers .KubernetesTestSupport ;
@@ -76,10 +75,6 @@ class ReadHealthStepTest {
76
75
private static final String DYNAMIC_MANAGED_SERVER2 = "dyn-managed-server2" ;
77
76
78
77
private static final ClassCastException CLASSCAST_EXCEPTION = new ClassCastException ("" );
79
- static final String MS1_URL = "http://127.0.0.1:7001" ;
80
- private final V1Service service = createStub (V1ServiceStub .class );
81
- private final V1Service headlessService = createStub (V1HeadlessServiceStub .class );
82
- private final V1Service headlessMSService = createStub (V1HeadlessMSServiceStub .class );
83
78
private final List <LogRecord > logRecords = new ArrayList <>();
84
79
private final List <Memento > mementos = new ArrayList <>();
85
80
private final KubernetesTestSupport testSupport = new KubernetesTestSupport ();
@@ -123,22 +118,15 @@ private int getRemainingServersToRead(Packet packet) {
123
118
return ((AtomicInteger ) packet .get (REMAINING_SERVERS_HEALTH_TO_READ )).get ();
124
119
}
125
120
126
- private void selectServer (String serverName ) {
127
- selectServer ( serverName , false );
121
+ private V1Service createService (String serverName ) {
122
+ return new V1ServiceBuilder (). withNewMetadata (). withName ( serverName ). withNamespace ( "Test" ). endMetadata (). build ( );
128
123
}
129
124
130
- private void selectServer (String serverName , V1Service service ) {
125
+ private V1Service selectServer (String serverName ) {
126
+ V1Service service = createService (serverName );
131
127
testSupport .addToPacket (SERVER_NAME , serverName );
132
128
info .setServerService (serverName , service );
133
- }
134
-
135
- private void selectServer (String serverName , boolean headless ) {
136
- testSupport .addToPacket (SERVER_NAME , serverName );
137
- if (headless ) {
138
- info .setServerService (serverName , headlessService );
139
- } else {
140
- info .setServerService (serverName , service );
141
- }
129
+ return service ;
142
130
}
143
131
144
132
@ AfterEach
@@ -149,7 +137,7 @@ public void tearDown() {
149
137
@ Test
150
138
void whenReadAdminServerHealth_decrementRemainingServers () {
151
139
selectServer (ADMIN_NAME );
152
- defineResponse (200 , OK_RESPONSE , "http://127.0.0.1 :3456" );
140
+ defineResponse (200 , OK_RESPONSE , "http://" + ADMIN_NAME + ".Test :3456" );
153
141
154
142
Packet packet = testSupport .runSteps (readHealthStep );
155
143
@@ -165,9 +153,9 @@ private void defineResponse(int status, String body, @Nonnull String url) {
165
153
166
154
@ Test
167
155
void whenReadConfiguredManagedServerHealth_decrementRemainingServers () {
168
- selectServer (CONFIGURED_MANAGED_SERVER1 );
169
- configureServiceWithClusterName (CONFIGURED_CLUSTER_NAME );
170
- defineResponse (200 , OK_RESPONSE , MS1_URL );
156
+ V1Service service = selectServer (CONFIGURED_MANAGED_SERVER1 );
157
+ configureServiceWithClusterName (CONFIGURED_CLUSTER_NAME , service );
158
+ defineResponse (200 , OK_RESPONSE , "http://" + CONFIGURED_MANAGED_SERVER1 + ".Test:7001" );
171
159
172
160
Packet packet = testSupport .runSteps (readHealthStep );
173
161
@@ -179,9 +167,9 @@ void whenReadConfiguredManagedServerHealth_decrementRemainingServers() {
179
167
180
168
@ Test
181
169
void whenReadDynamicManagedServerHealth_decrementRemainingServers () {
182
- selectServer (DYNAMIC_MANAGED_SERVER1 );
183
- configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME );
184
- defineResponse (200 , OK_RESPONSE , MS1_URL );
170
+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER1 );
171
+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
172
+ defineResponse (200 , OK_RESPONSE , "http://" + DYNAMIC_MANAGED_SERVER1 + ".Test:7001" );
185
173
186
174
Packet packet = testSupport .runSteps (readHealthStep );
187
175
@@ -192,7 +180,7 @@ void whenReadDynamicManagedServerHealth_decrementRemainingServers() {
192
180
void whenServerRunning_verifyServerHealth () {
193
181
selectServer (MANAGED_SERVER1 );
194
182
195
- defineResponse (200 , OK_RESPONSE , "http://127.0.0.1 :8001" );
183
+ defineResponse (200 , OK_RESPONSE , "http://" + MANAGED_SERVER1 + ".Test :8001" );
196
184
197
185
Packet packet = testSupport .runSteps (readHealthStep );
198
186
@@ -210,7 +198,7 @@ private Map<String, String> getServerStateMap(Packet packet) {
210
198
211
199
@ Test
212
200
void whenAdminPodIPNull_verifyServerHealth () {
213
- selectServer (ADMIN_NAME , true );
201
+ selectServer (ADMIN_NAME );
214
202
defineResponse (200 , OK_RESPONSE , "http://admin-server.Test:3456" );
215
203
216
204
Packet packet = testSupport .runSteps (readHealthStep );
@@ -220,7 +208,7 @@ void whenAdminPodIPNull_verifyServerHealth() {
220
208
221
209
@ Test
222
210
void whenAdminPodIPNull_requestSendWithCredentials () {
223
- selectServer (ADMIN_NAME , true );
211
+ selectServer (ADMIN_NAME );
224
212
defineResponse (200 , OK_RESPONSE , "http://admin-server.Test:3456" );
225
213
226
214
testSupport .runSteps (readHealthStep );
@@ -244,7 +232,7 @@ private String expectedAuthorizationHeader() {
244
232
void whenServerOverloaded_verifyServerHealth () {
245
233
selectServer (MANAGED_SERVER1 );
246
234
247
- defineResponse (500 , "" , "http://127.0.0.1 :8001" );
235
+ defineResponse (500 , "" , "http://" + MANAGED_SERVER1 + ".Test :8001" );
248
236
249
237
Packet packet = testSupport .runSteps (readHealthStep );
250
238
@@ -257,7 +245,7 @@ void whenServerOverloaded_verifyServerHealth() {
257
245
void whenUnableToReadHealth_verifyNotAvailable () {
258
246
selectServer (MANAGED_SERVER1 );
259
247
260
- defineResponse (404 , "" , MS1_URL );
248
+ defineResponse (404 , "" , "http://" + MANAGED_SERVER1 + ".Test:8001" );
261
249
262
250
Packet packet = testSupport .runSteps (readHealthStep );
263
251
@@ -268,7 +256,8 @@ void whenUnableToReadHealth_verifyNotAvailable() {
268
256
269
257
@ Test
270
258
void whenServerConfiguredWithServerListenPortOnly_readHealthUsingServerListenPort () {
271
- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
259
+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
260
+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
272
261
WlsServerConfig server = getDynamicClusterServer2 ();
273
262
server .setListenPort (8001 );
274
263
defineExpectedURLInResponse ("http" , 8001 );
@@ -280,7 +269,8 @@ void whenServerConfiguredWithServerListenPortOnly_readHealthUsingServerListenPor
280
269
281
270
@ Test
282
271
void whenServerConfiguredWithSSLPortOnly_readHealthUsingSSLPort () {
283
- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
272
+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
273
+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
284
274
WlsServerConfig server = getDynamicClusterServer2 ();
285
275
server .setSslListenPort (7002 );
286
276
defineExpectedURLInResponse ("https" , 7002 );
@@ -292,7 +282,8 @@ void whenServerConfiguredWithSSLPortOnly_readHealthUsingSSLPort() {
292
282
293
283
@ Test
294
284
void whenServerConfiguredWithServerListenPortAndSSLPort_readHealthUsingSSLPort () {
295
- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
285
+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
286
+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
296
287
WlsServerConfig server = getDynamicClusterServer2 ();
297
288
server .setListenPort (8001 );
298
289
server .setSslListenPort (7002 );
@@ -305,7 +296,8 @@ void whenServerConfiguredWithServerListenPortAndSSLPort_readHealthUsingSSLPort()
305
296
306
297
@ Test
307
298
void whenServerConfiguredWithServerListenPortAndNonAdminNAP_readHealthUsingServerListenPort () {
308
- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
299
+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
300
+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
309
301
WlsServerConfig server = getDynamicClusterServer2 ();
310
302
server .setListenPort (8001 );
311
303
server .addNetworkAccessPoint (new NetworkAccessPoint ("nap1" , "t3" , 9001 , 9001 ));
@@ -318,7 +310,8 @@ void whenServerConfiguredWithServerListenPortAndNonAdminNAP_readHealthUsingServe
318
310
319
311
@ Test
320
312
void whenServerConfiguredWithServerSSLPortAndNonAdminNAP_readHealthUsingSSLPort () {
321
- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
313
+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
314
+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
322
315
WlsServerConfig server = getDynamicClusterServer2 ();
323
316
server .setSslListenPort (7002 );
324
317
server .addNetworkAccessPoint (new NetworkAccessPoint ("nap1" , "t3" , 9001 , 9001 ));
@@ -331,7 +324,8 @@ void whenServerConfiguredWithServerSSLPortAndNonAdminNAP_readHealthUsingSSLPort(
331
324
332
325
@ Test
333
326
void whenServerConfiguredWithSSLPortAndAdminNAP_readHealthUsingAdminNAPPort () {
334
- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
327
+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
328
+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
335
329
WlsServerConfig server = getDynamicClusterServer2 ();
336
330
server .setSslListenPort (7002 );
337
331
server .addNetworkAccessPoint (new NetworkAccessPoint ("admin" , "admin" , 8888 , 8888 ));
@@ -344,7 +338,8 @@ void whenServerConfiguredWithSSLPortAndAdminNAP_readHealthUsingAdminNAPPort() {
344
338
345
339
@ Test
346
340
void whenServerConfiguredWithServerListenPortAndAdminNAP_readHealthUsingAdminNAPPort () {
347
- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
341
+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
342
+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
348
343
WlsServerConfig server = getDynamicClusterServer2 ();
349
344
server .setListenPort (8001 );
350
345
server .setListenPort (null );
@@ -358,7 +353,8 @@ void whenServerConfiguredWithServerListenPortAndAdminNAP_readHealthUsingAdminNAP
358
353
359
354
@ Test
360
355
void whenServerConfiguredWithNonAdminNAPOnly_readHealthFailed () {
361
- selectServer (DYNAMIC_MANAGED_SERVER2 , headlessMSService );
356
+ V1Service service = selectServer (DYNAMIC_MANAGED_SERVER2 );
357
+ configureServiceWithClusterName (DYNAMIC_CLUSTER_NAME , service );
362
358
WlsServerConfig server = getDynamicClusterServer2 ();
363
359
server .addNetworkAccessPoint (new NetworkAccessPoint ("nap1" , "t3" , 9001 , 9001 ));
364
360
defineExpectedURLInResponse ("http" , 9001 );
@@ -398,7 +394,7 @@ void whenAuthorizedToReadHealthAndThenWait_verifySecretCleared() {
398
394
void whenNotAuthorizedToReadHealth_verifySecretCleared () {
399
395
selectServer (MANAGED_SERVER1 );
400
396
401
- defineResponse (403 , "" , "http://127.0.0.1 :8001" );
397
+ defineResponse (403 , "" , "http://" + MANAGED_SERVER1 + ".Test :8001" );
402
398
403
399
testSupport .runSteps (readHealthStep );
404
400
@@ -418,37 +414,8 @@ private WlsServerConfig getDynamicClusterServer2() {
418
414
return wlsDomainConfig .getClusterConfig (DYNAMIC_CLUSTER_NAME ).getServerConfigs ().get (1 );
419
415
}
420
416
421
- public abstract static class V1ServiceStub extends V1Service {
422
-
423
- @ Override
424
- public V1ServiceSpec getSpec () {
425
- return new V1ServiceSpec ().clusterIP ("127.0.0.1" );
426
- }
427
- }
428
-
429
- public abstract static class V1HeadlessServiceStub extends V1Service {
430
-
431
- @ Override
432
- public V1ObjectMeta getMetadata () {
433
- return new V1ObjectMeta ().name (ADMIN_NAME ).namespace ("Test" );
434
- }
435
-
436
- @ Override
437
- public V1ServiceSpec getSpec () {
438
- return new V1ServiceSpec ().clusterIP ("None" );
439
- }
440
- }
441
-
442
- public abstract static class V1HeadlessMSServiceStub extends V1Service {
443
- @ Override
444
- public V1ObjectMeta getMetadata () {
445
- return new V1ObjectMeta ().name (DYNAMIC_MANAGED_SERVER2 ).namespace ("Test" )
446
- .putLabelsItem (CLUSTERNAME_LABEL , DYNAMIC_CLUSTER_NAME );
447
- }
448
- }
449
-
450
- private void configureServiceWithClusterName (String clusterName ) {
451
- service .setMetadata (new V1ObjectMeta ().putLabelsItem (CLUSTERNAME_LABEL , clusterName ));
417
+ private void configureServiceWithClusterName (String clusterName , V1Service service ) {
418
+ service .getMetadata ().putLabelsItem (CLUSTERNAME_LABEL , clusterName );
452
419
}
453
420
454
421
}
0 commit comments