88import java .util .List ;
99import java .util .Map ;
1010import java .util .Optional ;
11+ import java .util .concurrent .Callable ;
1112import java .util .regex .Matcher ;
1213import java .util .regex .Pattern ;
1314
5354import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
5455import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getServiceExtIPAddrtOke ;
5556import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
57+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .withLongRetryPolicy ;
5658import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainAndVerify ;
5759import static oracle .weblogic .kubernetes .utils .ExecCommand .exec ;
5860import 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,26 @@ 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" );
251+
248252 // verify that two HTTP connections are sticky to the same server
249- sendHttpRequestsToTestSessionStickinessAndVerify (ingressHost , 0 );
253+ testUntil (
254+ withLongRetryPolicy ,
255+ isHttpRequestsResponded (ingressHost , 0 ),
256+ logger ,
257+ "Waiting until Http Requests response" );
250258 }
251259
252260 /**
@@ -278,7 +286,11 @@ void testSameSessionStickinessUsingClusterService() {
278286 logger .info ("cluster port for cluster server {0} is: {1}" , clusterAddress , clusterPort );
279287
280288 // verify that two HTTP connections are sticky to the same server
281- sendHttpRequestsToTestSessionStickinessAndVerify (hostName , clusterPort , clusterAddress );
289+ testUntil (
290+ withLongRetryPolicy ,
291+ isHttpRequestsResponded (hostName , clusterPort , clusterAddress ),
292+ logger ,
293+ "Waiting until Http Requests response" );
282294 }
283295
284296 private static String createAndVerifyDomainImage () {
@@ -406,6 +418,10 @@ private Map<String, String> getServerAndSessionInfoAndVerify(String hostName,
406418 String sessionId = httpAttrInfo .get (sessionIdAttr );
407419 String countStr = httpAttrInfo .get (countAttr );
408420
421+ if (serverName == null || sessionId == null || countStr == null ) {
422+ return new HashMap <String , String >();
423+ }
424+
409425 // verify that the HTTP response data are not null
410426 assertAll ("Check that WebLogic server and session vars is not null or empty" ,
411427 () -> assertNotNull (serverName ,"Server name shouldn’t be null" ),
@@ -548,7 +564,15 @@ private int getIngressServiceNodePort(String nameSpace, String ingressServiceNam
548564 return ingressServiceNodePort ;
549565 }
550566
551- private void sendHttpRequestsToTestSessionStickinessAndVerify (String hostname ,
567+ private Callable <Boolean > isHttpRequestsResponded (String hostname ,
568+ int servicePort ,
569+ String ... clusterAddress ) {
570+ return () -> {
571+ return sendHttpRequestsToTestSessionStickinessAndVerify (hostname , servicePort , clusterAddress );
572+ };
573+ }
574+
575+ private boolean sendHttpRequestsToTestSessionStickinessAndVerify (String hostname ,
552576 int servicePort ,
553577 String ... clusterAddress ) {
554578 final int counterNum = 4 ;
@@ -561,6 +585,7 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
561585 // send a HTTP request to set http session state(count number) and save HTTP session info
562586 Map <String , String > httpDataInfo = getServerAndSessionInfoAndVerify (hostname ,
563587 servicePort , webServiceSetUrl , " -c " , clusterAddress );
588+
564589 // get server and session info from web service deployed on the cluster
565590 String serverName1 = httpDataInfo .get (serverNameAttr );
566591 String sessionId1 = httpDataInfo .get (sessionIdAttr );
@@ -570,6 +595,11 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
570595 // send a HTTP request again to get server and session info
571596 httpDataInfo = getServerAndSessionInfoAndVerify (hostname ,
572597 servicePort , webServiceGetUrl , " -b " , clusterAddress );
598+
599+ if (httpDataInfo .isEmpty ()) {
600+ return false ;
601+ }
602+
573603 // get server and session info from web service deployed on the cluster
574604 String serverName2 = httpDataInfo .get (serverNameAttr );
575605 String sessionId2 = httpDataInfo .get (sessionIdAttr );
@@ -591,5 +621,7 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
591621 logger .info ("SUCCESS --- test same session stickiness \n "
592622 + "Two HTTP connections are sticky to server {0} The session state "
593623 + "from the second HTTP connections is {2}" , serverName2 , SESSION_STATE );
624+
625+ return true ;
594626 }
595627}
0 commit comments