@@ -312,16 +312,15 @@ void pause_WhenUnpauseWithRetryThrowException_ShouldThrowUnpauseFailedException(
312312 String namespace = "dummyNs" ;
313313 String helmReleaseName = "dummyRelease" ;
314314 int pauseDuration = 1 ;
315-
316315 Instant startTime = Instant .now ().minus (5 , SECONDS );
317316 Instant endTime = Instant .now ().plus (5 , SECONDS );
318- MockedStatic <Instant > mockedTime = mockStatic (Instant .class );
319- mockedTime .when (() -> Instant .now ()).thenReturn (startTime ).thenReturn (endTime );
320317
321318 Pauser pauser = spy (new Pauser (namespace , helmReleaseName ));
319+ PausedDuration pausedDuration = new PausedDuration (startTime , endTime );
320+
322321 doReturn (targetBeforePause ).doReturn (targetAfterPause ).when (pauser ).getTarget ();
323322 doReturn (requestCoordinator ).when (pauser ).getRequestCoordinator (targetBeforePause );
324- doNothing ( ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
323+ doReturn ( pausedDuration ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
325324 doThrow (RuntimeException .class )
326325 .when (pauser )
327326 .unpauseWithRetry (requestCoordinator , MAX_UNPAUSE_RETRY_COUNT );
@@ -335,12 +334,9 @@ void pause_WhenUnpauseWithRetryThrowException_ShouldThrowUnpauseFailedException(
335334 "Unpause operation failed. Scalar products might still be in a paused state. You must"
336335 + " restart related pods by using the `kubectl rollout restart deployment %s`"
337336 + " command to unpause all pods. Note that the pause operations for taking backup"
338- + " succeeded. You can use a backup that was taken during this pause duration:"
339- + " Start Time = %s, End Time = %s. " ,
337+ + " succeeded. You can use a backup that was taken during this pause duration. " ,
340338 DUMMY_OBJECT_NAME , startTime , endTime ),
341339 thrown .getMessage ());
342-
343- mockedTime .close ();
344340 }
345341
346342 @ Test
@@ -350,10 +346,15 @@ void pause_WhenSecondGetTargetThrowException_ShouldThrowPauserException()
350346 String namespace = "dummyNs" ;
351347 String helmReleaseName = "dummyRelease" ;
352348 int pauseDuration = 1 ;
349+ Instant startTime = Instant .now ().minus (5 , SECONDS );
350+ Instant endTime = Instant .now ().plus (5 , SECONDS );
351+
353352 Pauser pauser = spy (new Pauser (namespace , helmReleaseName ));
353+ PausedDuration pausedDuration = new PausedDuration (startTime , endTime );
354+
354355 doReturn (targetBeforePause ).doThrow (RuntimeException .class ).when (pauser ).getTarget ();
355356 doReturn (requestCoordinator ).when (pauser ).getRequestCoordinator (targetBeforePause );
356- doNothing ( ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
357+ doReturn ( pausedDuration ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
357358 doNothing ().when (pauser ).unpauseWithRetry (any (), anyInt ());
358359
359360 // Act & Assert
@@ -373,10 +374,15 @@ void pause_WhenSecondGetTargetThrowException_ShouldThrowPauserException()
373374 String namespace = "dummyNs" ;
374375 String helmReleaseName = "dummyRelease" ;
375376 int pauseDuration = 1 ;
377+ Instant startTime = Instant .now ().minus (5 , SECONDS );
378+ Instant endTime = Instant .now ().plus (5 , SECONDS );
379+
376380 Pauser pauser = spy (new Pauser (namespace , helmReleaseName ));
381+ PausedDuration pausedDuration = new PausedDuration (startTime , endTime );
382+
377383 doReturn (targetBeforePause ).doThrow (RuntimeException .class ).when (pauser ).getTarget ();
378384 doReturn (requestCoordinator ).when (pauser ).getRequestCoordinator (targetBeforePause );
379- doNothing ( ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
385+ doReturn ( pausedDuration ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
380386 doThrow (RuntimeException .class )
381387 .when (pauser )
382388 .unpauseWithRetry (requestCoordinator , MAX_UNPAUSE_RETRY_COUNT );
@@ -400,10 +406,15 @@ void pause_WhenTargetStatusEqualsThrowException_ShouldThrowStatusCheckFailedExce
400406 String namespace = "dummyNs" ;
401407 String helmReleaseName = "dummyRelease" ;
402408 int pauseDuration = 1 ;
409+ Instant startTime = Instant .now ().minus (5 , SECONDS );
410+ Instant endTime = Instant .now ().plus (5 , SECONDS );
411+
403412 Pauser pauser = spy (new Pauser (namespace , helmReleaseName ));
413+ PausedDuration pausedDuration = new PausedDuration (startTime , endTime );
414+
404415 doReturn (targetBeforePause ).doReturn (targetAfterPause ).when (pauser ).getTarget ();
405416 doReturn (requestCoordinator ).when (pauser ).getRequestCoordinator (targetBeforePause );
406- doNothing ( ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
417+ doReturn ( pausedDuration ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
407418 doNothing ().when (pauser ).unpauseWithRetry (any (), anyInt ());
408419 doThrow (RuntimeException .class ).when (pauser ).targetStatusEquals (any (), any ());
409420
@@ -425,10 +436,15 @@ void pause_WhenTargetStatusEqualsThrowException_ShouldThrowStatusCheckFailedExce
425436 String namespace = "dummyNs" ;
426437 String helmReleaseName = "dummyRelease" ;
427438 int pauseDuration = 1 ;
439+ Instant startTime = Instant .now ().minus (5 , SECONDS );
440+ Instant endTime = Instant .now ().plus (5 , SECONDS );
441+
428442 Pauser pauser = spy (new Pauser (namespace , helmReleaseName ));
443+ PausedDuration pausedDuration = new PausedDuration (startTime , endTime );
444+
429445 doReturn (targetBeforePause ).doReturn (targetAfterPause ).when (pauser ).getTarget ();
430446 doReturn (requestCoordinator ).when (pauser ).getRequestCoordinator (targetBeforePause );
431- doNothing ( ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
447+ doReturn ( pausedDuration ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
432448 doThrow (RuntimeException .class )
433449 .when (pauser )
434450 .unpauseWithRetry (requestCoordinator , MAX_UNPAUSE_RETRY_COUNT );
@@ -453,7 +469,12 @@ void pause_WhenTargetPodStatusChanged_ShouldThrowStatusCheckFailedException()
453469 String namespace = "dummyNs" ;
454470 String helmReleaseName = "dummyRelease" ;
455471 int pauseDuration = 1 ;
472+ Instant startTime = Instant .now ().minus (5 , SECONDS );
473+ Instant endTime = Instant .now ().plus (5 , SECONDS );
474+
456475 Pauser pauser = spy (new Pauser (namespace , helmReleaseName ));
476+ PausedDuration pausedDuration = new PausedDuration (startTime , endTime );
477+
457478 doReturn (targetBeforePause ).doReturn (targetAfterPause ).when (pauser ).getTarget ();
458479 doReturn (requestCoordinator ).when (pauser ).getRequestCoordinator (targetBeforePause );
459480
@@ -476,7 +497,7 @@ void pause_WhenTargetPodStatusChanged_ShouldThrowStatusCheckFailedException()
476497 doReturn (beforeTargetStatus ).when (targetBeforePause ).getStatus ();
477498 doReturn (afterTargetStatus ).when (targetAfterPause ).getStatus ();
478499
479- doNothing ( ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
500+ doReturn ( pausedDuration ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
480501 doNothing ().when (pauser ).unpauseWithRetry (any (), anyInt ());
481502
482503 // Act & Assert
@@ -528,10 +549,15 @@ void pause_WhenUnpauseFailedAndTargetPodStatusChanged_ShouldThrowUnpauseFailedEx
528549 String namespace = "dummyNs" ;
529550 String helmReleaseName = "dummyRelease" ;
530551 int pauseDuration = 1 ;
552+ Instant startTime = Instant .now ().minus (5 , SECONDS );
553+ Instant endTime = Instant .now ().plus (5 , SECONDS );
554+
531555 Pauser pauser = spy (new Pauser (namespace , helmReleaseName ));
556+ PausedDuration pausedDuration = new PausedDuration (startTime , endTime );
557+
532558 doReturn (targetBeforePause ).doReturn (targetAfterPause ).when (pauser ).getTarget ();
533559 doReturn (requestCoordinator ).when (pauser ).getRequestCoordinator (targetBeforePause );
534- doNothing ( ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
560+ doReturn ( pausedDuration ).when (pauser ).pauseInternal (any (), anyInt (), anyLong ());
535561 doThrow (RuntimeException .class )
536562 .when (pauser )
537563 .unpauseWithRetry (requestCoordinator , MAX_UNPAUSE_RETRY_COUNT );
0 commit comments