|
44 | 44 | import org.apache.pulsar.reactive.client.api.MessageResult;
|
45 | 45 | import org.apache.pulsar.reactive.client.api.ReactiveMessageConsumer;
|
46 | 46 | import org.apache.pulsar.reactive.client.api.ReactiveMessageConsumerSpec;
|
| 47 | +import org.assertj.core.api.InstanceOfAssertFactories; |
47 | 48 | import org.junit.jupiter.api.Nested;
|
48 | 49 | import org.junit.jupiter.api.Test;
|
49 | 50 |
|
|
72 | 73 | import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.PulsarHeadersCustomObjectMapperTest.PulsarHeadersCustomObjectMapperTestConfig;
|
73 | 74 | import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.PulsarHeadersTest.PulsarListenerWithHeadersConfig;
|
74 | 75 | import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.StreamingListenerTestCases.StreamingListenerTestCasesConfig;
|
75 |
| -import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.SubscriptionTypeTests.SubscriptionTypeTestsConfig; |
| 76 | +import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.SubscriptionNameTests.SubscriptionNameTestsConfig; |
76 | 77 | import org.springframework.pulsar.reactive.support.MessageUtils;
|
77 | 78 | import org.springframework.pulsar.support.PulsarHeaders;
|
78 | 79 | import org.springframework.pulsar.support.header.JsonPulsarHeaderMapper;
|
@@ -815,80 +816,79 @@ Mono<Void> listen2(String message) {
|
815 | 816 | }
|
816 | 817 |
|
817 | 818 | @Nested
|
818 |
| - @ContextConfiguration(classes = SubscriptionTypeTestsConfig.class) |
819 |
| - class SubscriptionTypeTests { |
| 819 | + @ContextConfiguration(classes = SubscriptionNameTestsConfig.class) |
| 820 | + class SubscriptionNameTests { |
820 | 821 |
|
821 |
| - static final CountDownLatch latchTypeNotSet = new CountDownLatch(1); |
| 822 | + static final CountDownLatch latchNameNotSet = new CountDownLatch(1); |
822 | 823 |
|
823 |
| - static final CountDownLatch latchTypeSetOnAnnotation = new CountDownLatch(1); |
| 824 | + static final CountDownLatch latchNameSetOnAnnotation = new CountDownLatch(1); |
824 | 825 |
|
825 |
| - static final CountDownLatch latchTypeSetOnCustomizer = new CountDownLatch(1); |
| 826 | + static final CountDownLatch latchNameSetOnCustomizer = new CountDownLatch(1); |
826 | 827 |
|
827 | 828 | @Test
|
828 |
| - void defaultTypeFromContainerFactoryUsedWhenTypeNotSetAnywhere( |
| 829 | + void defaultNameFromContainerFactoryUsedWhenNameNotSetAnywhere( |
829 | 830 | @Autowired ConsumerTrackingReactivePulsarConsumerFactory<String> consumerFactory) throws Exception {
|
830 |
| - var topic = "rpl-latchTypeNotSet-topic"; |
831 |
| - assertThat(consumerFactory.getSpec(topic)).extracting(ReactiveMessageConsumerSpec::getSubscriptionType) |
832 |
| - .isEqualTo(SubscriptionType.Exclusive); |
| 831 | + var topic = "rpl-latchNameNotSet-topic"; |
| 832 | + assertThat(consumerFactory.getSpec(topic)) |
| 833 | + .extracting(ReactiveMessageConsumerSpec::getSubscriptionName, InstanceOfAssertFactories.STRING) |
| 834 | + .startsWith("org.springframework.Pulsar.ReactivePulsarListenerEndpointContainer#"); |
833 | 835 | pulsarTemplate.send(topic, "hello-" + topic);
|
834 |
| - assertThat(latchTypeNotSet.await(5, TimeUnit.SECONDS)).isTrue(); |
| 836 | + assertThat(latchNameNotSet.await(5, TimeUnit.SECONDS)).isTrue(); |
835 | 837 | }
|
836 | 838 |
|
837 | 839 | @Test
|
838 |
| - void typeSetOnAnnotationOverridesDefaultTypeFromContainerFactory( |
| 840 | + void nameSetOnAnnotationOverridesDefaultNameFromContainerFactory( |
839 | 841 | @Autowired ConsumerTrackingReactivePulsarConsumerFactory<String> consumerFactory) throws Exception {
|
840 |
| - var topic = "rpl-typeSetOnAnnotation-topic"; |
841 |
| - assertThat(consumerFactory.getSpec(topic)).extracting(ReactiveMessageConsumerSpec::getSubscriptionType) |
842 |
| - .isEqualTo(SubscriptionType.Key_Shared); |
| 842 | + var topic = "rpl-nameSetOnAnnotation-topic"; |
| 843 | + assertThat(consumerFactory.getSpec(topic)).extracting(ReactiveMessageConsumerSpec::getSubscriptionName) |
| 844 | + .isEqualTo("from-annotation"); |
843 | 845 | pulsarTemplate.send(topic, "hello-" + topic);
|
844 |
| - assertThat(latchTypeSetOnAnnotation.await(5, TimeUnit.SECONDS)).isTrue(); |
| 846 | + assertThat(latchNameSetOnAnnotation.await(5, TimeUnit.SECONDS)).isTrue(); |
845 | 847 | }
|
846 | 848 |
|
847 | 849 | @Test
|
848 |
| - void typeSetOnCustomizerOverridesTypeSetOnAnnotation( |
| 850 | + void nameSetOnCustomizerOverridesNameSetOnAnnotation( |
849 | 851 | @Autowired ConsumerTrackingReactivePulsarConsumerFactory<String> consumerFactory) throws Exception {
|
850 |
| - var topic = "rpl-typeSetOnCustomizer-topic"; |
851 |
| - assertThat(consumerFactory.getSpec(topic)).extracting(ReactiveMessageConsumerSpec::getSubscriptionType) |
852 |
| - .isEqualTo(SubscriptionType.Failover); |
| 852 | + var topic = "rpl-nameSetOnCustomizer-topic"; |
| 853 | + assertThat(consumerFactory.getSpec(topic)).extracting(ReactiveMessageConsumerSpec::getSubscriptionName) |
| 854 | + .isEqualTo("from-customizer"); |
853 | 855 | pulsarTemplate.send(topic, "hello-" + topic);
|
854 |
| - assertThat(latchTypeSetOnCustomizer.await(5, TimeUnit.SECONDS)).isTrue(); |
| 856 | + assertThat(latchNameSetOnCustomizer.await(5, TimeUnit.SECONDS)).isTrue(); |
855 | 857 | }
|
856 | 858 |
|
857 | 859 | @Configuration(proxyBeanMethods = false)
|
858 |
| - static class SubscriptionTypeTestsConfig { |
| 860 | + static class SubscriptionNameTestsConfig { |
859 | 861 |
|
860 | 862 | @Bean
|
861 |
| - ReactiveMessageConsumerBuilderCustomizer<String> consumerFactoryDefaultSubTypeCustomizer() { |
862 |
| - return (b) -> b.subscriptionType(SubscriptionType.Shared); |
| 863 | + ReactiveMessageConsumerBuilderCustomizer<String> consumerFactoryDefaultSubNameCustomizer() { |
| 864 | + return (b) -> b.subscriptionName("from-consumer-factory"); |
863 | 865 | }
|
864 | 866 |
|
865 |
| - @ReactivePulsarListener(topics = "rpl-latchTypeNotSet-topic", subscriptionName = "rpl-latchTypeNotSet-sub", |
| 867 | + @ReactivePulsarListener(topics = "rpl-latchNameNotSet-topic", |
866 | 868 | consumerCustomizer = "subscriptionInitialPositionEarliest")
|
867 |
| - Mono<Void> listenWithoutTypeSetAnywhere(String ignored) { |
868 |
| - latchTypeNotSet.countDown(); |
| 869 | + Mono<Void> listenWithoutNameSetAnywhere(String ignored) { |
| 870 | + latchNameNotSet.countDown(); |
869 | 871 | return Mono.empty();
|
870 | 872 | }
|
871 | 873 |
|
872 |
| - @ReactivePulsarListener(topics = "rpl-typeSetOnAnnotation-topic", |
873 |
| - subscriptionName = "rpl-typeSetOnAnnotation-sub", subscriptionType = SubscriptionType.Key_Shared, |
| 874 | + @ReactivePulsarListener(topics = "rpl-nameSetOnAnnotation-topic", subscriptionName = "from-annotation", |
874 | 875 | consumerCustomizer = "subscriptionInitialPositionEarliest")
|
875 |
| - Mono<Void> listenWithTypeSetOnAnnotation(String ignored) { |
876 |
| - latchTypeSetOnAnnotation.countDown(); |
| 876 | + Mono<Void> listenWithNameSetOnAnnotation(String ignored) { |
| 877 | + latchNameSetOnAnnotation.countDown(); |
877 | 878 | return Mono.empty();
|
878 | 879 | }
|
879 | 880 |
|
880 |
| - @ReactivePulsarListener(topics = "rpl-typeSetOnCustomizer-topic", |
881 |
| - subscriptionName = "rpl-typeSetOnCustomizer-sub", subscriptionType = SubscriptionType.Key_Shared, |
| 881 | + @ReactivePulsarListener(topics = "rpl-nameSetOnCustomizer-topic", subscriptionName = "from-annotation", |
882 | 882 | consumerCustomizer = "myCustomizer")
|
883 |
| - Mono<Void> listenWithTypeSetOnCustomizer(String ignored) { |
884 |
| - latchTypeSetOnCustomizer.countDown(); |
| 883 | + Mono<Void> listenWithNameSetOnCustomizer(String ignored) { |
| 884 | + latchNameSetOnCustomizer.countDown(); |
885 | 885 | return Mono.empty();
|
886 | 886 | }
|
887 | 887 |
|
888 | 888 | @Bean
|
889 | 889 | public ReactivePulsarListenerMessageConsumerBuilderCustomizer<String> myCustomizer() {
|
890 | 890 | return cb -> cb.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
|
891 |
| - .subscriptionType(SubscriptionType.Failover); |
| 891 | + .subscriptionName("from-customizer"); |
892 | 892 | }
|
893 | 893 |
|
894 | 894 | }
|
|
0 commit comments