11/*
2- * Copyright 2018-2021 the original author or authors.
2+ * Copyright 2018-2022 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2020import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
2121import static org .assertj .core .api .Assertions .assertThatNullPointerException ;
2222
23- import java .math .BigInteger ;
2423import java .time .Clock ;
2524import java .time .Instant ;
2625import java .util .Collections ;
27- import java .util .Map ;
2826
2927import org .junit .jupiter .api .BeforeEach ;
3028import org .junit .jupiter .api .Test ;
3634import org .springframework .context .event .ContextRefreshedEvent ;
3735import org .springframework .kafka .listener .ListenerExecutionFailedException ;
3836import org .springframework .kafka .listener .TimestampedException ;
37+ import org .springframework .kafka .support .converter .ConversionException ;
3938
4039/**
4140 * @author Tomaz Fernandes
4544@ ExtendWith (MockitoExtension .class )
4645class DefaultDestinationTopicResolverTests extends DestinationTopicTests {
4746
48- private Map <String , DefaultDestinationTopicResolver .DestinationTopicHolder > destinationTopicMap ;
49-
5047 @ Mock
5148 private ApplicationContext applicationContext ;
5249
@@ -61,8 +58,6 @@ class DefaultDestinationTopicResolverTests extends DestinationTopicTests {
6158
6259 private final long failureTimestamp = Instant .now (this .clock ).plusMillis (500 ).toEpochMilli ();
6360
64- private final byte [] originalTimestampBytes = BigInteger .valueOf (originalTimestamp ).toByteArray ();
65-
6661 @ BeforeEach
6762 public void setup () {
6863
@@ -77,16 +72,16 @@ public void setup() {
7772 void shouldResolveRetryDestination () {
7873 assertThat (defaultDestinationTopicContainer
7974 .resolveDestinationTopic (mainDestinationTopic .getDestinationName (), 1 ,
80- new IllegalArgumentException (), this .originalTimestamp )).isEqualTo (firstRetryDestinationTopic );
75+ new RuntimeException (), this .originalTimestamp )).isEqualTo (firstRetryDestinationTopic );
8176 assertThat (defaultDestinationTopicContainer
8277 .resolveDestinationTopic (firstRetryDestinationTopic .getDestinationName (), 1 ,
83- new IllegalArgumentException (), this .originalTimestamp )).isEqualTo (secondRetryDestinationTopic );
78+ new RuntimeException (), this .originalTimestamp )).isEqualTo (secondRetryDestinationTopic );
8479 assertThat (defaultDestinationTopicContainer
8580 .resolveDestinationTopic (secondRetryDestinationTopic .getDestinationName (), 1 ,
86- new IllegalArgumentException (), this .originalTimestamp )).isEqualTo (dltDestinationTopic );
81+ new RuntimeException (), this .originalTimestamp )).isEqualTo (dltDestinationTopic );
8782 assertThat (defaultDestinationTopicContainer
8883 .resolveDestinationTopic (dltDestinationTopic .getDestinationName (), 1 ,
89- new IllegalArgumentException (), this .originalTimestamp )).isEqualTo (noOpsDestinationTopic );
84+ new RuntimeException (), this .originalTimestamp )).isEqualTo (noOpsDestinationTopic );
9085
9186 assertThat (defaultDestinationTopicContainer
9287 .resolveDestinationTopic (mainDestinationTopic2 .getDestinationName (), 1 ,
@@ -106,22 +101,38 @@ void shouldResolveRetryDestination() {
106101 void shouldResolveDltDestinationForNonRetryableException () {
107102 assertThat (defaultDestinationTopicContainer
108103 .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 );
110121 }
111122
112123 @ Test
113124 void shouldResolveRetryDestinationForWrappedListenerExecutionFailedException () {
114125 assertThat (defaultDestinationTopicContainer
115126 .resolveDestinationTopic (mainDestinationTopic .getDestinationName (),
116127 1 , new ListenerExecutionFailedException ("Test exception!" ,
117- new IllegalArgumentException ()), originalTimestamp )).isEqualTo (firstRetryDestinationTopic );
128+ new RuntimeException ()), originalTimestamp )).isEqualTo (firstRetryDestinationTopic );
118129 }
119130
120131 @ Test
121132 void shouldResolveRetryDestinationForWrappedTimestampedException () {
122133 assertThat (defaultDestinationTopicContainer
123134 .resolveDestinationTopic (mainDestinationTopic .getDestinationName (),
124- 1 , new TimestampedException (new IllegalArgumentException ()), originalTimestamp ))
135+ 1 , new TimestampedException (new RuntimeException ()), originalTimestamp ))
125136 .isEqualTo (firstRetryDestinationTopic );
126137 }
127138
0 commit comments