Skip to content

Commit 0f07f9a

Browse files
committed
Adjust test to account for new order of subtype precedence
1 parent a46488d commit 0f07f9a

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

spring-pulsar/src/test/java/org/springframework/pulsar/listener/PulsarListenerTests.java

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
import org.springframework.pulsar.core.TopicResolver;
7575
import org.springframework.pulsar.listener.PulsarListenerTests.PulsarHeadersCustomObjectMapperTest.PulsarHeadersCustomObjectMapperTestConfig;
7676
import org.springframework.pulsar.listener.PulsarListenerTests.SubscriptionTypeTests.WithDefaultType.WithDefaultTypeConfig;
77-
import org.springframework.pulsar.listener.PulsarListenerTests.SubscriptionTypeTests.WithSpecificTypes.WithSpecificTypesConfig;
77+
import org.springframework.pulsar.listener.PulsarListenerTests.SubscriptionTypeTests.WithSubscriptionTypes.WithSubscriptionTypesConfig;
7878
import org.springframework.pulsar.support.PulsarHeaders;
7979
import org.springframework.pulsar.support.header.JsonPulsarHeaderMapper;
8080
import org.springframework.pulsar.test.model.UserPojo;
@@ -1089,61 +1089,69 @@ void listenWithoutTypeSetAnywhere(String ignored, Consumer<String> consumer) {
10891089

10901090
}
10911091

