@@ -34,7 +34,7 @@ public void testInvalidRetryTimes() {
3434 @ Test
3535 public void testRetry () {
3636 final Exception expectedEx = new RuntimeException ();
37- final int retryTimes = 10 ;
37+ final int retryTimes = 9 ;
3838
3939 doThrow (expectedEx ).when (wrappedHandler ).handleRecord (testingRecord );
4040
@@ -44,7 +44,7 @@ public void testRetry() {
4444 .isInstanceOf (HandleMessageFailedException .class )
4545 .hasCause (expectedEx );
4646
47- verify (wrappedHandler , times (retryTimes )).handleRecord (testingRecord );
47+ verify (wrappedHandler , times (retryTimes + 1 )).handleRecord (testingRecord );
4848 }
4949
5050 @ Test
@@ -61,8 +61,8 @@ public void testNoRetry() {
6161 }
6262
6363 @ Test
64- public void testRetrySuccess () {
65- final Exception expectedEx = new RuntimeException ();
64+ public void testRetryToSuccess () {
65+ final Exception expectedEx = new RuntimeException ("intended exception" );
6666 final int retryTimes = 10 ;
6767
6868 doThrow (expectedEx ).doNothing ().when (wrappedHandler ).handleRecord (testingRecord );
@@ -75,7 +75,7 @@ public void testRetrySuccess() {
7575 }
7676
7777 @ Test
78- public void testInterruptInRetryInterval () throws Exception {
78+ public void testInterruptInRetryIntervalAndFailForever () throws Exception {
7979 final Exception expectedEx = new RuntimeException ();
8080 final int retryTimes = 10 ;
8181
@@ -87,8 +87,23 @@ public void testInterruptInRetryInterval() throws Exception {
8787 .isInstanceOf (HandleMessageFailedException .class )
8888 .hasCause (expectedEx );
8989
90- assertThat (Thread .currentThread ().isInterrupted ()).isTrue ();
91- verify (wrappedHandler , times (1 )).handleRecord (testingRecord );
90+ assertThat (Thread .interrupted ()).isTrue ();
91+ verify (wrappedHandler , times (retryTimes + 1 )).handleRecord (testingRecord );
92+ }
93+
94+ @ Test
95+ public void testInterruptInRetryIntervalAndRetryToSuccess () throws Exception {
96+ final Exception expectedEx = new RuntimeException ("intended exception" );
97+ final int retryTimes = 2 ;
98+
99+ doThrow (expectedEx ).doThrow (expectedEx ).doNothing ().when (wrappedHandler ).handleRecord (testingRecord );
100+
101+ final ConsumerRecordHandler <Object , Object > handler = new RetriableConsumerRecordHandler <>(wrappedHandler , retryTimes , Duration .ofHours (1 ));
102+ interruptAfter (Thread .currentThread (), 200 );
103+ handler .handleRecord (testingRecord );
104+
105+ assertThat (Thread .interrupted ()).isTrue ();
106+ verify (wrappedHandler , times (3 )).handleRecord (testingRecord );
92107 }
93108
94109 private void interruptAfter (Thread threadToInterrupt , long triggerDelayMillis ) throws Exception {
0 commit comments