Skip to content

Commit 6ead511

Browse files
authored
Merge pull request #1124 from oracle/session-migration-tests
Bring back the source code to use serverStartPolicy to shutdown a ser…
2 parents eaa5ed3 + 6057564 commit 6ead511

File tree

2 files changed

+8
-70
lines changed

2 files changed

+8
-70
lines changed

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

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.regex.Pattern;
1111

1212
import oracle.kubernetes.operator.utils.Domain;
13-
import oracle.kubernetes.operator.utils.ExecCommand;
1413
import oracle.kubernetes.operator.utils.ExecResult;
1514
import oracle.kubernetes.operator.utils.Operator;
1615
import oracle.kubernetes.operator.utils.TestUtils;
@@ -31,11 +30,8 @@
3130
public class ItSessionMigration extends BaseTest {
3231
private static final String testAppName = "httpsessionreptestapp";
3332
private static final String scriptName = "buildDeployAppInPod.sh";
34-
3533
private static Map<String, String> httpAttrMap;
36-
3734
private static String httpHeaderFile;
38-
3935
private static Operator operator;
4036
private static Domain domain;
4137

@@ -71,7 +67,6 @@ public static void staticPrepare() throws Exception {
7167
}
7268

7369
httpHeaderFile = BaseTest.getResultDir() + "/headers";
74-
7570
httpAttrMap = new HashMap<String, String>();
7671
httpAttrMap.put("sessioncreatetime", "(.*)sessioncreatetime>(.*)</sessioncreatetime(.*)");
7772
httpAttrMap.put("sessionid", "(.*)sessionid>(.*)</sessionid(.*)");
@@ -134,7 +129,7 @@ public void testRepickPrimary() throws Exception {
134129
String sessCreateTime1 = getHttpResponseAttribute(result.stdout(), sessCreateTime);
135130

136131
// Stop primary server
137-
stopPrimaryServer(primaryServName1);
132+
domain.shutdownManagedServerUsingServerStartPolicy(primaryServName1);
138133

139134
// Send the second HTTP request using HTTP header/sessionID info save before
140135
result = getHttpResponse(testAppPath, " -b ");
@@ -152,6 +147,7 @@ public void testRepickPrimary() throws Exception {
152147
primaryServName1.trim().equals(primaryServName2.trim()));
153148

154149
// Restore test env
150+
domain.restartManagedServerUsingServerStartPolicy(primaryServName1);
155151
TestUtils.checkPodReady(domainUid + "-" + primaryServName1, domainNS);
156152

157153
logger.info(
@@ -190,7 +186,7 @@ public void testHttpSessionMigr() throws Exception {
190186
final String countattribute1 = getHttpResponseAttribute(result.stdout(), count);
191187

192188
// Stop primary server
193-
stopPrimaryServer(primaryServName1);
189+
domain.shutdownManagedServerUsingServerStartPolicy(primaryServName1);
194190

195191
// Send the second HTTP request using HTTP header/sessionID info save before
196192
result = getHttpResponse(webServiceGetUrl, " -b ");
@@ -210,6 +206,7 @@ public void testHttpSessionMigr() throws Exception {
210206
"HTTP session state is NOT migrated!", countattribute1.equals(countattribute2));
211207

212208
// Restore test env
209+
domain.restartManagedServerUsingServerStartPolicy(primaryServName1);
213210
TestUtils.checkPodReady(domainUid + "-" + primaryServName1, domainNS);
214211

215212
logger.info("SUCCESS - " + testMethodName + ". HTTP session state is migrated!");
@@ -227,59 +224,22 @@ private ExecResult getHttpResponse(String webServiceUrl, String headerOption) th
227224
String curlCmd = buildWebServiceUrl(webServiceUrl, headerOption + httpHeaderFile);
228225
logger.info("Send a HTTP request: " + curlCmd);
229226

230-
ExecResult result = ExecCommand.exec(curlCmd);
231-
232-
if (result.exitValue() != 0) {
233-
throw new Exception(
234-
"FAILURE: command "
235-
+ curlCmd
236-
+ " failed, returned "
237-
+ result.stderr()
238-
+ "\n "
239-
+ result.stdout());
240-
}
227+
ExecResult result = TestUtils.exec(curlCmd);
241228

242229
return result;
243230
}
244231

245-
/**
246-
* Stop the primary server.
247-
*
248-
* @param primaryServerName - weblogic primary server name
249-
* @throws Exception exception
250-
*/
251-
private void stopPrimaryServer(String primaryServerName) throws Exception {
252-
Map<String, Object> domainMap = domain.getDomainMap();
253-
String domainNS = domainMap.get("namespace").toString();
254-
String domainUid = domain.getDomainUid();
255-
256-
// stop primary server
257-
String msPodName = domainUid + "-" + primaryServerName;
258-
String cmd = "kubectl delete po/" + msPodName + " -n " + domainNS;
259-
logger.info("Stop managed server <" + msPodName + "> using command:\n" + cmd);
260-
261-
ExecResult result = ExecCommand.exec(cmd);
262-
if (result.exitValue() != 0) {
263-
throw new Exception("FAILURE: command " + cmd + " failed, returned " + result.stderr());
264-
}
265-
266-
logger.info(result.stdout());
267-
}
268-
269232
/**
270233
* Get the value of a HTTP attribute.
271234
*
272235
* @param httpResponseString - HTTP response
273-
* @param attribute - attrubute name to find in the HTTP response
236+
* @param attribute - attribute name to find in the HTTP response
274237
* @throws Exception exception
275238
*/
276239
private String getHttpResponseAttribute(String httpResponseString, String attribute)
277240
throws Exception {
278-
279241
String attrPatn = httpAttrMap.get(attribute);
280-
281242
Assume.assumeNotNull(attrPatn);
282-
283243
String httpAttribute = null;
284244

285245
Pattern pattern = Pattern.compile(attrPatn);
@@ -317,28 +277,4 @@ private String buildWebServiceUrl(String curlUrlPath, String paramToAppend) thro
317277

318278
return webServiceUrl.toString();
319279
}
320-
321-
/**
322-
* Execute a given curl command and verify the results.
323-
*
324-
* @param curlCmd - a curl command to execute
325-
* @throws Exception exception
326-
*/
327-
private ExecResult execCurlCmd(String curlCmd) throws Exception {
328-
logger.info("curl command to exec is:\n" + curlCmd);
329-
330-
ExecResult result = ExecCommand.exec(curlCmd);
331-
332-
if (result.exitValue() != 0) {
333-
throw new Exception(
334-
"FAILURE: command "
335-
+ curlCmd
336-
+ " failed, returned "
337-
+ result.stderr()
338-
+ "\n "
339-
+ result.stdout());
340-
}
341-
342-
return result;
343-
}
344280
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,7 @@ public int getLoadBalancerWebPort() {
17971797
/**
17981798
* Shut down a ms by setting serverStartPolicy to NEVER.
17991799
*
1800+
* @param msName - a managed server name to be stopped
18001801
* @throws Exception exception
18011802
*/
18021803
public void shutdownManagedServerUsingServerStartPolicy(String msName) throws Exception {
@@ -1813,6 +1814,7 @@ public void shutdownManagedServerUsingServerStartPolicy(String msName) throws Ex
18131814
/**
18141815
* Restart a ms by setting serverStartPolicy to IF_NEEDED.
18151816
*
1817+
* @param msName - a managed server name to be started
18161818
* @throws Exception exception
18171819
*/
18181820
public void restartManagedServerUsingServerStartPolicy(String msName) throws Exception {

0 commit comments

Comments
 (0)