Skip to content

Commit 83711f8

Browse files
echo304sangboak.lee
andauthored
GH-2377: Add DestinationTopic.Properties#isRetryTopic() (#2589)
* GH-2377: Feature Request: Provide DestinationTopic.Properties#isRetryTopic() method Resolve #2377 `DestinationTopic.Properties` has `isDltTopic()` and `isMainEndpoint()` but not for retry topic. It adds `isRetryTopic()` method and adds tests to verify the correct behavior. * Add `isRetryTopic()` instance method to `DestinationTopic.Properties` * GH-2377: Provide DestinationTopic.Properties#isRetryTopic() method Resolve #2377 `DestinationTopic.Properties` has `isDltTopic()` and `isMainEndpoint()` but not for retry topic. It adds `isRetryTopic()` method and adds tests to verify the correct behavior. * Add `isRetryTopic()` instance method to `DestinationTopic.Properties` * Fix to align with code style --------- Co-authored-by: sangboak.lee <[email protected]>
1 parent 30f334f commit 83711f8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

spring-kafka/src/main/java/org/springframework/kafka/retrytopic/DestinationTopic.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2022 the original author or authors.
2+
* Copyright 2018-2023 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.
@@ -212,6 +212,10 @@ public boolean isDltTopic() {
212212
return Type.DLT.equals(this.type);
213213
}
214214

215+
public boolean isRetryTopic() {
216+
return Type.RETRY.equals(this.type) || Type.SINGLE_TOPIC_RETRY.equals(this.type);
217+
}
218+
215219
public String suffix() {
216220
return this.suffix;
217221
}

spring-kafka/src/test/java/org/springframework/kafka/retrytopic/DestinationTopicPropertiesFactoryTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2021 the original author or authors.
2+
* Copyright 2018-2023 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.
@@ -96,6 +96,7 @@ void shouldCreateMainAndDltProperties() {
9696
DestinationTopic.Properties mainTopicProperties = propertiesList.get(0);
9797
assertThat(mainTopicProperties.suffix()).isEqualTo("");
9898
assertThat(mainTopicProperties.isDltTopic()).isFalse();
99+
assertThat(mainTopicProperties.isRetryTopic()).isFalse();
99100
DestinationTopic mainTopic = new DestinationTopic("mainTopic", mainTopicProperties);
100101
assertThat(mainTopic.getDestinationDelay()).isEqualTo(0L);
101102
assertThat(mainTopic.shouldRetryOn(0, new IllegalArgumentException())).isTrue();
@@ -110,6 +111,7 @@ void shouldCreateMainAndDltProperties() {
110111
private void assertDltTopic(DestinationTopic.Properties dltProperties) {
111112
assertThat(dltProperties.suffix()).isEqualTo(dltSuffix);
112113
assertThat(dltProperties.isDltTopic()).isTrue();
114+
assertThat(dltProperties.isRetryTopic()).isFalse();
113115
DestinationTopic dltTopic = new DestinationTopic("mainTopic", dltProperties);
114116
assertThat(dltTopic.getDestinationDelay()).isEqualTo(0);
115117
assertThat(dltTopic.shouldRetryOn(0, new IllegalArgumentException())).isFalse();
@@ -144,6 +146,7 @@ void shouldCreateTwoRetryPropertiesForMultipleBackoffValues() {
144146
DestinationTopic.Properties firstRetryProperties = propertiesList.get(1);
145147
assertThat(firstRetryProperties.suffix()).isEqualTo(retryTopicSuffix + "-1000");
146148
assertThat(firstRetryProperties.isDltTopic()).isFalse();
149+
assertThat(firstRetryProperties.isRetryTopic()).isTrue();
147150
DestinationTopic firstRetryDestinationTopic = destinationTopicList.get(1);
148151
assertThat(firstRetryDestinationTopic.getDestinationDelay()).isEqualTo(1000);
149152
assertThat(firstRetryDestinationTopic.getDestinationPartitions()).isEqualTo(numPartitions);
@@ -154,6 +157,7 @@ void shouldCreateTwoRetryPropertiesForMultipleBackoffValues() {
154157
DestinationTopic.Properties secondRetryProperties = propertiesList.get(2);
155158
assertThat(secondRetryProperties.suffix()).isEqualTo(retryTopicSuffix + "-2000");
156159
assertThat(secondRetryProperties.isDltTopic()).isFalse();
160+
assertThat(secondRetryProperties.isRetryTopic()).isTrue();
157161
DestinationTopic secondRetryDestinationTopic = destinationTopicList.get(2);
158162
assertThat(secondRetryDestinationTopic.getDestinationDelay()).isEqualTo(2000);
159163
assertThat(secondRetryDestinationTopic.getDestinationPartitions()).isEqualTo(numPartitions);
@@ -219,6 +223,7 @@ void shouldCreateOneRetryPropertyForFixedBackoffWithSingleTopicStrategy() {
219223

220224
DestinationTopic.Properties firstRetryProperties = propertiesList.get(1);
221225
assertThat(firstRetryProperties.suffix()).isEqualTo(retryTopicSuffix);
226+
assertThat(firstRetryProperties.isRetryTopic()).isTrue();
222227
DestinationTopic retryDestinationTopic = destinationTopicList.get(1);
223228
assertThat(retryDestinationTopic.isSingleTopicRetry()).isTrue();
224229
assertThat(retryDestinationTopic.getDestinationDelay()).isEqualTo(1000);
@@ -261,6 +266,7 @@ void shouldCreateRetryPropertiesForFixedBackoffWithMultiTopicStrategy() {
261266

262267
DestinationTopic.Properties firstRetryProperties = propertiesList.get(1);
263268
assertThat(firstRetryProperties.suffix()).isEqualTo(retryTopicSuffix + "-0");
269+
assertThat(firstRetryProperties.isRetryTopic()).isTrue();
264270
DestinationTopic retryDestinationTopic = destinationTopicList.get(1);
265271
assertThat(retryDestinationTopic.isSingleTopicRetry()).isFalse();
266272
assertThat(retryDestinationTopic.getDestinationDelay()).isEqualTo(5000);

0 commit comments

Comments
 (0)