5
5
import java .util .Optional ;
6
6
import java .util .concurrent .TimeUnit ;
7
7
import java .util .function .BiFunction ;
8
+ import java .util .function .Supplier ;
8
9
9
10
import org .junit .jupiter .api .BeforeEach ;
10
11
import org .junit .jupiter .api .Test ;
11
12
import org .mockito .ArgumentCaptor ;
12
- import org .mockito .ArgumentMatcher ;
13
13
import org .mockito .ArgumentMatchers ;
14
14
import org .mockito .stubbing .Answer ;
15
15
28
28
import io .javaoperatorsdk .operator .api .reconciler .Cleaner ;
29
29
import io .javaoperatorsdk .operator .api .reconciler .Context ;
30
30
import io .javaoperatorsdk .operator .api .reconciler .DeleteControl ;
31
- import io .javaoperatorsdk .operator .api .reconciler .ErrorStatusHandler ;
32
31
import io .javaoperatorsdk .operator .api .reconciler .ErrorStatusUpdateControl ;
33
32
import io .javaoperatorsdk .operator .api .reconciler .Reconciler ;
34
33
import io .javaoperatorsdk .operator .api .reconciler .RetryInfo ;
@@ -479,7 +478,7 @@ void callErrorStatusHandlerIfImplemented() {
479
478
reconciler .reconcile = (r , c ) -> {
480
479
throw new IllegalStateException ("Error Status Test" );
481
480
};
482
- reconciler .errorHandler = (r , ri , e ) -> {
481
+ reconciler .errorHandler = () -> {
483
482
testCustomResource .getStatus ().setConfigMapStatus (ERROR_MESSAGE );
484
483
return ErrorStatusUpdateControl .patchStatus (testCustomResource );
485
484
};
@@ -499,7 +498,7 @@ public boolean isLastAttempt() {
499
498
}).setResource (testCustomResource ));
500
499
501
500
verify (customResourceFacade , times (1 )).patchStatus (eq (testCustomResource ), any ());
502
- verify ((( ErrorStatusHandler ) reconciler ) , times (1 )).updateErrorStatus (eq (testCustomResource ),
501
+ verify (reconciler , times (1 )).updateErrorStatus (eq (testCustomResource ),
503
502
any (), any ());
504
503
}
505
504
@@ -510,15 +509,15 @@ void callErrorStatusHandlerEvenOnFirstError() {
510
509
reconciler .reconcile = (r , c ) -> {
511
510
throw new IllegalStateException ("Error Status Test" );
512
511
};
513
- reconciler .errorHandler = (r , ri , e ) -> {
512
+ reconciler .errorHandler = () -> {
514
513
testCustomResource .getStatus ().setConfigMapStatus (ERROR_MESSAGE );
515
514
return ErrorStatusUpdateControl .patchStatus (testCustomResource );
516
515
};
517
516
518
517
var postExecControl = reconciliationDispatcher .handleExecution (
519
518
new ExecutionScope (null ).setResource (testCustomResource ));
520
519
verify (customResourceFacade , times (1 )).patchStatus (eq (testCustomResource ), any ());
521
- verify ((( ErrorStatusHandler ) reconciler ) , times (1 )).updateErrorStatus (eq (testCustomResource ),
520
+ verify (reconciler , times (1 )).updateErrorStatus (eq (testCustomResource ),
522
521
any (), any ());
523
522
assertThat (postExecControl .exceptionDuringExecution ()).isTrue ();
524
523
}
@@ -529,15 +528,15 @@ void errorHandlerCanInstructNoRetryWithUpdate() {
529
528
reconciler .reconcile = (r , c ) -> {
530
529
throw new IllegalStateException ("Error Status Test" );
531
530
};
532
- reconciler .errorHandler = (r , ri , e ) -> {
531
+ reconciler .errorHandler = () -> {
533
532
testCustomResource .getStatus ().setConfigMapStatus (ERROR_MESSAGE );
534
533
return ErrorStatusUpdateControl .patchStatus (testCustomResource ).withNoRetry ();
535
534
};
536
535
537
536
var postExecControl = reconciliationDispatcher .handleExecution (
538
537
new ExecutionScope (null ).setResource (testCustomResource ));
539
538
540
- verify ((( ErrorStatusHandler ) reconciler ) , times (1 )).updateErrorStatus (eq (testCustomResource ),
539
+ verify (reconciler , times (1 )).updateErrorStatus (eq (testCustomResource ),
541
540
any (), any ());
542
541
verify (customResourceFacade , times (1 )).patchStatus (eq (testCustomResource ), any ());
543
542
assertThat (postExecControl .exceptionDuringExecution ()).isFalse ();
@@ -549,15 +548,15 @@ void errorHandlerCanInstructNoRetryNoUpdate() {
549
548
reconciler .reconcile = (r , c ) -> {
550
549
throw new IllegalStateException ("Error Status Test" );
551
550
};
552
- reconciler .errorHandler = (r , ri , e ) -> {
551
+ reconciler .errorHandler = () -> {
553
552
testCustomResource .getStatus ().setConfigMapStatus (ERROR_MESSAGE );
554
553
return ErrorStatusUpdateControl .<TestCustomResource >noStatusUpdate ().withNoRetry ();
555
554
};
556
555
557
556
var postExecControl = reconciliationDispatcher .handleExecution (
558
557
new ExecutionScope (null ).setResource (testCustomResource ));
559
558
560
- verify ((( ErrorStatusHandler ) reconciler ) , times (1 )).updateErrorStatus (eq (testCustomResource ),
559
+ verify (reconciler , times (1 )).updateErrorStatus (eq (testCustomResource ),
561
560
any (), any ());
562
561
verify (customResourceFacade , times (0 )).patchStatus (eq (testCustomResource ), any ());
563
562
assertThat (postExecControl .exceptionDuringExecution ()).isFalse ();
@@ -570,13 +569,13 @@ void errorStatusHandlerCanPatchResource() {
570
569
throw new IllegalStateException ("Error Status Test" );
571
570
};
572
571
reconciler .errorHandler =
573
- (r , ri , e ) -> ErrorStatusUpdateControl .patchStatus (testCustomResource );
572
+ () -> ErrorStatusUpdateControl .patchStatus (testCustomResource );
574
573
575
574
reconciliationDispatcher .handleExecution (
576
575
new ExecutionScope (null ).setResource (testCustomResource ));
577
576
578
577
verify (customResourceFacade , times (1 )).patchStatus (eq (testCustomResource ), any ());
579
- verify ((( ErrorStatusHandler ) reconciler ) , times (1 )).updateErrorStatus (eq (testCustomResource ),
578
+ verify (reconciler , times (1 )).updateErrorStatus (eq (testCustomResource ),
580
579
any (), any ());
581
580
}
582
581
@@ -592,16 +591,14 @@ void ifRetryLimitedToZeroMaxAttemptsErrorHandlerGetsCorrectLastAttempt() {
592
591
reconciler .reconcile = (r , c ) -> {
593
592
throw new IllegalStateException ("Error Status Test" );
594
593
};
595
- var mockErrorHandler = mock (ErrorStatusHandler .class );
596
- when (mockErrorHandler .updateErrorStatus (any (), any (), any ()))
597
- .thenReturn (ErrorStatusUpdateControl .noStatusUpdate ());
598
- reconciler .errorHandler = mockErrorHandler ;
594
+
595
+ reconciler .errorHandler = () -> ErrorStatusUpdateControl .noStatusUpdate ();
599
596
600
597
reconciliationDispatcher .handleExecution (
601
598
new ExecutionScope (null ).setResource (testCustomResource ));
602
599
603
- verify (mockErrorHandler , times (1 )).updateErrorStatus (any (),
604
- ArgumentMatchers .argThat (( ArgumentMatcher < Context < TestCustomResource >>) context -> {
600
+ verify (reconciler , times (1 )).updateErrorStatus (any (),
601
+ ArgumentMatchers .argThat (context -> {
605
602
var retryInfo = context .getRetryInfo ().orElseThrow ();
606
603
return retryInfo .isLastAttempt ();
607
604
}), any ());
@@ -651,7 +648,7 @@ void reSchedulesFromErrorHandler() {
651
648
throw new IllegalStateException ("Error Status Test" );
652
649
};
653
650
reconciler .errorHandler =
654
- (r , ri , e ) -> ErrorStatusUpdateControl .<TestCustomResource >noStatusUpdate ()
651
+ () -> ErrorStatusUpdateControl .<TestCustomResource >noStatusUpdate ()
655
652
.rescheduleAfter (delay );
656
653
657
654
var res = reconciliationDispatcher .handleExecution (
@@ -691,12 +688,11 @@ public <T extends HasMetadata> ExecutionScope<T> executionScopeWithCREvent(T res
691
688
}
692
689
693
690
private class TestReconciler
694
- implements Reconciler <TestCustomResource >, Cleaner <TestCustomResource >,
695
- ErrorStatusHandler <TestCustomResource > {
691
+ implements Reconciler <TestCustomResource >, Cleaner <TestCustomResource > {
696
692
697
693
private BiFunction <TestCustomResource , Context , UpdateControl <TestCustomResource >> reconcile ;
698
694
private BiFunction <TestCustomResource , Context , DeleteControl > cleanup ;
699
- private ErrorStatusHandler < TestCustomResource > errorHandler ;
695
+ private Supplier < ErrorStatusUpdateControl > errorHandler ;
700
696
701
697
@ Override
702
698
public UpdateControl <TestCustomResource > reconcile (TestCustomResource resource ,
@@ -719,7 +715,7 @@ public DeleteControl cleanup(TestCustomResource resource, Context context) {
719
715
public ErrorStatusUpdateControl <TestCustomResource > updateErrorStatus (
720
716
TestCustomResource resource ,
721
717
Context <TestCustomResource > context , Exception e ) {
722
- return errorHandler != null ? errorHandler .updateErrorStatus ( resource , context , e )
718
+ return errorHandler != null ? errorHandler .get ( )
723
719
: ErrorStatusUpdateControl .noStatusUpdate ();
724
720
}
725
721
}
0 commit comments