12
12
import java .util .HashMap ;
13
13
import java .util .List ;
14
14
import java .util .Map ;
15
- import java .util .concurrent .TimeUnit ;
15
+ import java .util .concurrent .Callable ;
16
16
17
17
import io .kubernetes .client .custom .V1Patch ;
18
18
import io .kubernetes .client .openapi .models .V1ConfigMap ;
44
44
import org .junit .jupiter .params .ParameterizedTest ;
45
45
import org .junit .jupiter .params .provider .MethodSource ;
46
46
47
+ import static java .util .concurrent .TimeUnit .MILLISECONDS ;
47
48
import static java .util .concurrent .TimeUnit .MINUTES ;
48
49
import static java .util .concurrent .TimeUnit .SECONDS ;
49
50
import static oracle .weblogic .kubernetes .TestConstants .ADMIN_PASSWORD_DEFAULT ;
@@ -122,6 +123,7 @@ class ItMiiDomain {
122
123
private String miiImageAddSecondApp = null ;
123
124
private String miiImage = null ;
124
125
private static LoggingFacade logger = null ;
126
+ private static volatile boolean mainThreadDone = false ;
125
127
126
128
/**
127
129
* Install Operator.
@@ -137,9 +139,9 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
137
139
.atMost (6 , MINUTES ).await ();
138
140
139
141
// create a reusable quick retry policy
140
- withQuickRetryPolicy = with ().pollDelay (0 , SECONDS )
141
- .and ().with ().pollInterval (4 , SECONDS )
142
- .atMost (10 , SECONDS ).await ();
142
+ withQuickRetryPolicy = with ().pollDelay (1 , SECONDS )
143
+ .and ().with ().pollInterval (2 , SECONDS )
144
+ .atMost (15 , SECONDS ).await ();
143
145
144
146
// get a new unique opNamespace
145
147
logger .info ("Creating unique namespace for Operator" );
@@ -334,7 +336,7 @@ public void testPatchAppV2() {
334
336
accountingThread =
335
337
new Thread (
336
338
() -> {
337
- collectAppAvaiability (
339
+ collectAppAvailability (
338
340
domainNamespace ,
339
341
appAvailability ,
340
342
managedServerPrefix ,
@@ -394,7 +396,7 @@ public void testPatchAppV2() {
394
396
MII_APP_RESPONSE_V2 + i );
395
397
}
396
398
} finally {
397
-
399
+ mainThreadDone = true ;
398
400
if (accountingThread != null ) {
399
401
try {
400
402
accountingThread .join ();
@@ -1060,56 +1062,74 @@ private void checkPodImagePatched(
1060
1062
namespace )));
1061
1063
}
1062
1064
1063
- private static void collectAppAvaiability (
1065
+ private static void collectAppAvailability (
1064
1066
String namespace ,
1065
1067
List <Integer > appAvailability ,
1066
1068
String managedServerPrefix ,
1067
1069
int replicaCount ,
1068
1070
String internalPort ,
1069
1071
String appPath
1070
1072
) {
1071
- boolean v2AppAvailable = false ;
1073
+ with ().pollDelay (2 , SECONDS )
1074
+ .and ().with ().pollInterval (200 , MILLISECONDS )
1075
+ .atMost (15 , MINUTES )
1076
+ .await ()
1077
+ .conditionEvaluationListener (
1078
+ condition -> logger .info ("Waiting for patched application running on all managed servers in namespace {1} "
1079
+ + "(elapsed time {2}ms, remaining time {3}ms)" ,
1080
+ namespace ,
1081
+ condition .getElapsedTimeInMS (),
1082
+ condition .getRemainingTimeInMS ()))
1083
+ .until (assertDoesNotThrow (() -> checkContinuousAvailability (
1084
+ namespace , appAvailability , managedServerPrefix , replicaCount , internalPort , appPath ),
1085
+ String .format (
1086
+ "App is not available on all managed servers in namespace %s." ,
1087
+ namespace )));
1072
1088
1073
- // Access the pod periodically to check application's availability across the duration
1074
- // of patching the domain with newer version of the application.
1075
- while (!v2AppAvailable ) {
1076
- v2AppAvailable = true ;
1089
+ }
1090
+
1091
+ private static Callable <Boolean > checkContinuousAvailability (
1092
+ String namespace ,
1093
+ List <Integer > appAvailability ,
1094
+ String managedServerPrefix ,
1095
+ int replicaCount ,
1096
+ String internalPort ,
1097
+ String appPath ) {
1098
+ return () -> {
1099
+ boolean v2AppAvailable = true ;
1100
+
1077
1101
for (int i = 1 ; i <= replicaCount ; i ++) {
1078
1102
v2AppAvailable = v2AppAvailable && appAccessibleInPod (
1079
1103
namespace ,
1080
- managedServerPrefix + i ,
1081
- internalPort ,
1082
- appPath ,
1104
+ managedServerPrefix + i ,
1105
+ internalPort ,
1106
+ appPath ,
1083
1107
MII_APP_RESPONSE_V2 + i );
1084
1108
}
1085
1109
1086
1110
int count = 0 ;
1087
1111
for (int i = 1 ; i <= replicaCount ; i ++) {
1088
1112
if (appAccessibleInPod (
1089
1113
namespace ,
1090
- managedServerPrefix + i ,
1091
- internalPort ,
1092
- appPath ,
1093
- "Hello World" )) {
1114
+ managedServerPrefix + i ,
1115
+ internalPort ,
1116
+ appPath ,
1117
+ "Hello World" )) {
1094
1118
count ++;
1095
1119
}
1096
1120
}
1097
1121
appAvailability .add (count );
1098
-
1122
+
1099
1123
if (count == 0 ) {
1100
- logger .info ("XXXXXXXXXXX: application not available XXXXXXXX" );
1101
- break ;
1102
- } else {
1103
- logger .fine ("YYYYYYYYYYY: application available YYYYYYYY count = " + count );
1124
+ logger .info ("NNNNNNNNNNN: application not available NNNNNNNN" );
1125
+ return true ;
1104
1126
}
1105
- try {
1106
- TimeUnit .MILLISECONDS .sleep (200 );
1107
- } catch (InterruptedException ie ) {
1108
- // do nothing
1109
- }
1110
- }
1127
+
1128
+ logger .fine ("YYYYYYYYYYY: application available YYYYYYYY count = " + count );
1129
+ return v2AppAvailable || mainThreadDone ;
1130
+ };
1111
1131
}
1112
-
1132
+
1113
1133
private static boolean appAlwaysAvailable (List <Integer > appAvailability ) {
1114
1134
for (Integer count : appAvailability ) {
1115
1135
if (count == 0 ) {
0 commit comments