Skip to content

Commit 527d923

Browse files
hzhao-githubhuizhaohuizhao
authored
Added tests to use script scaleCluster.sh/ClusterStatus.sh (#2350)
* Added tests to use script scaleCluster.sh/ClusterStatus.sh * Added more desriptions Co-authored-by: huizhao <huizhao@huizhao-1.subnet2ad1phx.devweblogicphx.oraclevcn.com> Co-authored-by: huizhao <huizhao@phx3187a26.subnet4ad3phx.devweblogicphx.oraclevcn.com>
1 parent 7daac17 commit 527d923

File tree

1 file changed

+133
-1
lines changed

1 file changed

+133
-1
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItServerStartPolicy.java

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import static oracle.weblogic.kubernetes.utils.CommonPatchTestUtils.patchServerStartPolicy;
6565
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkClusterReplicaCountMatches;
6666
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodDeleted;
67+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodDoesNotExist;
6768
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodInitializing;
6869
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
6970
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createConfigMapAndVerify;
@@ -89,7 +90,6 @@
8990
* managed server. The replica count is set to 1 and serverStartPolicy is set
9091
* to IF_NEEDED at managed server level.
9192
*/
92-
9393
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
9494
@DisplayName("ServerStartPolicy attribute in different levels in a MII domain")
9595
@IntegrationTest
@@ -104,6 +104,8 @@ class ItServerStartPolicy {
104104
public static final String START_CLUSTER_SCRIPT = "startCluster.sh";
105105
public static final String STOP_DOMAIN_SCRIPT = "stopDomain.sh";
106106
public static final String START_DOMAIN_SCRIPT = "startDomain.sh";
107+
public static final String SCALE_CLUSTER_SCRIPT = "scaleCluster.sh";
108+
public static final String STATUS_CLUSTER_SCRIPT = "clusterStatus.sh";
107109
public static final String managedServerNamePrefix = "managed-server";
108110
public static final String CLUSTER_1 = "cluster-1";
109111
public static final String CLUSTER_2 = "cluster-2";
@@ -1130,6 +1132,131 @@ public void testRestartingMSWithExplicitServerStartStateWhileVaryingReplicaCount
11301132
logger.info("managed server " + serverName + " restarted successfully.");
11311133
}
11321134

1135+
/**
1136+
* Scale the configured cluster using the sample script scaleCluster.sh script
1137+
* Verify that server(s) in the configured cluster are scaled up and in RUNNING state.
1138+
* Verify that server(s) in the dynamic cluster are not affected.
1139+
* Restore the env using the sample script stopServer.sh.
1140+
*/
1141+
@Order(19)
1142+
@Test
1143+
@DisplayName("Scale the configured cluster with scaleCluster.sh script")
1144+
public void testConfigClusterScale() {
1145+
int newReplicaCount = 2;
1146+
String configServerName = "config-cluster-server" + newReplicaCount;
1147+
String configServerPodName = domainUid + "-" + configServerName;
1148+
String dynamicServerPodName = domainUid + "-managed-server" + newReplicaCount;
1149+
1150+
// use clusterStatus.sh to make sure the server-to-be-test doesn't exist
1151+
// String regex matches below
1152+
// cluster min max goal current ready
1153+
// clusterName 1 5 1 1 1
1154+
String regex = ".*" + CLUSTER_1 + "(\\s+)1(\\s+)5(\\s+)1(\\s+)1(\\s+)1";
1155+
scalingClusters(CLUSTER_1, dynamicServerPodName, replicaCount, regex, false);
1156+
// String regex matches below
1157+
// cluster min max goal current ready
1158+
// clusterName 0 2 1 1 1
1159+
regex = ".*" + CLUSTER_2 + "(\\s+)0(\\s+)2(\\s+)1(\\s+)1(\\s+)1";
1160+
scalingClusters(CLUSTER_2, configServerPodName, replicaCount, regex, false);
1161+
1162+
// use scaleCluster.sh to scale a dynamic cluster and
1163+
// use clusterStatus.sh to verify scaling results
1164+
// String regex matches below
1165+
// cluster min max goal current ready
1166+
// clusterName 0 2 2 2 2
1167+
regex = ".*" + CLUSTER_2 + "(\\s+)0(\\s+)2(\\s+)2(\\s+)2(\\s+)2";
1168+
scalingClusters(CLUSTER_2, configServerPodName, newReplicaCount, regex, true);
1169+
1170+
// check managed server from other cluster are not affected
1171+
logger.info("Check dynamic managed server pods are not affected");
1172+
assertDoesNotThrow(() -> assertTrue(checkClusterReplicaCountMatches(CLUSTER_1,
1173+
domainUid, domainNamespace, replicaCount)));
1174+
checkPodDoesNotExist(dynamicServerPodName, domainUid, domainNamespace);
1175+
1176+
// use clusterStatus.sh to restore test env
1177+
// String regex matches below
1178+
// cluster min max goal current ready
1179+
// clusterName 0 2 1 1 1
1180+
regex = ".*" + CLUSTER_2 + "(\\s+)0(\\s+)2(\\s+)1(\\s+)1(\\s+)1";
1181+
scalingClusters(CLUSTER_2, configServerPodName, replicaCount, regex, false);
1182+
}
1183+
1184+
/**
1185+
* Scale the dynamic cluster using the sample script scaleCluster.sh script
1186+
* Verify that server(s) in the dynamic cluster are scaled up and in RUNNING state.
1187+
* Verify that server(s) in the configured cluster are not affected.
1188+
* Restore the env using the sample script stopServer.sh.
1189+
*/
1190+
@Order(20)
1191+
@Test
1192+
@DisplayName("Scale the dynamic cluster with scaleCluster.sh script")
1193+
public void testDynamicClusterScale() {
1194+
int newReplicaCount = 2;
1195+
String dynamicServerName = "managed-server" + newReplicaCount;
1196+
String dynamicServerPodName = domainUid + "-" + dynamicServerName;
1197+
String configServerPodName = domainUid + "-config-cluster-server" + newReplicaCount;
1198+
1199+
// use clusterStatus.sh to make sure the server-to-be-test doesn't exist
1200+
// String regex matches below
1201+
// cluster min max goal current ready
1202+
// clusterName 1 5 1 1 1
1203+
String regex = ".*" + CLUSTER_1 + "(\\s+)1(\\s+)5(\\s+)1(\\s+)1(\\s+)1";
1204+
scalingClusters(CLUSTER_1, dynamicServerPodName, replicaCount, regex, false);
1205+
// String regex matches below
1206+
// cluster min max goal current ready
1207+
// clusterName 0 2 1 1 1
1208+
regex = ".*" + CLUSTER_2 + "(\\s+)0(\\s+)2(\\s+)1(\\s+)1(\\s+)1";
1209+
scalingClusters(CLUSTER_2, configServerPodName, replicaCount, regex, false);
1210+
1211+
// use scaleCluster.sh to scale a dynamic cluster and
1212+
// use clusterStatus.sh to verify scaling results
1213+
// String regex matches below
1214+
// cluster min max goal current ready
1215+
// clusterName 1 5 2 2 2
1216+
regex = ".*" + CLUSTER_1 + "(\\s+)1(\\s+)5(\\s+)2(\\s+)2(\\s+)2";
1217+
scalingClusters(CLUSTER_1, dynamicServerPodName, newReplicaCount, regex, true);
1218+
1219+
// check managed server from other cluster are not affected
1220+
logger.info("Check configured managed server pods are not affected");
1221+
assertDoesNotThrow(() -> assertTrue(checkClusterReplicaCountMatches(CLUSTER_2,
1222+
domainUid, domainNamespace, replicaCount)));
1223+
checkPodDoesNotExist(configServerPodName, domainUid, domainNamespace);
1224+
1225+
// use clusterStatus.sh to restore test env
1226+
// String regex matches below
1227+
// cluster min max goal current ready
1228+
// clusterName 1 5 1 1 1
1229+
regex = ".*" + CLUSTER_1 + "(\\s+)1(\\s+)5(\\s+)1(\\s+)1(\\s+)1";
1230+
scalingClusters(CLUSTER_1, dynamicServerPodName, replicaCount, regex, false);
1231+
}
1232+
1233+
private void scalingClusters(String clusterName, String serverPodName, int replicaNum,
1234+
String regex, boolean checkPodExist) {
1235+
// use scaleCluster.sh to scale a given cluster
1236+
logger.info("Scale cluster {0} using the script scaleCluster.sh", clusterName);
1237+
String result = assertDoesNotThrow(() ->
1238+
executeLifecycleScript(SCALE_CLUSTER_SCRIPT, CLUSTER_LIFECYCLE, clusterName, " -r " + replicaNum, false),
1239+
String.format("Failed to run %s", SCALE_CLUSTER_SCRIPT));
1240+
1241+
if (checkPodExist) {
1242+
checkPodReadyAndServiceExists(serverPodName, domainUid, domainNamespace);
1243+
} else {
1244+
checkPodDoesNotExist(serverPodName, domainUid, domainNamespace);
1245+
}
1246+
1247+
// verify that scaleCluster.sh does scale to a required replica number
1248+
assertDoesNotThrow(() -> assertTrue(checkClusterReplicaCountMatches(clusterName,
1249+
domainUid, domainNamespace, replicaNum)));
1250+
1251+
// use clusterStatus.sh to verify scaling results
1252+
result = assertDoesNotThrow(() ->
1253+
executeLifecycleScript(STATUS_CLUSTER_SCRIPT, CLUSTER_LIFECYCLE, clusterName),
1254+
String.format("Failed to run %s", STATUS_CLUSTER_SCRIPT));
1255+
1256+
assertTrue(verifyExecuteResult(result, regex), "The script should scale the given cluster: " + clusterName);
1257+
logger.info("The cluster {0} scaled successfully.", clusterName);
1258+
}
1259+
11331260
private static void createDomainSecret(String secretName, String username, String password, String domNamespace) {
11341261
Map<String, String> secretMap = new HashMap<>();
11351262
secretMap.put("username", username);
@@ -1284,6 +1411,7 @@ private String executeLifecycleScript(String script,
12841411
boolean checkResult,
12851412
String... args) {
12861413
String domainName = (args.length == 0) ? domainUid : args[0];
1414+
12871415
CommandParams params;
12881416
String commonParameters = " -d " + domainName + " -n " + domainNamespace;
12891417
params = new CommandParams().defaults();
@@ -1292,6 +1420,10 @@ private String executeLifecycleScript(String script,
12921420
+ Paths.get(domainLifecycleSamplePath.toString(), "/" + script).toString()
12931421
+ commonParameters + " -s " + entityName + " " + extraParams);
12941422
} else if (scriptType.equals(CLUSTER_LIFECYCLE)) {
1423+
if (extraParams.contains("-r")) {
1424+
commonParameters += " " + extraParams;
1425+
}
1426+
12951427
params.command("sh "
12961428
+ Paths.get(domainLifecycleSamplePath.toString(), "/" + script).toString()
12971429
+ commonParameters + " -c " + entityName);

0 commit comments

Comments
 (0)