|
1 | 1 | /* |
2 | | - * Copyright 2019-2022 the original author or authors. |
| 2 | + * Copyright 2019-2023 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
24 | 24 | import java.util.List; |
25 | 25 | import java.util.Map; |
26 | 26 | import java.util.concurrent.atomic.AtomicBoolean; |
| 27 | +import java.util.concurrent.atomic.AtomicReference; |
27 | 28 |
|
| 29 | +import org.apache.kafka.clients.consumer.Consumer; |
28 | 30 | import org.apache.kafka.clients.consumer.ConsumerRecord; |
29 | 31 | import org.apache.kafka.common.TopicPartition; |
30 | 32 | import org.junit.jupiter.api.Test; |
@@ -186,4 +188,32 @@ void exceptionChanges(boolean reset) { |
186 | 188 | } |
187 | 189 | } |
188 | 190 |
|
| 191 | + @Test |
| 192 | + void exceptionChangesWithTimestampedException() throws InterruptedException { |
| 193 | + FixedBackOff bo1 = new FixedBackOff(0L, 5L); |
| 194 | + FailedRecordTracker tracker = new FailedRecordTracker((rec, ex) -> { }, bo1, mock(LogAccessor.class)); |
| 195 | + AtomicReference<Exception> captured = new AtomicReference<>(); |
| 196 | + tracker.setBackOffFunction((record, ex) -> { |
| 197 | + captured.set(ex); |
| 198 | + if (ex instanceof IllegalStateException) { |
| 199 | + return bo1; |
| 200 | + } |
| 201 | + else { |
| 202 | + return new FixedBackOff(0L, 0L); |
| 203 | + } |
| 204 | + }); |
| 205 | + IllegalStateException ise = new IllegalStateException(); |
| 206 | + Exception ex = new ListenerExecutionFailedException("", new TimestampedException( |
| 207 | + new ListenerExecutionFailedException("", ise))); |
| 208 | + ConsumerRecord<?, ?> record = mock(ConsumerRecord.class); |
| 209 | + Consumer<?, ?> consumer = mock(Consumer.class); |
| 210 | + assertThat(tracker.recovered(record, ex, mock(MessageListenerContainer.class), consumer)).isFalse(); |
| 211 | + assertThat(captured.get()).isSameAs(ise); |
| 212 | + IllegalArgumentException iae = new IllegalArgumentException(); |
| 213 | + ex = new ListenerExecutionFailedException("", new TimestampedException( |
| 214 | + new ListenerExecutionFailedException("", iae))); |
| 215 | + assertThat(tracker.recovered(record, ex, mock(MessageListenerContainer.class), consumer)).isTrue(); |
| 216 | + assertThat(captured.get()).isSameAs(iae); |
| 217 | + } |
| 218 | + |
189 | 219 | } |
0 commit comments