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,25 @@ 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" );
248
251
// 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" );
250
257
}
251
258
252
259
/**
@@ -278,7 +285,11 @@ void testSameSessionStickinessUsingClusterService() {
278
285
logger .info ("cluster port for cluster server {0} is: {1}" , clusterAddress , clusterPort );
279
286
280
287
// 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" );
282
293
}
283
294
284
295
private static String createAndVerifyDomainImage () {
@@ -406,6 +417,10 @@ private Map<String, String> getServerAndSessionInfoAndVerify(String hostName,
406
417
String sessionId = httpAttrInfo .get (sessionIdAttr );
407
418
String countStr = httpAttrInfo .get (countAttr );
408
419
420
+ if (serverName == null || sessionId == null || countStr == null ) {
421
+ return new HashMap <String , String >();
422
+ }
423
+
409
424
// verify that the HTTP response data are not null
410
425
assertAll ("Check that WebLogic server and session vars is not null or empty" ,
411
426
() -> assertNotNull (serverName ,"Server name shouldn’t be null" ),
@@ -548,9 +563,17 @@ private int getIngressServiceNodePort(String nameSpace, String ingressServiceNam
548
563
return ingressServiceNodePort ;
549
564
}
550
565
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 ) {
554
577
final int counterNum = 4 ;
555
578
final String webServiceSetUrl = SESSMIGR_APP_WAR_NAME + "/?setCounter=" + counterNum ;
556
579
final String webServiceGetUrl = SESSMIGR_APP_WAR_NAME + "/?getCounter" ;
@@ -560,7 +583,8 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
560
583
561
584
// send a HTTP request to set http session state(count number) and save HTTP session info
562
585
Map <String , String > httpDataInfo = getServerAndSessionInfoAndVerify (hostname ,
563
- servicePort , webServiceSetUrl , " -c " , clusterAddress );
586
+ servicePort , webServiceSetUrl , " -c " , clusterAddress );
587
+
564
588
// get server and session info from web service deployed on the cluster
565
589
String serverName1 = httpDataInfo .get (serverNameAttr );
566
590
String sessionId1 = httpDataInfo .get (sessionIdAttr );
@@ -570,6 +594,11 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
570
594
// send a HTTP request again to get server and session info
571
595
httpDataInfo = getServerAndSessionInfoAndVerify (hostname ,
572
596
servicePort , webServiceGetUrl , " -b " , clusterAddress );
597
+
598
+ if (httpDataInfo .isEmpty ()) {
599
+ return false ;
600
+ }
601
+
573
602
// get server and session info from web service deployed on the cluster
574
603
String serverName2 = httpDataInfo .get (serverNameAttr );
575
604
String sessionId2 = httpDataInfo .get (sessionIdAttr );
@@ -591,5 +620,7 @@ private void sendHttpRequestsToTestSessionStickinessAndVerify(String hostname,
591
620
logger .info ("SUCCESS --- test same session stickiness \n "
592
621
+ "Two HTTP connections are sticky to server {0} The session state "
593
622
+ "from the second HTTP connections is {2}" , serverName2 , SESSION_STATE );
623
+
624
+ return true ;
594
625
}
595
626
}
0 commit comments