1
1
/*
2
- * Copyright 2018-2021 the original author or authors.
2
+ * Copyright 2018-2022 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.
20
20
import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
21
21
import static org .assertj .core .api .Assertions .assertThatNullPointerException ;
22
22
23
- import java .math .BigInteger ;
24
23
import java .time .Clock ;
25
24
import java .time .Instant ;
26
25
import java .util .Collections ;
27
- import java .util .Map ;
28
26
29
27
import org .junit .jupiter .api .BeforeEach ;
30
28
import org .junit .jupiter .api .Test ;
36
34
import org .springframework .context .event .ContextRefreshedEvent ;
37
35
import org .springframework .kafka .listener .ListenerExecutionFailedException ;
38
36
import org .springframework .kafka .listener .TimestampedException ;
37
+ import org .springframework .kafka .support .converter .ConversionException ;
39
38
40
39
/**
41
40
* @author Tomaz Fernandes
45
44
@ ExtendWith (MockitoExtension .class )
46
45
class DefaultDestinationTopicResolverTests extends DestinationTopicTests {
47
46
48
- private Map <String , DefaultDestinationTopicResolver .DestinationTopicHolder > destinationTopicMap ;
49
-
50
47
@ Mock
51
48
private ApplicationContext applicationContext ;
52
49
@@ -61,8 +58,6 @@ class DefaultDestinationTopicResolverTests extends DestinationTopicTests {
61
58
62
59
private final long failureTimestamp = Instant .now (this .clock ).plusMillis (500 ).toEpochMilli ();
63
60
64
- private final byte [] originalTimestampBytes = BigInteger .valueOf (originalTimestamp ).toByteArray ();
65
-
66
61
@ BeforeEach
67
62
public void setup () {
68
63
@@ -77,16 +72,16 @@ public void setup() {
77
72
void shouldResolveRetryDestination () {
78
73
assertThat (defaultDestinationTopicContainer
79
74
.resolveDestinationTopic (mainDestinationTopic .getDestinationName (), 1 ,
80
- new IllegalArgumentException (), this .originalTimestamp )).isEqualTo (firstRetryDestinationTopic );
75
+ new RuntimeException (), this .originalTimestamp )).isEqualTo (firstRetryDestinationTopic );
81
76
assertThat (defaultDestinationTopicContainer
82
77
.resolveDestinationTopic (firstRetryDestinationTopic .getDestinationName (), 1 ,
83
- new IllegalArgumentException (), this .originalTimestamp )).isEqualTo (secondRetryDestinationTopic );
78
+ new RuntimeException (), this .originalTimestamp )).isEqualTo (secondRetryDestinationTopic );
84
79
assertThat (defaultDestinationTopicContainer
85
80
.resolveDestinationTopic (secondRetryDestinationTopic .getDestinationName (), 1 ,
86
- new IllegalArgumentException (), this .originalTimestamp )).isEqualTo (dltDestinationTopic );
81
+ new RuntimeException (), this .originalTimestamp )).isEqualTo (dltDestinationTopic );
87
82
assertThat (defaultDestinationTopicContainer
88
83
.resolveDestinationTopic (dltDestinationTopic .getDestinationName (), 1 ,
89
- new IllegalArgumentException (), this .originalTimestamp )).isEqualTo (noOpsDestinationTopic );
84
+ new RuntimeException (), this .originalTimestamp )).isEqualTo (noOpsDestinationTopic );
90
85
91
86
assertThat (defaultDestinationTopicContainer
92
87
.resolveDestinationTopic (mainDestinationTopic2 .getDestinationName (), 1 ,
@@ -106,22 +101,38 @@ void shouldResolveRetryDestination() {
106
101
void shouldResolveDltDestinationForNonRetryableException () {
107
102
assertThat (defaultDestinationTopicContainer
108
103
.resolveDestinationTopic (mainDestinationTopic .getDestinationName (),
109
- 1 , new RuntimeException (), originalTimestamp )).isEqualTo (dltDestinationTopic );
104
+ 1 , new IllegalArgumentException (), originalTimestamp )).isEqualTo (dltDestinationTopic );
105
+ }
106
+
107
+ @ Test
108
+ void shouldResolveDltDestinationForFatalDefaultException () {
109
+ assertThat (defaultDestinationTopicContainer
110
+ .resolveDestinationTopic (mainDestinationTopic .getDestinationName (),
111
+ 1 , new ConversionException ("Test exception" , new RuntimeException ()), originalTimestamp ))
112
+ .isEqualTo (dltDestinationTopic );
113
+ }
114
+
115
+ @ Test
116
+ void shouldResolveNoOpsForFatalDefaultExceptionInDlt () {
117
+ assertThat (defaultDestinationTopicContainer
118
+ .resolveDestinationTopic (dltDestinationTopic .getDestinationName (),
119
+ 1 , new ConversionException ("Test exception" , new RuntimeException ()), originalTimestamp ))
120
+ .isEqualTo (noOpsDestinationTopic );
110
121
}
111
122
112
123
@ Test
113
124
void shouldResolveRetryDestinationForWrappedListenerExecutionFailedException () {
114
125
assertThat (defaultDestinationTopicContainer
115
126
.resolveDestinationTopic (mainDestinationTopic .getDestinationName (),
116
127
1 , new ListenerExecutionFailedException ("Test exception!" ,
117
- new IllegalArgumentException ()), originalTimestamp )).isEqualTo (firstRetryDestinationTopic );
128
+ new RuntimeException ()), originalTimestamp )).isEqualTo (firstRetryDestinationTopic );
118
129
}
119
130
120
131
@ Test
121
132
void shouldResolveRetryDestinationForWrappedTimestampedException () {
122
133
assertThat (defaultDestinationTopicContainer
123
134
.resolveDestinationTopic (mainDestinationTopic .getDestinationName (),
124
- 1 , new TimestampedException (new IllegalArgumentException ()), originalTimestamp ))
135
+ 1 , new TimestampedException (new RuntimeException ()), originalTimestamp ))
125
136
.isEqualTo (firstRetryDestinationTopic );
126
137
}
127
138
0 commit comments