Skip to content

Commit 1e21f4c

Browse files
committed
more changes for Coherence rolling restart test
1 parent a61d2fa commit 1e21f4c

File tree

7 files changed

+379
-80
lines changed

7 files changed

+379
-80
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/ITCoherenceTests.java

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
package oracle.kubernetes.operator;
66

7-
import java.nio.file.Files;
8-
import java.nio.file.Paths;
97
import java.util.Map;
108
import oracle.kubernetes.operator.utils.CoherenceUtils;
119
import oracle.kubernetes.operator.utils.Domain;
12-
import oracle.kubernetes.operator.utils.ExecResult;
1310
import oracle.kubernetes.operator.utils.K8sTestUtils;
1411
import oracle.kubernetes.operator.utils.Operator;
1512
import oracle.kubernetes.operator.utils.TestUtils;
@@ -49,6 +46,12 @@ public static void staticPrepare() throws Exception {
4946
if (!QUICKTEST) {
5047
initialize(APP_PROPS_FILE);
5148

49+
// The default cmd loop sleep is too long and we could miss states like terminating. Change the
50+
// sleep and iterations
51+
//
52+
setWaitTimePod(2);
53+
setMaxIterationsPod(125);
54+
5255
if (operator1 == null) {
5356
operator1 = TestUtils.createOperator(OPERATOR1_YAML);
5457
}
@@ -76,34 +79,30 @@ public void testRollingRestart() throws Exception {
7679
domain = createDomain();
7780
Assert.assertNotNull(domain);
7881

79-
// public static void exposePod(String podName, String domainNS, String serviceName, int port,
80-
// int targetPort) throws Exception {
82+
// String nodePortName = "coh-nodeport";
83+
// String podName = "dd";
84+
// int port = 9000;
85+
// TestUtils.exposePod(podName, domain.getDomainNS(), nodePortName, port, port);
86+
//
87+
utils.loadCache();
8188

89+
// Do the rolling restart
90+
testServerPodsRestartByChangingEnvProperty();
8291

83-
// String nodePortName = "coh-nodeport";
84-
// String podName = "dd";
85-
// int port = 9000;
86-
// TestUtils.exposePod(podName, domain.getDomainNS(), nodePortName, port, port);
87-
//
88-
utils.loadCache();
8992
utils.validateCache();
9093

9194
destroyDomain();
9295
}
9396

94-
9597
/**
9698
* Modify the domain scope env property on the domain resource using kubectl apply -f domain.yaml
9799
* Verify that all the server pods in the domain got re-started. The property tested is: env:
98100
* "-Dweblogic.StdoutDebugEnabled=false"--> "-Dweblogic.StdoutDebugEnabled=true"
99101
*
100102
* @throws Exception
101103
*/
102-
@Ignore
103-
@Test
104104
public void testServerPodsRestartByChangingEnvProperty() throws Exception {
105105

106-
107106
Assume.assumeFalse(QUICKTEST);
108107
String testMethodName = new Object() {}.getClass().getEnclosingMethod().getName();
109108
logTestBegin(testMethodName);
@@ -112,56 +111,34 @@ public void testServerPodsRestartByChangingEnvProperty() throws Exception {
112111
"About to verifyDomainServerPodRestart for Domain: "
113112
+ domain.getDomainUid()
114113
+ " env property: StdoutDebugEnabled=false to StdoutDebugEnabled=true");
114+
115115
domain.verifyDomainServerPodRestart(
116116
"\"-Dweblogic.StdoutDebugEnabled=false\"", "\"-Dweblogic.StdoutDebugEnabled=true\"");
117117

118118
logger.info("SUCCESS - " + testMethodName);
119119
}
120120

121-
private static Domain createDomain() throws Exception {
122-
123-
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAININIMAGE_WLST_YAML);
124-
domainMap.put("namespace","test1");
125-
domainMap.put("domainUID", "coh");
126-
domain = TestUtils.createDomain(domainMap);
127-
domain.verifyDomainCreated();
128-
return domain;
129-
}
130-
131121
private static void destroyDomain() throws Exception {
132122
if (domain != null) {
133123
domain.destroy();
134124
}
135125
}
136126

137-
/**
138-
* Utility method to check if a pod is in Terminating or Running status
139-
*
140-
* @param podName - String name of the pod to check the status for
141-
* @param podStatusExpected - String the expected status of Terminating || RUnning
142-
* @throws InterruptedException when thread is interrupted
143-
*/
144-
private void verifyPodStatus(String podName, String podStatusExpected)
145-
throws InterruptedException {
146-
K8sTestUtils testUtil = new K8sTestUtils();
147-
String domain1LabelSelector = String.format("weblogic.domainUID in (%s)", domainUid);
148-
String namespace = domain.getDomainNS();
149-
boolean gotExpected = false;
150-
for (int i = 0; i < BaseTest.getMaxIterationsPod(); i++) {
151-
if (podStatusExpected.equals("Terminating")) {
152-
if (testUtil.isPodTerminating(namespace, domain1LabelSelector, podName)) {
153-
gotExpected = true;
154-
break;
155-
}
156-
} else if (podStatusExpected.equals("Running")) {
157-
if (testUtil.isPodRunning(namespace, domain1LabelSelector, podName)) {
158-
gotExpected = true;
159-
break;
160-
}
161-
}
127+
private Domain createDomain() throws Exception {
162128

163-
Thread.sleep(BaseTest.getWaitTimePod() * 1000);
164-
}
165-
Assert.assertTrue("Didn't get the expected pod status", gotExpected);
129+
// System.getenv().put("CUSTOM_WDT_ARCHIVE", "/Users/pmackin/archive-proxy.zip");
130+
131+
// create domain
132+
Domain domain = null;
133+
Map<String, Object> domainMap = TestUtils.loadYaml(DOMAININIMAGE_WDT_YAML);
134+
domainMap.put("namespace", "test1");
135+
domainMap.put("domainUID", "coh");
136+
domainMap.put(
137+
"customWdtTemplate",
138+
BaseTest.getProjectRoot()
139+
+ "/integration-tests/src/test/resources/wdt/coh-wdt-config.yaml");
140+
domain = TestUtils.createDomain(domainMap);
141+
domain.verifyDomainCreated();
142+
return domain;
166143
}
167-
}
144+
}