1092+
/**
1093+
* Tests the following order of setting the subscription type:
1094+
* <pre>
1095+
* - 1) ConsumerFactory defaultConfigCustomizer
1096+
* - 2) ContainerFactory props.subType (default is Exclusive)
1097+
* - 3) PulsarListener subType attribute
1098+
* - 4) PulsarListener customizer attribute
1099+
* </pre>
1100+
*/
10921101
@Nested
1093-
@ContextConfiguration(classes = WithSpecificTypesConfig.class)
1094-
class WithSpecificTypes {
1102+
@ContextConfiguration(classes = WithSubscriptionTypesConfig.class)
1103+
class WithSubscriptionTypes {
10951104

1096-
static final CountDownLatch latchTypeSetConsumerFactory = new CountDownLatch(1);
1105+
static final CountDownLatch latchTypeSetOnContainerFactory = new CountDownLatch(1);
10971106

1098-
static final CountDownLatch latchTypeSetAnnotation = new CountDownLatch(1);
1107+
static final CountDownLatch latchTypeSetOnAnnotation = new CountDownLatch(1);
10991108

1100-
static final CountDownLatch latchWithCustomizer = new CountDownLatch(1);
1109+
static final CountDownLatch latchTypeSetOnCustomizer = new CountDownLatch(1);
11011110

11021111
@Test
1103-
void whenTypeSetOnlyInConsumerFactoryThenConsumerFactoryTypeIsUsed() throws Exception {
1104-
pulsarTemplate.send("typeSetConsumerFactory-topic", "hello-typeSetConsumerFactory");
1105-
assertThat(latchTypeSetConsumerFactory.await(5, TimeUnit.SECONDS)).isTrue();
1112+
void typeSetOnContainerFactoryUsedWhenNotSetElsewhere() throws Exception {
1113+
pulsarTemplate.send("typeSetOnContainerFactory-topic", "hello-typeSetOnContainerFactory");
1114+
assertThat(latchTypeSetOnContainerFactory.await(5, TimeUnit.SECONDS)).isTrue();
11061115
}
11071116

11081117
@Test
1109-
void whenTypeSetOnAnnotationThenAnnotationTypeIsUsed() throws Exception {
1110-
pulsarTemplate.send("typeSetAnnotation-topic", "hello-typeSetAnnotation");
1111-
assertThat(latchTypeSetAnnotation.await(5, TimeUnit.SECONDS)).isTrue();
1118+
void typeSetOnAnnotationOverridesTypeSetOnContainerFactory() throws Exception {
1119+
pulsarTemplate.send("typeSetOnAnnotation-topic", "hello-typeSetOnAnnotation");
1120+
assertThat(latchTypeSetOnAnnotation.await(5, TimeUnit.SECONDS)).isTrue();
11121121
}
11131122

11141123
@Test
1115-
void whenTypeSetWithCustomizerThenCustomizerTypeIsUsed() throws Exception {
1116-
pulsarTemplate.send("typeSetCustomizer-topic", "hello-typeSetCustomizer");
1117-
assertThat(latchWithCustomizer.await(5, TimeUnit.SECONDS)).isTrue();
1124+
void typeSetOnCustomizerOverridesTypeSetOnAnnotation() throws Exception {
1125+
pulsarTemplate.send("typeSetOnCustomizer-topic", "hello-typeSetOnCustomizer");
1126+
assertThat(latchTypeSetOnCustomizer.await(5, TimeUnit.SECONDS)).isTrue();
11181127
}
11191128

11201129
@Configuration(proxyBeanMethods = false)
1121-
static class WithSpecificTypesConfig {
1130+
static class WithSubscriptionTypesConfig {
11221131

11231132
@Bean
1124-
ConsumerBuilderCustomizer<String> consumerFactoryDefaultSubTypeCustomizer() {
1133+
ConsumerBuilderCustomizer<String> consumerFactoryCustomizerSubTypeIsIgnored() {
11251134
return (b) -> b.subscriptionType(SubscriptionType.Shared);
11261135
}
11271136

1128-
@PulsarListener(topics = "typeSetConsumerFactory-topic",
1129-
subscriptionName = "typeSetConsumerFactory-sub", subscriptionType = {})
1130-
void listenWithTypeSetOnlyOnConsumerFactory(String ignored, Consumer<String> consumer) {
1131-
assertSubscriptionType(consumer).isEqualTo(SubscriptionType.Shared);
1132-
latchTypeSetConsumerFactory.countDown();
1137+
@PulsarListener(topics = "typeSetOnContainerFactory-topic", subscriptionName = "typeSetOnContainerFactory-sub")
1138+
void listenWithTypeSetOnlyOnContainerFactory(String ignored, Consumer<String> consumer) {
1139+
assertSubscriptionType(consumer).isEqualTo(SubscriptionType.Exclusive);
1140+
latchTypeSetOnContainerFactory.countDown();
11331141
}
11341142

1135-
@PulsarListener(topics = "typeSetAnnotation-topic", subscriptionName = "typeSetAnnotation-sub",
1143+
@PulsarListener(topics = "typeSetOnAnnotation-topic", subscriptionName = "typeSetOnAnnotation-sub",
11361144
subscriptionType = SubscriptionType.Key_Shared)
11371145
void listenWithTypeSetOnAnnotation(String ignored, Consumer<String> consumer) {
11381146
assertSubscriptionType(consumer).isEqualTo(SubscriptionType.Key_Shared);
1139-
latchTypeSetAnnotation.countDown();
1147+
latchTypeSetOnAnnotation.countDown();
11401148
}
11411149

1142-
@PulsarListener(topics = "typeSetCustomizer-topic", subscriptionName = "typeSetCustomizer-sub",
1150+
@PulsarListener(topics = "typeSetOnCustomizer-topic", subscriptionName = "typeSetOnCustomizer-sub",
11431151
subscriptionType = SubscriptionType.Key_Shared, consumerCustomizer = "myCustomizer")
1144-
void listenWithTypeSetInCustomizer(String ignored, Consumer<String> consumer) {
1152+
void listenWithTypeSetOnCustomizer(String ignored, Consumer<String> consumer) {
11451153
assertSubscriptionType(consumer).isEqualTo(SubscriptionType.Failover);
1146-
latchWithCustomizer.countDown();
1154+
latchTypeSetOnCustomizer.countDown();
11471155
}
11481156

11491157
@Bean

0 commit comments

Comments
 (0)