Skip to content

Commit 6e76dd3

Browse files
committed
forward port OWLS-121241 to main
1 parent 9ff10f6 commit 6e76dd3

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

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

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99
import java.util.Map;
1010
import java.util.Optional;
11+
import java.util.concurrent.Callable;
1112
import java.util.regex.Matcher;
1213
import java.util.regex.Pattern;
1314

@@ -53,6 +54,7 @@
5354
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getNextFreePort;
5455
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getServiceExtIPAddrtOke;
5556
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
57+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withLongRetryPolicy;
5658
import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainAndVerify;
5759
import static oracle.weblogic.kubernetes.utils.ExecCommand.exec;
5860
import static oracle.weblogic.kubernetes.utils.ImageUtils.createMiiImageAndVerify;
@@ -182,7 +184,6 @@ void tearDown() {
182184
@DisplayName("Create a Traefik ingress resource and verify that two HTTP connections are sticky to the same server")
183185
@DisabledIfEnvironmentVariable(named = "OKD", matches = "true")
184186
void testSameSessionStickinessUsingTraefik() {
185-
186187
final String channelName = "web";
187188

188189
// create Traefik ingress resource
@@ -216,7 +217,11 @@ void testSameSessionStickinessUsingTraefik() {
216217
}
217218

218219
// verify that two HTTP connections are sticky to the same server
219-
sendHttpRequestsToTestSessionStickinessAndVerify(hostName, ingressServiceNodePort);
220+
testUntil(
221+
withLongRetryPolicy,
222+
isHttpRequestsResponded(hostName, ingressServiceNodePort),
223+
logger,
224+
"Waiting until Http Requests response");
220225
}
221226

222227
/**
@@ -230,23 +235,25 @@ void testSameSessionStickinessUsingTraefik() {
230235
@EnabledIfEnvironmentVariable(named = "OKD", matches = "true")
231236
void testSameSessionStickinessinOKD() {
232237
final String serviceName = domainUid + "-cluster-" + clusterName;
233-
//final String channelName = "web";
234238

235239
// create route for cluster service
236240
String ingressHost = createRouteForOKD(serviceName, domainNamespace);
237241

238242
// Since the app seems to take a bit longer to be available,
239243
// checking if the app is running by executing the curl command
240-
String curlString
241-
= buildCurlCommand(ingressHost, 0, SESSMIGR_APP_WAR_NAME + "/?getCounter", " -b ");
244+
String curlString = buildCurlCommand(ingressHost, 0, SESSMIGR_APP_WAR_NAME
245+
+ "/?getCounter", " -b ");
242246
logger.info("Command to set HTTP request or get HTTP response {0} ", curlString);
243-
testUntil(
244-
assertDoesNotThrow(()
245-
-> () -> exec(curlString, true).stdout().contains("managed-server")),
247+
testUntil(assertDoesNotThrow(()
248+
-> () -> exec(curlString, true).stdout().contains("managed-server")),
246249
logger,
247250
"Checking if app is available");
248251
// verify that two HTTP connections are sticky to the same server
249-
sendHttpRequestsToTestSessionStickinessAndVerify(ingressHost, 0);
252+
testUntil(
253+
withLongRetryPolicy,
254+
isHttpRequestsResponded(ingressHost, 0),
255+
logger,
256+
"Waiting until Http Requests response");
250257
}
251258

252259
/**
@@ -278,7 +285,11 @@ void testSameSessionStickinessUsingClusterService() {
278285
logger.info("cluster port for cluster server {0} is: {1}", clusterAddress, clusterPort);
279286

280287
// verify that two HTTP connections are sticky to the same server
281-
sendHttpRequestsToTestSessionStickinessAndVerify(hostName, clusterPort, clusterAddress);
288+
testUntil(
289+
withLongRetryPolicy,
290+
isHttpRequestsResponded(hostName, clusterPort, clusterAddress),
291+
logger,
292+
"Waiting until Http Requests response");
282293
}
283294

284295
private static String createAndVerifyDomainImage() {
@@ -406,6 +417,10 @@ private Map<String, String> getServerAndSessionInfoAndVerify(String hostName,
406417
String sessionId = httpAttrInfo.get(sessionIdAttr);
407418
String countStr = httpAttrInfo.get(countAttr);
408419

420+
if (serverName == null || sessionId == null || countStr == null) {
421+
return new HashMap<String, String>();
422+
}
423+
409424
// verify that the HTTP response data are not null
410425
assertAll("Check that WebLogic server and session vars is not null or empty",
411426
() -> assertNotNull(serverName,"Server name shouldn’t be null"),
@@ -548,9 +563,17 @@ private int getIngressServiceNodePort(String nameSpace, String ingressServiceNam
548563
return ingressServiceNodePort;
549564
}
550565

551-
private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
552-
int servicePort,
553-
String... clusterAddress) {
566+
private Callable<Boolean> isHttpRequestsResponded(String hostname,
567+
int servicePort,
568+
String... clusterAddress) {
569+
return () -> {
570+
return sendHttpRequestsToTestSessionStickinessAndVerify(hostname, servicePort, clusterAddress);
571+
};
572+
}
573+
574+
private boolean sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
575+
int servicePort,
576+
String... clusterAddress) {
554577
final int counterNum = 4;
555578
final String webServiceSetUrl = SESSMIGR_APP_WAR_NAME + "/?setCounter=" + counterNum;
556579
final String webServiceGetUrl = SESSMIGR_APP_WAR_NAME + "/?getCounter";
@@ -560,7 +583,8 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
560583

561584
// send a HTTP request to set http session state(count number) and save HTTP session info
562585
Map<String, String> httpDataInfo = getServerAndSessionInfoAndVerify(hostname,
563-
servicePort, webServiceSetUrl, " -c ", clusterAddress);
586+
servicePort, webServiceSetUrl, " -c ", clusterAddress);
587+
564588
// get server and session info from web service deployed on the cluster
565589
String serverName1 = httpDataInfo.get(serverNameAttr);
566590
String sessionId1 = httpDataInfo.get(sessionIdAttr);
@@ -570,6 +594,11 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
570594
// send a HTTP request again to get server and session info
571595
httpDataInfo = getServerAndSessionInfoAndVerify(hostname,
572596
servicePort, webServiceGetUrl, " -b ", clusterAddress);
597+
598+
if (httpDataInfo.isEmpty()) {
599+
return false;
600+
}
601+
573602
// get server and session info from web service deployed on the cluster
574603
String serverName2 = httpDataInfo.get(serverNameAttr);
575604
String sessionId2 = httpDataInfo.get(sessionIdAttr);
@@ -591,5 +620,7 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
591620
logger.info("SUCCESS --- test same session stickiness \n"
592621
+ "Two HTTP connections are sticky to server {0} The session state "
593622
+ "from the second HTTP connections is {2}", serverName2, SESSION_STATE);
623+
624+
return true;
594625
}
595626
}

0 commit comments

Comments
 (0)