8
8
import java .util .List ;
9
9
import java .util .Map ;
10
10
import java .util .Optional ;
11
+ import java .util .concurrent .Callable ;
11
12
import java .util .regex .Matcher ;
12
13
import java .util .regex .Pattern ;
13
14
53
54
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
54
55
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getServiceExtIPAddrtOke ;
55
56
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
57
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .withLongRetryPolicy ;
56
58
import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainAndVerify ;
57
59
import static oracle .weblogic .kubernetes .utils .ExecCommand .exec ;
58
60
import static oracle .weblogic .kubernetes .utils .ImageUtils .createMiiImageAndVerify ;
@@ -182,7 +184,6 @@ void tearDown() {
182
184
@ DisplayName ("Create a Traefik ingress resource and verify that two HTTP connections are sticky to the same server" )
183
185
@ DisabledIfEnvironmentVariable (named = "OKD" , matches = "true" )
184
186
void testSameSessionStickinessUsingTraefik () {
185
-
186
187
final String channelName = "web" ;
187
188
188
189
// create Traefik ingress resource
@@ -216,7 +217,11 @@ void testSameSessionStickinessUsingTraefik() {
216
217
}
217
218
218
219
// 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" );
220
225
}
221
226
222
227
/**
@@ -230,23 +235,26 @@ void testSameSessionStickinessUsingTraefik() {
230
235
@ EnabledIfEnvironmentVariable (named = "OKD" , matches = "true" )
231
236
void testSameSessionStickinessinOKD () {
232
237
final String serviceName = domainUid + "-cluster-" + clusterName ;
233
- //final String channelName = "web";
234
238
235
239
// create route for cluster service
236
240
String ingressHost = createRouteForOKD (serviceName , domainNamespace );
237
241
238
242
// Since the app seems to take a bit longer to be available,
239
243
// 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 " );
242
246
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" )),
246
249
logger ,
247
250
"Checking if app is available" );
251
+
248
252
// 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" );
250
258
}
251
259
252
260
/**
@@ -278,7 +286,11 @@ void testSameSessionStickinessUsingClusterService() {
278
286
logger .info ("cluster port for cluster server {0} is: {1}" , clusterAddress , clusterPort );
279
287
280
288
// 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" );
282
294
}
283
295
284
296
private static String createAndVerifyDomainImage () {
@@ -406,6 +418,10 @@ private Map<String, String> getServerAndSessionInfoAndVerify(String hostName,
406
418
String sessionId = httpAttrInfo .get (sessionIdAttr );
407
419
String countStr = httpAttrInfo .get (countAttr );
408
420
421
+ if (serverName == null || sessionId == null || countStr == null ) {
422
+ return new HashMap <String , String >();
423
+ }
424
+
409
425
// verify that the HTTP response data are not null
410
426
assertAll ("Check that WebLogic server and session vars is not null or empty" ,
411
427
() -> assertNotNull (serverName ,"Server name shouldn’t be null" ),
@@ -548,7 +564,15 @@ private int getIngressServiceNodePort(String nameSpace, String ingressServiceNam
548
564
return ingressServiceNodePort ;
549
565
}
550
566
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 ,
552
576
int servicePort ,
553
577
String ... clusterAddress ) {
554
578
final int counterNum = 4 ;
@@ -561,6 +585,7 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
561
585
// send a HTTP request to set http session state(count number) and save HTTP session info
562
586
Map <String , String > httpDataInfo = getServerAndSessionInfoAndVerify (hostname ,
563
587
servicePort , webServiceSetUrl , " -c " , clusterAddress );
588
+
564
589
// get server and session info from web service deployed on the cluster
565
590
String serverName1 = httpDataInfo .get (serverNameAttr );
566
591
String sessionId1 = httpDataInfo .get (sessionIdAttr );
@@ -570,6 +595,11 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
570
595
// send a HTTP request again to get server and session info
571
596
httpDataInfo = getServerAndSessionInfoAndVerify (hostname ,
572
597
servicePort , webServiceGetUrl , " -b " , clusterAddress );
598
+
599
+ if (httpDataInfo .isEmpty ()) {
600
+ return false ;
601
+ }
602
+
573
603
// get server and session info from web service deployed on the cluster
574
604
String serverName2 = httpDataInfo .get (serverNameAttr );
575
605
String sessionId2 = httpDataInfo .get (sessionIdAttr );
@@ -591,5 +621,7 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
591
621
logger .info ("SUCCESS --- test same session stickiness \n "
592
622
+ "Two HTTP connections are sticky to server {0} The session state "
593
623
+ "from the second HTTP connections is {2}" , serverName2 , SESSION_STATE );
624
+
625
+ return true ;
594
626
}
595
627
}
0 commit comments