|
72 | 72 | import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.PulsarHeadersCustomObjectMapperTest.PulsarHeadersCustomObjectMapperTestConfig;
|
73 | 73 | import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.PulsarHeadersTest.PulsarListenerWithHeadersConfig;
|
74 | 74 | import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.StreamingListenerTestCases.StreamingListenerTestCasesConfig;
|
75 |
| -import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.SubscriptionTypeTests.WithDefaultType.WithDefaultTypeConfig; |
76 |
| -import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.SubscriptionTypeTests.WithSpecificTypes.WithSpecificTypesConfig; |
| 75 | +import org.springframework.pulsar.reactive.listener.ReactivePulsarListenerTests.SubscriptionTypeTests.SubscriptionTypeTestsConfig; |
77 | 76 | import org.springframework.pulsar.reactive.support.MessageUtils;
|
78 | 77 | import org.springframework.pulsar.support.PulsarHeaders;
|
79 | 78 | import org.springframework.pulsar.support.header.JsonPulsarHeaderMapper;
|
@@ -816,117 +815,80 @@ Mono<Void> listen2(String message) {
|
816 | 815 | }
|
817 | 816 |
|
818 | 817 | @Nested
|
| 818 | + @ContextConfiguration(classes = SubscriptionTypeTestsConfig.class) |
819 | 819 | class SubscriptionTypeTests {
|
820 | 820 |
|
821 |
| - @Nested |
822 |
| - @ContextConfiguration(classes = WithDefaultTypeConfig.class) |
823 |
| - class WithDefaultType { |
| 821 | + static final CountDownLatch latchTypeNotSet = new CountDownLatch(1); |
824 | 822 |
|
825 |
| - static final CountDownLatch latchTypeNotSet = new CountDownLatch(1); |
| 823 | + static final CountDownLatch latchTypeSetOnAnnotation = new CountDownLatch(1); |
826 | 824 |
|
827 |
| - @Test |
828 |
| - void whenTypeNotSetAnywhereThenFallbackTypeIsUsed( |
829 |
| - @Autowired ConsumerTrackingReactivePulsarConsumerFactory<String> consumerFactory) throws Exception { |
830 |
| - assertThat(consumerFactory.topicNameToConsumerSpec).hasEntrySatisfying("rpl-typeNotSetAnywhere-topic", |
831 |
| - (consumerSpec) -> assertThat(consumerSpec.getSubscriptionType()) |
832 |
| - .isEqualTo(SubscriptionType.Exclusive)); |
833 |
| - pulsarTemplate.send("rpl-typeNotSetAnywhere-topic", "hello-rpl-typeNotSetAnywhere"); |
834 |
| - assertThat(latchTypeNotSet.await(10, TimeUnit.SECONDS)).isTrue(); |
835 |
| - } |
836 |
| - |
837 |
| - @Configuration(proxyBeanMethods = false) |
838 |
| - static class WithDefaultTypeConfig { |
839 |
| - |
840 |
| - @ReactivePulsarListener(topics = "rpl-typeNotSetAnywhere-topic", |
841 |
| - subscriptionName = "rpl-typeNotSetAnywhere-sub", |
842 |
| - consumerCustomizer = "subscriptionInitialPositionEarliest") |
843 |
| - Mono<Void> listenWithoutTypeSetAnywhere(String ignored) { |
844 |
| - latchTypeNotSet.countDown(); |
845 |
| - return Mono.empty(); |
846 |
| - } |
847 |
| - |
848 |
| - } |
| 825 | + static final CountDownLatch latchTypeSetOnCustomizer = new CountDownLatch(1); |
849 | 826 |
|
| 827 | + @Test |
| 828 | + void defaultTypeFromContainerFactoryUsedWhenTypeNotSetAnywhere( |
| 829 | + @Autowired ConsumerTrackingReactivePulsarConsumerFactory<String> consumerFactory) throws Exception { |
| 830 | + var topic = "rpl-latchTypeNotSet-topic"; |
| 831 | + assertThat(consumerFactory.getSpec(topic)).extracting(ReactiveMessageConsumerSpec::getSubscriptionType) |
| 832 | + .isEqualTo(SubscriptionType.Exclusive); |
| 833 | + pulsarTemplate.send(topic, "hello-" + topic); |
| 834 | + assertThat(latchTypeNotSet.await(5, TimeUnit.SECONDS)).isTrue(); |
850 | 835 | }
|
851 | 836 |
|
852 |
| - @Nested |
853 |
| - @ContextConfiguration(classes = WithSpecificTypesConfig.class) |
854 |
| - class WithSpecificTypes { |
855 |
| - |
856 |
| - static final CountDownLatch latchTypeSetConsumerFactory = new CountDownLatch(1); |
| 837 | + @Test |
| 838 | + void typeSetOnAnnotationOverridesDefaultTypeFromContainerFactory( |
| 839 | + @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); |
| 843 | + pulsarTemplate.send(topic, "hello-" + topic); |
| 844 | + assertThat(latchTypeSetOnAnnotation.await(5, TimeUnit.SECONDS)).isTrue(); |
| 845 | + } |
857 | 846 |
|
858 |
| - static final CountDownLatch latchTypeSetAnnotation = new CountDownLatch(1); |
| 847 | + @Test |
| 848 | + void typeSetOnCustomizerOverridesTypeSetOnAnnotation( |
| 849 | + @Autowired ConsumerTrackingReactivePulsarConsumerFactory<String> consumerFactory) throws Exception { |
| 850 | + var topic = "rpl-typeSetOnCustomizer-topic"; |
| 851 | + assertThat(consumerFactory.getSpec(topic)).extracting(ReactiveMessageConsumerSpec::getSubscriptionType) |
| 852 | + .isEqualTo(SubscriptionType.Failover); |
| 853 | + pulsarTemplate.send(topic, "hello-" + topic); |
| 854 | + assertThat(latchTypeSetOnCustomizer.await(5, TimeUnit.SECONDS)).isTrue(); |
| 855 | + } |
859 | 856 |
|
860 |
| - static final CountDownLatch latchWithCustomizer = new CountDownLatch(1); |
| 857 | + @Configuration(proxyBeanMethods = false) |
| 858 | + static class SubscriptionTypeTestsConfig { |
861 | 859 |
|
862 |
| - @Test |
863 |
| - void whenTypeSetOnlyInConsumerFactoryThenConsumerFactoryTypeIsUsed( |
864 |
| - @Autowired ConsumerTrackingReactivePulsarConsumerFactory<String> consumerFactory) throws Exception { |
865 |
| - assertThat(consumerFactory.getSpec("rpl-typeSetConsumerFactory-topic")) |
866 |
| - .extracting(ReactiveMessageConsumerSpec::getSubscriptionType) |
867 |
| - .isEqualTo(SubscriptionType.Shared); |
868 |
| - pulsarTemplate.send("rpl-typeSetConsumerFactory-topic", "hello-rpl-typeSetConsumerFactory"); |
869 |
| - assertThat(latchTypeSetConsumerFactory.await(10, TimeUnit.SECONDS)).isTrue(); |
| 860 | + @Bean |
| 861 | + ReactiveMessageConsumerBuilderCustomizer<String> consumerFactoryDefaultSubTypeCustomizer() { |
| 862 | + return (b) -> b.subscriptionType(SubscriptionType.Shared); |
870 | 863 | }
|
871 | 864 |
|
872 |
| - @Test |
873 |
| - void whenTypeSetOnAnnotationThenAnnotationTypeIsUsed( |
874 |
| - @Autowired ConsumerTrackingReactivePulsarConsumerFactory<String> consumerFactory) throws Exception { |
875 |
| - assertThat(consumerFactory.getSpec("rpl-typeSetAnnotation-topic")) |
876 |
| - .extracting(ReactiveMessageConsumerSpec::getSubscriptionType) |
877 |
| - .isEqualTo(SubscriptionType.Key_Shared); |
878 |
| - pulsarTemplate.send("rpl-typeSetAnnotation-topic", "hello-rpl-typeSetAnnotation"); |
879 |
| - assertThat(latchTypeSetAnnotation.await(10, TimeUnit.SECONDS)).isTrue(); |
| 865 | + @ReactivePulsarListener(topics = "rpl-latchTypeNotSet-topic", subscriptionName = "rpl-latchTypeNotSet-sub", |
| 866 | + consumerCustomizer = "subscriptionInitialPositionEarliest") |
| 867 | + Mono<Void> listenWithoutTypeSetAnywhere(String ignored) { |
| 868 | + latchTypeNotSet.countDown(); |
| 869 | + return Mono.empty(); |
880 | 870 | }
|
881 | 871 |
|
882 |
| - @Test |
883 |
| - void whenTypeSetWithCustomizerThenCustomizerTypeIsUsed( |
884 |
| - @Autowired ConsumerTrackingReactivePulsarConsumerFactory<String> consumerFactory) throws Exception { |
885 |
| - assertThat(consumerFactory.getSpec("rpl-typeSetCustomizer-topic")) |
886 |
| - .extracting(ReactiveMessageConsumerSpec::getSubscriptionType) |
887 |
| - .isEqualTo(SubscriptionType.Failover); |
888 |
| - pulsarTemplate.send("rpl-typeSetCustomizer-topic", "hello-rpl-typeSetCustomizer"); |
889 |
| - assertThat(latchWithCustomizer.await(10, TimeUnit.SECONDS)).isTrue(); |
| 872 | + @ReactivePulsarListener(topics = "rpl-typeSetOnAnnotation-topic", |
| 873 | + subscriptionName = "rpl-typeSetOnAnnotation-sub", subscriptionType = SubscriptionType.Key_Shared, |
| 874 | + consumerCustomizer = "subscriptionInitialPositionEarliest") |
| 875 | + Mono<Void> listenWithTypeSetOnAnnotation(String ignored) { |
| 876 | + latchTypeSetOnAnnotation.countDown(); |
| 877 | + return Mono.empty(); |
890 | 878 | }
|
891 | 879 |
|
892 |
| - @Configuration(proxyBeanMethods = false) |
893 |
| - static class WithSpecificTypesConfig { |
894 |
| - |
895 |
| - @Bean |
896 |
| - ReactiveMessageConsumerBuilderCustomizer<String> consumerFactoryDefaultSubTypeCustomizer() { |
897 |
| - return (b) -> b.subscriptionType(SubscriptionType.Shared); |
898 |
| - } |
899 |
| - |
900 |
| - @ReactivePulsarListener(topics = "rpl-typeSetConsumerFactory-topic", |
901 |
| - subscriptionName = "rpl-typeSetConsumerFactory-sub", subscriptionType = {}, |
902 |
| - consumerCustomizer = "subscriptionInitialPositionEarliest") |
903 |
| - Mono<Void> listenWithTypeSetOnlyOnConsumerFactory(String ignored) { |
904 |
| - latchTypeSetConsumerFactory.countDown(); |
905 |
| - return Mono.empty(); |
906 |
| - } |
907 |
| - |
908 |
| - @ReactivePulsarListener(topics = "rpl-typeSetAnnotation-topic", |
909 |
| - subscriptionName = "rpl-typeSetAnnotation-sub", subscriptionType = SubscriptionType.Key_Shared, |
910 |
| - consumerCustomizer = "subscriptionInitialPositionEarliest") |
911 |
| - Mono<Void> listenWithTypeSetOnAnnotation(String ignored) { |
912 |
| - latchTypeSetAnnotation.countDown(); |
913 |
| - return Mono.empty(); |
914 |
| - } |
915 |
| - |
916 |
| - @ReactivePulsarListener(topics = "rpl-typeSetCustomizer-topic", |
917 |
| - subscriptionName = "rpl-typeSetCustomizer-sub", subscriptionType = SubscriptionType.Key_Shared, |
918 |
| - consumerCustomizer = "myCustomizer") |
919 |
| - Mono<Void> listenWithTypeSetInCustomizer(String ignored) { |
920 |
| - latchWithCustomizer.countDown(); |
921 |
| - return Mono.empty(); |
922 |
| - } |
923 |
| - |
924 |
| - @Bean |
925 |
| - public ReactivePulsarListenerMessageConsumerBuilderCustomizer<String> myCustomizer() { |
926 |
| - return cb -> cb.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest) |
927 |
| - .subscriptionType(SubscriptionType.Failover); |
928 |
| - } |
| 880 | + @ReactivePulsarListener(topics = "rpl-typeSetOnCustomizer-topic", |
| 881 | + subscriptionName = "rpl-typeSetOnCustomizer-sub", subscriptionType = SubscriptionType.Key_Shared, |
| 882 | + consumerCustomizer = "myCustomizer") |
| 883 | + Mono<Void> listenWithTypeSetOnCustomizer(String ignored) { |
| 884 | + latchTypeSetOnCustomizer.countDown(); |
| 885 | + return Mono.empty(); |
| 886 | + } |
929 | 887 |
|
| 888 | + @Bean |
| 889 | + public ReactivePulsarListenerMessageConsumerBuilderCustomizer<String> myCustomizer() { |
| 890 | + return cb -> cb.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest) |
| 891 | + .subscriptionType(SubscriptionType.Failover); |
930 | 892 | }
|
931 | 893 |
|
932 | 894 | }
|
|
0 commit comments