integration-tests/src/test/java/oracle/kubernetes/operator/utils/CoherenceUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class CoherenceUtils {
3232
private static final String PREFIX = "Thread-";
3333
private static final int VALUE_SIZE = 1024;
3434
private static final int NUM_ITEMS =
35-
200 * 1000; // Total number of items, regardless of thread count
35+
100 * 1000; // Total number of items, regardless of thread count
3636
private static final int THREAD_COUNT = 1;
3737
private static final int MAX_BATCH_SIZE = 1000;
3838

@@ -126,7 +126,7 @@ public void loadCache() {
126126
Instant finishInstant = Instant.now();
127127
Duration duration = Duration.between(startInstant, finishInstant);
128128

129-
System.out.println("Load Test elaspsed Time = " + duration.getSeconds() + " seconds");
129+
System.out.println("Load Test SUCCESS - elapsed Time = " + duration.getSeconds() + " seconds");
130130
}
131131

132132
public void validateCache() {
@@ -156,7 +156,7 @@ public void validateCache() {
156156
Instant finishInstant = Instant.now();
157157
Duration duration = Duration.between(startInstant, finishInstant);
158158

159-
System.out.println("Validate Test elaspsed Time = " + duration.getSeconds() + " seconds");
159+
System.out.println("Validate Test SUCCESS - elapsed Time = " + duration.getSeconds() + " seconds");
160160
}
161161

162162
/**

integration-tests/src/test/java/oracle/kubernetes/operator/utils/Domain.java

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
import java.nio.file.StandardOpenOption;
1818
import java.util.Arrays;
1919
import java.util.HashMap;
20+
import java.util.HashSet;
2021
import java.util.Hashtable;
22+
import java.util.Iterator;
2123
import java.util.List;
2224
import java.util.Map;
2325
import java.util.Objects;
26+
import java.util.Set;
2427
import java.util.StringTokenizer;
2528
import java.util.logging.Level;
2629
import java.util.logging.Logger;
@@ -1016,6 +1019,7 @@ public void verifyDomainServerPodRestart(String oldPropertyString, String newPro
10161019
// verify the servers in the domain are being restarted in a sequence
10171020
verifyAdminServerRestarted();
10181021
verifyManagedServersRestarted();
1022+
10191023
// make domain.yaml include the new changed property
10201024
TestUtils.copyFile(
10211025
BaseTest.getUserProjectsDir() + "/weblogic-domains/" + domainUid + "/domain_new.yaml",
@@ -1118,8 +1122,9 @@ public void verifyAdminServerRestarted() throws Exception {
11181122
logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Terminating");
11191123
TestUtils.checkPodTerminating(domainUid + "-" + adminServerName, domainNS);
11201124

1121-
logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Running");
1125+
logger.info("Checking if admin pod(" + domainUid + "-" + adminServerName + ") is Ready");
11221126
TestUtils.checkPodCreated(domainUid + "-" + adminServerName, domainNS);
1127+
TestUtils.checkPodReady(domainUid + "-" + adminServerName, domainNS);
11231128
}
11241129

11251130
/**
@@ -1129,25 +1134,36 @@ public void verifyAdminServerRestarted() throws Exception {
11291134
*/
11301135
public void verifyManagedServersRestarted() throws Exception {
11311136
if (!serverStartPolicy.equals("ADMIN_ONLY")) {
1132-
// check managed server pods
1137+
1138+
// Note: Managed Servers can be stopped in any order. Build the set of server names
1139+
// then loop until all servers have been recycled. When we find one that is terminating,
1140+
// wait until it is running then remove it from the set.
1141+
Set<String> podNameSet = new HashSet<>();
11331142
for (int i = 1; i <= initialManagedServerReplicas; i++) {
1134-
logger.info(
1135-
"Checking if managed pod("
1136-
+ domainUid
1137-
+ "-"
1138-
+ managedServerNameBase
1139-
+ i
1140-
+ ") is Terminating");
1141-
TestUtils.checkPodTerminating(domainUid + "-" + managedServerNameBase + i, domainNS);
1143+
podNameSet.add(managedServerNameBase + i);
1144+
}
11421145

1143-
logger.info(
1144-
"Checking if managed pod("
1145-
+ domainUid
1146-
+ "-"
1147-
+ managedServerNameBase
1148-
+ i
1149-
+ ") is Running");
1150-
TestUtils.checkPodCreated(domainUid + "-" + managedServerNameBase + i, domainNS);
1146+
// Loop until all the servers have recycled
1147+
//
1148+
while (podNameSet.size() > 0) {
1149+
Iterator<String> iter = podNameSet.iterator();
1150+
while (iter.hasNext()) {
1151+
String podName = iter.next();
1152+
if (TestUtils.checkPodTerminatingNoWait(domainUid + "-" + podName, domainNS)) {
1153+
// Server is terminating, wait until server running then remove it from the list
1154+
logger.info("Managed server pod " + podName + " is terminating");
1155+
TestUtils.checkPodCreated(domainUid + "-" + adminServerName, domainNS);
1156+
TestUtils.checkPodReady(domainUid + "-" + podName, domainNS);
1157+
logger.info("Managed server pod " + podName + " has been recycled");
1158+
iter.remove();
1159+
}
1160+
}
1161+
// We iterated through all the servers and if there are some remaining then
1162+
// Sleep and loop through the remaining ones again. Keep the sleep short so we don't miss the terminating status.
1163+
if (podNameSet.size() > 0) {
1164+
logger.info("Waiting for any managed server pod to be terminating...");
1165+
Thread.sleep(1000);
1166+
}
11511167
}
11521168
}
11531169
}

integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,27 @@ public static void checkPodCreated(String podName, String domainNS) throws Excep
8282
StringBuffer cmd = new StringBuffer();
8383
cmd.append("kubectl get pod ").append(podName).append(" -n ").append(domainNS);
8484

85-
// check for admin pod
85+
// check for pod to be running
8686
checkCmdInLoop(cmd.toString(), "Running", podName);
8787
}
8888

89+
/**
90+
* Checks that pod is ready and running.
91+
*
92+
* @param podName - pod name
93+
* @param domainNS - domain namespace name
94+
*/
95+
public static void checkPodReadyAndRunning(String podName, String domainNS) throws Exception {
96+
97+
StringBuffer cmd = new StringBuffer();
98+
cmd.append("kubectl get pod ").append(podName).append(" -n ").append(domainNS);
99+
100+
// check for pod to be running
101+
checkCmdInLoop(cmd.toString(), "Running", podName);
102+
checkCmdInLoop(cmd.toString(), "1/1", podName);
103+
}
104+
105+
89106
/**
90107
* Checks that pod is initializing.
91108
*
@@ -117,6 +134,24 @@ public static void checkPodTerminating(String podName, String domainNS) throws E
117134
checkCmdInLoop(cmd.toString(), "Terminating", podName);
118135
}
119136

137+
/**
138+
* check pod is in Terminating state without waiting
139+
*
140+
* @param podName - pod name
141+
* @param domainNS - domain namespace name
142+
*
143+
* @return true if pod terminating else false
144+
* @throws Exception exception
145+
*/
146+
public static boolean checkPodTerminatingNoWait(String podName, String domainNS) throws Exception {
147+
148+
StringBuffer cmd = new StringBuffer();
149+
cmd.append("kubectl get pod ").append(podName).append(" -n ").append(domainNS);
150+
151+
// check for admin pod
152+
return checkPodMatch(cmd.toString(), "Terminating", podName);
153+
}
154+
120155
/**
121156
* Checks that service is created.
122157
*
@@ -1302,12 +1337,12 @@ public static void checkCmdInLoop(String cmd, String matchStr, String k8sObjName
13021337
// check for last iteration
13031338
if (i == (BaseTest.getMaxIterationsPod() - 1)) {
13041339
throw new RuntimeException(
1305-
"FAILURE: pod " + k8sObjName + " is not running/ready, exiting!");
1340+
"FAILURE: Timeout - pod " + k8sObjName + " output does not contain '" + matchStr + "'");
13061341
}
13071342
logger.info(
13081343
"Pod "
13091344
+ k8sObjName
1310-
+ " is not Running/Ready Ite ["
1345+
+ " output does not contain '" + matchStr + "' Iteration ["
13111346
+ i
13121347
+ "/"
13131348
+ BaseTest.getMaxIterationsPod()
@@ -1318,12 +1353,34 @@ public static void checkCmdInLoop(String cmd, String matchStr, String k8sObjName
13181353
Thread.sleep(BaseTest.getWaitTimePod() * 1000);
13191354
i++;
13201355
} else {
1321-
logger.info("Pod " + k8sObjName + " is Running");
1356+
logger.info("SUCCESS: Pod " + k8sObjName + " output contains '" + matchStr + "'");
13221357
break;
13231358
}
13241359
}
13251360
}
13261361

1362+
/**
1363+
* Check if the pod is in a specific status.
1364+
*
1365+
* @param cmd command to execute
1366+
* @param matchStr matching string
1367+
* @param k8sObjName pod Name
1368+
*
1369+
* @return true for match else false
1370+
* @throws Exception
1371+
*/
1372+
public static boolean checkPodMatch(String cmd, String matchStr, String k8sObjName)
1373+
throws Exception {
1374+
ExecResult result = ExecCommand.exec(cmd);
1375+
if (result.exitValue() != 0
1376+
|| (result.exitValue() == 0 && !result.stdout().contains(matchStr))) {
1377+
return false;
1378+
} else {
1379+
logger.info("Pod " + k8sObjName + " match found for " + matchStr);
1380+
return true;
1381+
}
1382+
}
1383+
13271384
private static void checkCmdInLoopForDelete(String cmd, String matchStr, String k8sObjName)
13281385
throws Exception {
13291386
int i = 0;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
domainUID: domaininimagewlst
5+
namespace: test1
6+
configuredManagedServerCount: 4
7+
initialManagedServerReplicas: 2
8+
exposeAdminT3Channel: true
9+
exposeAdminNodePort: true
10+
voyagerWebPort: 30322
11+
domainHomeImageBuildPath: ./docker-images/OracleWebLogic/samples/12213-domain-home-in-image
12+
domainHomeImageBase: "container-registry.oracle.com/middleware/weblogic:12.2.1.3"
13+
logHomeOnPV: true
14+
createDomainPyScript: integration-tests/src/test/resources/domain-home-in-image/create-domain-coherence-cluster.py

0 commit comments

Comments
 (0)