1818import oracle .kubernetes .operator .utils .ExecResult ;
1919import oracle .kubernetes .operator .utils .Operator ;
2020import oracle .kubernetes .operator .utils .TestUtils ;
21- import org .junit .AfterClass ;
2221import org .junit .Assert ;
2322import org .junit .Assume ;
2423import org .junit .BeforeClass ;
@@ -82,11 +81,7 @@ public static void staticPrepare() throws Exception {
8281 // Wait some time for deployment gets ready
8382 // Thread.sleep(10 * 1000);
8483 // restart managed server to get default shutdown time with default shutdown options
85- getDefaultShutdownTime ();
8684
87- logger .info (
88- "termination time for managed-server1 with default shutdown options is:"
89- + terminationDefaultOptionsTime );
9085 }
9186 }
9287
@@ -95,7 +90,7 @@ public static void staticPrepare() throws Exception {
9590 *
9691 * @throws Exception
9792 */
98- @ AfterClass
93+ // @AfterClass
9994 public static void staticUnPrepare () throws Exception {
10095 if (!QUICKTEST ) {
10196 logger .info ("+++++++++++++++++++++++++++++++++---------------------------------+" );
@@ -127,11 +122,14 @@ public void testAddShutdownOptionsToMS() throws Exception {
127122 DomainCRD crd = new DomainCRD (originalYaml );
128123
129124 Map <String , Object > shutdownProps = new HashMap ();
130- shutdownProps .put ("timeoutSeconds" , 60 );
125+ shutdownProps .put ("timeoutSeconds" , 160 );
131126 shutdownProps .put ("shutdownType" , "Forced" );
132127 shutdownProps .put ("ignoreSessions" , true );
133128 crd .addShutDownOptionToMS ("managed-server1" , shutdownProps );
134- updateCRDYamlVerifyShutdown (crd , 1000 );
129+ updateCRDYamlVerifyShutdown (crd , 0 );
130+ Assert .assertTrue (checkShutdownUpdatedProp (domainUid + "-admin-server" , "Graceful" ));
131+ Assert .assertTrue (
132+ checkShutdownUpdatedProp (domainUid + "-managed-server1" , "Forced" , "160" , "true" ));
135133 }
136134
137135 /**
@@ -146,8 +144,8 @@ public void testAddShutdownOptionToCluster() throws Exception {
146144 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
147145 logTestBegin (testMethodName );
148146 resetDomainCRD ();
149- String podName = domainUid + "-managed-server1" ;
150147 Files .createDirectories (Paths .get (shutdownTmpDir ));
148+
151149 // Modify the original domain yaml to include shutdown options in cluster-1 node
152150 DomainCRD crd = new DomainCRD (originalYaml );
153151
@@ -158,6 +156,8 @@ public void testAddShutdownOptionToCluster() throws Exception {
158156
159157 crd .addShutdownOptionsToCluster (domain .getClusterName (), shutdownProps );
160158 updateCRDYamlVerifyShutdown (crd , 0 );
159+ Assert .assertTrue (checkShutdownUpdatedProp (domainUid + "-admin-server" , "Graceful" ));
160+ Assert .assertTrue (checkShutdownUpdatedProp (domainUid + "-managed-server1" , "Forced" ));
161161 logger .log (Level .INFO , "SUCCESS - {0}" , testMethodName );
162162 }
163163
@@ -173,19 +173,46 @@ public void testAddShutdownOptionsToDomain() throws Exception {
173173 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
174174 logTestBegin (testMethodName );
175175 resetDomainCRD ();
176- String podName = domainUid + "-managed-server1" ;
177176 Files .createDirectories (Paths .get (shutdownTmpDir ));
178177 // Modify the original domain yaml to include shutdown options in domain spec node
179178 DomainCRD crd = new DomainCRD (originalYaml );
180179
181180 Map <String , Object > shutdownProps = new HashMap ();
182181 shutdownProps .put ("timeoutSeconds" , 160 );
183- shutdownProps .put ("ignoreSessions" , false );
184182 crd .addShutdownOptionToDomain (shutdownProps );
183+
184+ updateCRDYamlVerifyShutdown (crd , 0 );
185+ Assert .assertTrue (checkShutdownUpdatedProp (domainUid + "-admin-server" , "160" ));
186+ Assert .assertTrue (checkShutdownUpdatedProp (domainUid + "-managed-server1" , "160" ));
187+
188+ logger .log (Level .INFO , "SUCCESS - {0}" , testMethodName );
189+ }
190+
191+ /**
192+ * Add shutdown option IgnoreSessions at managed server level and verify all pods are Terminated
193+ * according to the setting
194+ *
195+ * @throws Exception when domain.yaml cannot be read or modified
196+ */
197+ @ Test
198+ public void testAddShutdownOptionsToMSIgnoreSessions () throws Exception {
199+
200+ Assume .assumeFalse (QUICKTEST );
201+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
202+ logTestBegin (testMethodName );
203+
204+ resetDomainCRD ();
205+ Files .createDirectories (Paths .get (shutdownTmpDir ));
206+ // Modify the original domain yaml to include shutdown options in domain spec node
207+ DomainCRD crd = new DomainCRD (originalYaml );
208+
209+ Map <String , Object > shutdownProps = new HashMap ();
210+ shutdownProps .put ("timeoutSeconds" , 160 );
211+ shutdownProps .put ("ignoreSessions" , false );
212+ crd .addShutDownOptionToMS ("managed-server1" , shutdownProps );
185213 long delayTime = 50 * 1000 ;
186214 updateCRDYamlVerifyShutdown (crd , delayTime );
187- Assert .assertTrue (
188- checkShutdownUpdatedProp (domainUid + "-admin-server" , "160" , "false" , "Graceful" ));
215+
189216 Assert .assertTrue (
190217 checkShutdownUpdatedProp (domainUid + "-managed-server1" , "160" , "false" , "Graceful" ));
191218 if (terminationTime < delayTime ) {
@@ -195,15 +222,13 @@ public void testAddShutdownOptionsToDomain() throws Exception {
195222 long terminationTimeWithIgnoreSessionFalse = terminationTime ;
196223 logger .info (
197224 " Termination time with ignoreSession=false :" + terminationTimeWithIgnoreSessionFalse );
198- resetDomainCRD ();
225+
199226 shutdownProps = new HashMap ();
200227 shutdownProps .put ("timeoutSeconds" , 160 );
201228 shutdownProps .put ("ignoreSessions" , true );
202- crd .addShutdownOptionToDomain (shutdownProps );
203229
230+ crd .addShutDownOptionToMS ("managed-server1" , shutdownProps );
204231 updateCRDYamlVerifyShutdown (crd , delayTime );
205- Assert .assertTrue (
206- checkShutdownUpdatedProp (domainUid + "-admin-server" , "160" , "true" , "Graceful" ));
207232 Assert .assertTrue (
208233 checkShutdownUpdatedProp (domainUid + "-managed-server1" , "160" , "true" , "Graceful" ));
209234
@@ -215,30 +240,73 @@ public void testAddShutdownOptionsToDomain() throws Exception {
215240 logger .info ("FAILURE: did not ignore opened sessions during shutdown" );
216241 throw new Exception ("FAILURE: did not ignore opened sessions during shutdown" );
217242 }
243+ logger .log (Level .INFO , "SUCCESS - {0}" , testMethodName );
244+ }
245+
246+ /**
247+ * Add shutdown option Timeout at managed server level and verify all pods are Terminated
248+ * according to the setting
249+ *
250+ * @throws Exception when domain.yaml cannot be read or modified
251+ */
252+ @ Test
253+ public void testAddShutdownOptionsToMSTimeout () throws Exception {
254+
255+ Assume .assumeFalse (QUICKTEST );
256+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
257+ logTestBegin (testMethodName );
258+
218259 resetDomainCRD ();
260+ Files .createDirectories (Paths .get (shutdownTmpDir ));
261+ // Modify the original domain yaml to include shutdown options in domain spec node
262+ DomainCRD crd = new DomainCRD (originalYaml );
263+
264+ long delayTime = 50 * 1000 ;
219265 // testing timeout
220- shutdownProps = new HashMap ();
266+ Map < String , Object > shutdownProps = new HashMap ();
221267 shutdownProps .put ("timeoutSeconds" , 20 );
222268 shutdownProps .put ("ignoreSessions" , false );
223- crd .addShutdownOptionToDomain ( shutdownProps );
269+ crd .addShutDownOptionToMS ( "managed-server1" , shutdownProps );
224270
225271 updateCRDYamlVerifyShutdown (crd , delayTime );
226- Assert .assertTrue (
227- checkShutdownUpdatedProp (domainUid + "-admin-server" , "20" , "false" , "Graceful" ));
272+
228273 Assert .assertTrue (
229274 checkShutdownUpdatedProp (domainUid + "-managed-server1" , "20" , "false" , "Graceful" ));
230275 if (terminationTime > (3 * 20 * 1000 )) {
231276 logger .info ("\" FAILURE: ignored timeoutValue during shutdown" );
232277 throw new Exception ("FAILURE: ignored timeoutValue during shutdown" );
233278 }
234- // testing Forced
279+ logger .log (Level .INFO , "SUCCESS - {0}" , testMethodName );
280+ }
281+
282+ /**
283+ * Add shutdown option Forced at managed server level and verify all pods are Terminated according
284+ * to the setting
285+ *
286+ * @throws Exception when domain.yaml cannot be read or modified
287+ */
288+ @ Test
289+ public void testAddShutdownOptionsToMSForced () throws Exception {
290+
291+ Assume .assumeFalse (QUICKTEST );
292+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
293+ logTestBegin (testMethodName );
294+
235295 resetDomainCRD ();
236- shutdownProps = new HashMap ();
237- shutdownProps .put ("shutdownType" , "Forced" );
238- crd .addShutdownOptionToDomain (shutdownProps );
296+ if (terminationDefaultOptionsTime == 0 ) {
297+ getDefaultShutdownTime ();
298+ }
299+ Files .createDirectories (Paths .get (shutdownTmpDir ));
300+ // Modify the original domain yaml to include shutdown options in domain spec node
301+ DomainCRD crd = new DomainCRD (originalYaml );
239302
303+ long delayTime = 50 * 1000 ;
304+ // testing timeout
305+ Map <String , Object > shutdownProps = new HashMap ();
306+ shutdownProps .put ("shutdownType" , "Forced" );
307+ crd .addShutDownOptionToMS ("managed-server1" , shutdownProps );
240308 updateCRDYamlVerifyShutdown (crd , delayTime );
241- Assert . assertTrue ( checkShutdownUpdatedProp ( domainUid + "-admin-server" , "Forced" ));
309+
242310 Assert .assertTrue (checkShutdownUpdatedProp (domainUid + "-managed-server1" , "Forced" ));
243311 if ((2 * terminationDefaultOptionsTime < terminationTime )) {
244312 logger .info ("\" FAILURE: ignored timeout Forced value during shutdown" );
@@ -258,7 +326,6 @@ public void testAddEnvShutdownOptions() throws Exception {
258326 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
259327 logTestBegin (testMethodName );
260328 resetDomainCRD ();
261- String podName = domainUid + "-managed-server1" ;
262329 Files .createDirectories (Paths .get (shutdownTmpDir ));
263330 // Modify the original domain yaml to include shutdown env vars options in domain spec node
264331 DomainCRD crd = new DomainCRD (originalYaml );
@@ -284,7 +351,7 @@ public void testShutdownOptionsOverrideViaEnv() throws Exception {
284351 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
285352 logTestBegin (testMethodName );
286353 resetDomainCRD ();
287- String podName = domainUid + "-managed-server1" ;
354+
288355 Files .createDirectories (Paths .get (shutdownTmpDir ));
289356 // Modify the original domain yaml to include shutdown options in domain spec node
290357 DomainCRD crd = new DomainCRD (originalYaml );
@@ -320,7 +387,6 @@ public void testShutdownOptionsOverrideClusterLevel() throws Exception {
320387 String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
321388 logTestBegin (testMethodName );
322389 resetDomainCRD ();
323- String podName = domainUid + "-managed-server1" ;
324390 Files .createDirectories (Paths .get (shutdownTmpDir ));
325391 // Modify the original domain yaml to include shutdown env vars options in domain spec node
326392 DomainCRD crd = new DomainCRD (originalYaml );
@@ -370,13 +436,14 @@ private static void updateCRDYamlVerifyShutdown(DomainCRD crd, long delayTime) t
370436 Files .write (path , modYaml .getBytes (charset ));
371437 modifiedYaml = path .toString ();
372438 // Apply the new yaml to update the domain crd
439+
373440 logger .log (Level .INFO , "kubectl delete -f {0}" , originalYaml );
374441 ExecResult exec = TestUtils .exec ("kubectl delete -f " + originalYaml );
375442 logger .info (exec .stdout ());
376443 TestUtils .checkPodDeleted (domainUid + "-managed-server1" , domainNS );
377444 TestUtils .checkPodDeleted (domainUid + "-admin-server" , domainNS );
378445
379- logger .log (Level .INFO , "kubectl apply -f " , path .toString ());
446+ logger .log (Level .INFO , "kubectl apply -f {0} " , path .toString ());
380447 exec = TestUtils .exec ("kubectl apply -f " + path .toString ());
381448 logger .info (exec .stdout ());
382449
@@ -396,11 +463,15 @@ private static void updateCRDYamlVerifyShutdown(DomainCRD crd, long delayTime) t
396463
397464 logger .info ("Checking termination time" );
398465 terminationTime = checkShutdownTime (domainUid + "-managed-server1" );
466+ logger .info (" termination time " + terminationTime );
399467 }
400468
401469 private static void getDefaultShutdownTime () throws Exception {
402470 shutdownServer ("managed-server1" );
403471 terminationDefaultOptionsTime = checkShutdownTime (domainUid + "-managed-server1" );
472+ logger .info (
473+ " termination pod's time with default shutdown options is: "
474+ + terminationDefaultOptionsTime );
404475 }
405476
406477 private static void resetDomainCRD () throws Exception {
@@ -440,6 +511,7 @@ private static void destroyDomain() throws Exception {
440511 *
441512 * @param testAppPath - URL path for webapp
442513 * @param domain - Domain where webapp deployed
514+ * @param deployApp - option to build and deployApp
443515 * @throws Exception
444516 */
445517 public static void callWebApp (String testAppPath , Domain domain , boolean deployApp )
@@ -448,6 +520,7 @@ public static void callWebApp(String testAppPath, Domain domain, boolean deployA
448520 if (deployApp ) {
449521 domain .buildDeployJavaAppInPod (
450522 testAppName , scriptName , BaseTest .getUsername (), BaseTest .getPassword ());
523+ domain .callWebAppAndVerifyLoadBalancing (testAppName , false );
451524 }
452525 String nodePortHost = domain .getHostNameForCurl ();
453526 int nodePort = domain .getLoadBalancerWebPort ();
@@ -492,6 +565,7 @@ private void scaleCluster(int replicas) throws Exception {
492565 * @param podName
493566 * @throws Exception
494567 */
568+ /*
495569 public static long checkShutdownTime(String podName) throws Exception {
496570 String namespace = domainNS;
497571 long startTime = System.currentTimeMillis();
@@ -507,6 +581,7 @@ public static long checkShutdownTime(String podName) throws Exception {
507581 logger.info("The time to terminate the pod is " + (currentTime - startTime));
508582 return (currentTime - startTime);
509583 }
584+ */
510585
511586 /**
512587 * shutdown managed server
@@ -554,6 +629,51 @@ public static boolean checkShutdownUpdatedProp(String podName, String... props)
554629 if (props .length == propFound .size ()) found = true ;
555630 return found ;
556631 }
632+
633+ public static long checkShutdownTime (String podName ) throws Exception {
634+ long startTime = System .currentTimeMillis ();
635+ long endTime = 0 ;
636+ int maxIterations = 50 ;
637+ int waitPodTime = 5 ;
638+ String matchStr = "Terminating" ;
639+ StringBuffer cmd = new StringBuffer ();
640+ cmd .append ("kubectl get pod " ).append (podName ).append (" -n " ).append (domainNS );
641+ int i = 0 ;
642+ while (i < maxIterations ) {
643+ ExecResult result = ExecCommand .exec (cmd .toString ());
644+
645+ // pod might not have been created or if created loop till condition
646+ if ((result .exitValue () == 0 && result .stdout ().contains (matchStr ))) {
647+ logger .info ("Output for " + cmd + "\n " + result .stdout () + "\n " + result .stderr ());
648+
649+ // check for last iteration
650+ if (i == (maxIterations - 1 )) {
651+ throw new RuntimeException (
652+ "FAILURE: pod " + podName + " is still in " + matchStr + " status, exiting!" );
653+ }
654+ logger .info (
655+ "Pod "
656+ + podName
657+ + " is "
658+ + matchStr
659+ + " Ite ["
660+ + i
661+ + "/"
662+ + maxIterations
663+ + "], sleeping "
664+ + waitPodTime
665+ + " seconds more" );
666+
667+ Thread .sleep (maxIterations * 1000 );
668+ i ++;
669+ } else {
670+ endTime = System .currentTimeMillis ();
671+ logger .info ("Pod " + podName + " is not in the " + matchStr + " status or does not exists" );
672+ break ;
673+ }
674+ }
675+ return (endTime - startTime );
676+ }
557677}
558678
559679class SessionDelayThread implements Runnable {
0 commit comments