69
69
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkClusterReplicaCountMatches ;
70
70
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
71
71
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
72
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
72
73
import static oracle .weblogic .kubernetes .utils .ConfigMapUtils .createConfigMapAndVerify ;
73
74
import static oracle .weblogic .kubernetes .utils .ExecCommand .exec ;
74
75
import static oracle .weblogic .kubernetes .utils .ImageUtils .createOcirRepoSecret ;
@@ -226,23 +227,23 @@ public void beforeEach() {
226
227
logger .info ("Check admin service/pod {0} is created in namespace {1}" ,
227
228
adminServerPodName , domainNamespace );
228
229
checkPodReadyAndServiceExists (adminServerPodName ,
229
- domainUid , domainNamespace );
230
+ domainUid , domainNamespace );
230
231
231
232
for (int i = 1 ; i <= replicaCount ; i ++) {
232
233
checkPodReadyAndServiceExists (managedServerPrefix + i ,
233
- domainUid , domainNamespace );
234
+ domainUid , domainNamespace );
234
235
}
235
236
236
- // Check configured cluster configuration is available
237
+ // Check configured cluster configuration is available
237
238
boolean isServerConfigured =
238
- checkManagedServerConfiguration (ingressHost , "config-cluster-server1" );
239
+ checkManagedServerConfiguration (ingressHost , "config-cluster-server1" );
239
240
assertTrue (isServerConfigured ,
240
241
"Could not find managed server from configured cluster" );
241
242
logger .info ("Found managed server from configured cluster" );
242
243
243
244
// Check standalone server configuration is available
244
245
boolean isStandaloneServerConfigured =
245
- checkManagedServerConfiguration (ingressHost , "standalone-managed" );
246
+ checkManagedServerConfiguration (ingressHost , "standalone-managed" );
246
247
assertTrue (isStandaloneServerConfigured ,
247
248
"Could not find standalone managed server from configured cluster" );
248
249
logger .info ("Found standalone managed server configuration" );
@@ -311,14 +312,14 @@ void testAdminServerRestart() {
311
312
312
313
logger .info ("Check managed server pods are not affected" );
313
314
Callable <Boolean > isDynRestarted =
314
- assertDoesNotThrow (() -> isPodRestarted (dynamicServerPodName ,
315
- domainNamespace , dynTs ));
315
+ assertDoesNotThrow (() -> isPodRestarted (dynamicServerPodName ,
316
+ domainNamespace , dynTs ));
316
317
assertFalse (assertDoesNotThrow (isDynRestarted ::call ),
317
318
"Dynamic managed server pod must not be restated" );
318
319
319
320
Callable <Boolean > isCfgRestarted =
320
- assertDoesNotThrow (() -> isPodRestarted (configServerPodName ,
321
- domainNamespace , cfgTs ));
321
+ assertDoesNotThrow (() -> isPodRestarted (configServerPodName ,
322
+ domainNamespace , cfgTs ));
322
323
assertFalse (assertDoesNotThrow (isCfgRestarted ::call ),
323
324
"Configured managed server pod must not be restated" );
324
325
@@ -327,7 +328,7 @@ void testAdminServerRestart() {
327
328
logger .info ("Check admin service/pod {0} is created in namespace {1}" ,
328
329
adminServerPodName , domainNamespace );
329
330
checkPodReadyAndServiceExists (adminServerPodName ,
330
- domainUid , domainNamespace );
331
+ domainUid , domainNamespace );
331
332
}
332
333
333
334
/**
@@ -350,7 +351,7 @@ void testConfigClusterRestart() {
350
351
OffsetDateTime dynTs = getPodCreationTime (domainNamespace , dynamicServerPodName );
351
352
352
353
checkPodReadyAndServiceExists (configServerPodName ,
353
- domainUid , domainNamespace );
354
+ domainUid , domainNamespace );
354
355
// startCluster.sh does not take any action on a running cluster
355
356
String result = executeLifecycleScript (START_CLUSTER_SCRIPT , CLUSTER_LIFECYCLE , CLUSTER_2 );
356
357
assertTrue (result .contains ("No changes needed" ), "startCluster.sh shouldn't make changes" );
@@ -366,8 +367,8 @@ void testConfigClusterRestart() {
366
367
logger .info ("Check dynamic managed server pods are not affected" );
367
368
368
369
Callable <Boolean > isDynRestarted =
369
- assertDoesNotThrow (() -> isPodRestarted (dynamicServerPodName ,
370
- domainNamespace , dynTs ));
370
+ assertDoesNotThrow (() -> isPodRestarted (dynamicServerPodName ,
371
+ domainNamespace , dynTs ));
371
372
assertFalse (assertDoesNotThrow (isDynRestarted ::call ),
372
373
"Dynamic managed server pod must not be restated" );
373
374
@@ -378,7 +379,7 @@ void testConfigClusterRestart() {
378
379
logger .info ("Start configured cluster using the script" );
379
380
executeLifecycleScript (START_CLUSTER_SCRIPT , CLUSTER_LIFECYCLE , CLUSTER_2 );
380
381
checkPodReadyAndServiceExists (configServerPodName ,
381
- domainUid , domainNamespace );
382
+ domainUid , domainNamespace );
382
383
logger .info ("Configured cluster restart success" );
383
384
}
384
385
@@ -418,16 +419,16 @@ void testDynamicClusterRestart() {
418
419
419
420
// check managed server from other cluster are not affected
420
421
Callable <Boolean > isCfgRestarted =
421
- assertDoesNotThrow (() -> isPodRestarted (configServerPodName ,
422
- domainNamespace , cfgTs ));
422
+ assertDoesNotThrow (() -> isPodRestarted (configServerPodName ,
423
+ domainNamespace , cfgTs ));
423
424
assertFalse (assertDoesNotThrow (isCfgRestarted ::call ),
424
425
"Configured managed server pod must not be restated" );
425
426
426
427
// Verify clustered server are started after startCluster script execution
427
428
logger .info ("Start dynamic cluster using the script" );
428
429
executeLifecycleScript (START_CLUSTER_SCRIPT , CLUSTER_LIFECYCLE , CLUSTER_1 );
429
430
checkPodReadyAndServiceExists (dynamicServerPodName ,
430
- domainUid , domainNamespace );
431
+ domainUid , domainNamespace );
431
432
logger .info ("Dynamic cluster restart success" );
432
433
}
433
434
@@ -487,8 +488,8 @@ void testDomainRestart() {
487
488
logger .info ("Domain is patched to start only administrative server" );
488
489
489
490
checkPodReadyAndServiceExists (adminServerPodName ,
490
- domainUid , domainNamespace );
491
- // make sure all other managed server pods are not provisioned
491
+ domainUid , domainNamespace );
492
+ // make sure all other managed server pods are not provisioned
492
493
for (int i = 1 ; i <= replicaCount ; i ++) {
493
494
checkPodDeleted (managedServerPrefix + i , domainUid , domainNamespace );
494
495
}
@@ -511,7 +512,7 @@ void testDomainRestart() {
511
512
// check dynamic managed server pods are ready
512
513
for (int i = 1 ; i <= replicaCount ; i ++) {
513
514
checkPodReadyAndServiceExists (managedServerPrefix + i ,
514
- domainUid , domainNamespace );
515
+ domainUid , domainNamespace );
515
516
}
516
517
checkPodReadyAndServiceExists (configServerPodName ,
517
518
domainUid , domainNamespace );
@@ -547,7 +548,7 @@ void testConfigClusterStartServerAlways() {
547
548
"Failed to patch config managedServers's serverStartPolicy to ALWAYS" );
548
549
logger .info ("Configured managed server is patched to set the serverStartPolicy to ALWAYS" );
549
550
checkPodReadyAndServiceExists (serverPodName ,
550
- domainUid , domainNamespace );
551
+ domainUid , domainNamespace );
551
552
logger .info ("Configured cluster managed server is RUNNING" );
552
553
553
554
// Stop the server by changing the serverStartPolicy to IF_NEEDED
@@ -588,7 +589,7 @@ void testDynamicClusterStartServerAlways() {
588
589
"Failed to patch dynamic managedServers's serverStartPolicy to ALWAYS" );
589
590
logger .info ("Dynamic managed server is patched to set the serverStartPolicy to ALWAYS" );
590
591
checkPodReadyAndServiceExists (serverPodName ,
591
- domainUid , domainNamespace );
592
+ domainUid , domainNamespace );
592
593
logger .info ("Second managed server in dynamic cluster is RUNNING" );
593
594
594
595
// Stop the server by changing the serverStartPolicy to IF_NEEDED
@@ -790,22 +791,22 @@ void testStandaloneManagedRestart() {
790
791
logger .info ("Configured managed server is RUNNING" );
791
792
// startServer.sh does not take any action on a running server
792
793
String result = executeLifecycleScript (START_SERVER_SCRIPT ,
793
- SERVER_LIFECYCLE , "standalone-managed" ,
794
- keepReplicaCountConstantParameter );
794
+ SERVER_LIFECYCLE , "standalone-managed" ,
795
+ keepReplicaCountConstantParameter );
795
796
assertTrue (result .contains ("No changes needed" ), "startServer.sh shouldn't make changes" );
796
797
797
798
// shutdown standalone-managed using the script stopServer.sh
798
799
executeLifecycleScript (STOP_SERVER_SCRIPT , SERVER_LIFECYCLE ,
799
- "standalone-managed" , keepReplicaCountConstantParameter );
800
+ "standalone-managed" , keepReplicaCountConstantParameter );
800
801
logger .info ("Script executed to shutdown standalone managed server" );
801
802
802
803
checkPodDeleted (serverPodName , domainUid , domainNamespace );
803
804
logger .info ("Standalone managed server shutdown success" );
804
805
805
806
// stopServer.sh does not take any action on a stopped server
806
807
result = executeLifecycleScript (STOP_SERVER_SCRIPT ,
807
- SERVER_LIFECYCLE , "standalone-managed" ,
808
- keepReplicaCountConstantParameter );
808
+ SERVER_LIFECYCLE , "standalone-managed" ,
809
+ keepReplicaCountConstantParameter );
809
810
assertTrue (result .contains ("No changes needed" ), "stopServer.sh shouldn't make changes" );
810
811
811
812
executeLifecycleScript (START_SERVER_SCRIPT , SERVER_LIFECYCLE ,
@@ -994,8 +995,8 @@ void testDynamicServerLifeCycleWithoutAdmin() {
994
995
995
996
// verify the script can stop the server by reducing replica count
996
997
assertDoesNotThrow (() ->
997
- executeLifecycleScript (STOP_SERVER_SCRIPT ,
998
- SERVER_LIFECYCLE , serverName , "" , true ),
998
+ executeLifecycleScript (STOP_SERVER_SCRIPT ,
999
+ SERVER_LIFECYCLE , serverName , "" , true ),
999
1000
String .format ("Failed to run %s" , STOP_SERVER_SCRIPT ));
1000
1001
checkPodDeleted (serverPodName , domainUid , domainNamespace );
1001
1002
logger .info ("Shutdown [" + serverName + "] without admin server success" );
@@ -1077,8 +1078,8 @@ void testConfiguredServerLifeCycleWithoutAdmin() {
1077
1078
1078
1079
// verify the script can stop the server by reducing replica count
1079
1080
assertDoesNotThrow (() ->
1080
- executeLifecycleScript (STOP_SERVER_SCRIPT ,
1081
- SERVER_LIFECYCLE , serverName , "" , true ),
1081
+ executeLifecycleScript (STOP_SERVER_SCRIPT ,
1082
+ SERVER_LIFECYCLE , serverName , "" , true ),
1082
1083
String .format ("Failed to run %s" , STOP_SERVER_SCRIPT ));
1083
1084
checkPodDeleted (serverPodName , domainUid , domainNamespace );
1084
1085
logger .info ("Shutdown [" + serverName + "] without admin server success" );
@@ -1432,12 +1433,9 @@ private void scalingClusters(String clusterName, String serverPodName, int repli
1432
1433
domainUid , domainNamespace , replicaNum )));
1433
1434
1434
1435
// use clusterStatus.sh to verify scaling results
1435
- result = assertDoesNotThrow (() ->
1436
- executeLifecycleScript (STATUS_CLUSTER_SCRIPT , CLUSTER_LIFECYCLE , clusterName ),
1437
- String .format ("Failed to run %s" , STATUS_CLUSTER_SCRIPT ));
1436
+ testUntil (checkClusterStatus (clusterName , regex ), logger ,
1437
+ "Checking for cluster status for cluster: " + clusterName );
1438
1438
1439
- assertTrue (verifyExecuteResult (result , regex ), "The script should scale the given cluster: " + clusterName
1440
- + ", the result is -> " + result + " . It doesn't match the expected pattern -> " + regex );
1441
1439
logger .info ("The cluster {0} scaled successfully." , clusterName );
1442
1440
}
1443
1441
@@ -1646,4 +1644,13 @@ private boolean verifyExecuteResult(String result, String regex) {
1646
1644
1647
1645
return matcher .find ();
1648
1646
}
1647
+
1648
+ private Callable <Boolean > checkClusterStatus (String clusterName , String regex ) {
1649
+ // use clusterStatus.sh to verify scaling results
1650
+ String result = assertDoesNotThrow (() ->
1651
+ executeLifecycleScript (STATUS_CLUSTER_SCRIPT , CLUSTER_LIFECYCLE , clusterName ),
1652
+ String .format ("Failed to run %s" , STATUS_CLUSTER_SCRIPT ));
1653
+ logger .info ("Status of cluster {0} retured {1}, expected {2}" , clusterName , result , regex );
1654
+ return () -> verifyExecuteResult (result , regex );
1655
+ }
1649
1656
}
0 commit comments