diff --git a/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc b/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc index 20c7d651..3e6c62c8 100644 --- a/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc +++ b/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc @@ -1,5 +1,26 @@ = What's new? +[[what-s-new-in-2-0-since-1-2]] +== What's New in 2.0 Since 1.2 +:page-section-summary-toc: 1 + +This section covers the changes made from version 1.2 to version 2.0. + +=== Removals +The following previously deprecated APIs, which were marked for removal in version 2.0.x, have now been removed: + +- `org.springframework.pulsar.config.ConcurrentPulsarListenerContainerFactory#setConcurrency` +- `org.springframework.pulsar.config.ConcurrentPulsarListenerContainerFactoryCustomizer` +- `org.springframework.pulsar.config.ListenerContainerFactory#createListenerContainer` +- `org.springframework.pulsar.config.ReaderContainerFactory#createReaderContainer` +- `org.springframework.pulsar.config.ProducerBuilderConfigurationUtil` +- `org.springframework.pulsar.config.PulsarClientProxy#getPartitionsForTopic` +- `org.springframework.pulsar.config.PulsarTopic#builder` +- `org.springframework.pulsar.config.PulsarTopic#getFullyQualifiedTopicName` +- `org.springframework.pulsar.config.Resolved#get` +- `org.springframework.pulsar.test.support.model.UserPojo` +- `org.springframework.pulsar.test.support.model.UserRecord` + [[what-s-new-in-1-2-since-1-1]] == What's New in 1.2 Since 1.1 :page-section-summary-toc: 1 diff --git a/spring-pulsar-reactive/src/test/java/org/springframework/pulsar/reactive/config/DefaultReactivePulsarListenerContainerFactoryTests.java b/spring-pulsar-reactive/src/test/java/org/springframework/pulsar/reactive/config/DefaultReactivePulsarListenerContainerFactoryTests.java index e91f982b..a1c4214d 100644 --- a/spring-pulsar-reactive/src/test/java/org/springframework/pulsar/reactive/config/DefaultReactivePulsarListenerContainerFactoryTests.java +++ b/spring-pulsar-reactive/src/test/java/org/springframework/pulsar/reactive/config/DefaultReactivePulsarListenerContainerFactoryTests.java @@ -18,8 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.apache.pulsar.client.api.SubscriptionType; @@ -34,18 +32,6 @@ */ class DefaultReactivePulsarListenerContainerFactoryTests { - @SuppressWarnings({ "removal", "unchecked" }) - @Test - void deprecatedCreateListenerContainerCallsReplacementApi() { - var containerFactory = spy(new DefaultReactivePulsarListenerContainerFactory( - mock(ReactivePulsarConsumerFactory.class), new ReactivePulsarContainerProperties<>())); - var endpoint = mock(ReactivePulsarListenerEndpoint.class); - when(endpoint.getConcurrency()).thenReturn(1); - var createdContainer = containerFactory.createListenerContainer(endpoint); - assertThat(createdContainer).isNotNull(); - verify(containerFactory).createRegisteredContainer(endpoint); - } - @SuppressWarnings("unchecked") @Nested class SubscriptionTypeFrom { diff --git a/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/model/UserPojo.java b/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/model/UserPojo.java deleted file mode 100644 index ca39c355..00000000 --- a/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/model/UserPojo.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2022-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.pulsar.test.support.model; - -import java.util.Objects; - -/** - * Test object (user) defined via standard Java beans get/set methods. - *

- * WARN Do not convert this to a Record as this is used for Avro tests and Avro - * does not work well w/ records yet. - * - * @deprecated this class is replaced with Gradle test fixtures and is only meant to be - * used internally. - */ -@SuppressWarnings("NullAway") -@Deprecated(since = "1.2.0", forRemoval = true) -public class UserPojo { - - private String name; - - private int age; - - UserPojo() { - } - - public UserPojo(String name, int age) { - this.name = name; - this.age = age; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - UserPojo user = (UserPojo) o; - return age == user.age && Objects.equals(name, user.name); - } - - @Override - public int hashCode() { - return Objects.hash(name, age); - } - - @Override - public String toString() { - return "User{" + "name='" + name + '\'' + ", age=" + age + '}'; - } - -} diff --git a/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/model/UserRecord.java b/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/model/UserRecord.java deleted file mode 100644 index 2cfbe1fd..00000000 --- a/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/model/UserRecord.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2022-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.pulsar.test.support.model; - -/** - * Test object (user) defined via a Java record. - * - * @param name the user's name - * @param age the user's age - * @deprecated this class is replaced with Gradle test fixtures and is only meant to be - * used internally. - */ -@Deprecated(since = "1.2.0", forRemoval = true) -public record UserRecord(String name, int age) { -} diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/annotation/ConcurrentPulsarListenerContainerFactoryBeanCustomizerPostProcessor.java b/spring-pulsar/src/main/java/org/springframework/pulsar/annotation/ConcurrentPulsarListenerContainerFactoryBeanCustomizerPostProcessor.java deleted file mode 100644 index 379b9fa5..00000000 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/annotation/ConcurrentPulsarListenerContainerFactoryBeanCustomizerPostProcessor.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2023-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.pulsar.annotation; - -import static java.util.Objects.requireNonNull; - -import org.jspecify.annotations.Nullable; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.core.log.LogAccessor; -import org.springframework.pulsar.config.ConcurrentPulsarListenerContainerFactory; -import org.springframework.pulsar.config.ConcurrentPulsarListenerContainerFactoryCustomizer; -import org.springframework.util.CollectionUtils; - -/** - * Applies a {@link ConcurrentPulsarListenerContainerFactoryCustomizer} to all - * {@link ConcurrentPulsarListenerContainerFactory} beans. - *

- * There must be only one customizer in the application context in order for it to be - * applied. - * - * @author Chris Bono - */ -@SuppressWarnings("removal") -class ConcurrentPulsarListenerContainerFactoryBeanCustomizerPostProcessor - implements BeanPostProcessor, ApplicationContextAware { - - private final LogAccessor logger = new LogAccessor(getClass()); - - private @Nullable ApplicationContext applicationContext; - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.applicationContext = applicationContext; - } - - @SuppressWarnings("unchecked") - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof ConcurrentPulsarListenerContainerFactory containerFactory) { - var customizers = requireNonNull(this.applicationContext, "applicationContext must not be null") - .getBeansOfType(ConcurrentPulsarListenerContainerFactoryCustomizer.class); - if (CollectionUtils.isEmpty(customizers)) { - return bean; - } - if (customizers.size() > 1) { - this.logger.warn("Found multiple %s beans [%s] - must be only 1 in order to apply".formatted( - ConcurrentPulsarListenerContainerFactoryCustomizer.class.getSimpleName(), - customizers.keySet())); - } - else { - customizers.values().forEach((c) -> c.customize(containerFactory)); - } - } - return bean; - } - -} diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/annotation/PulsarBootstrapConfiguration.java b/spring-pulsar/src/main/java/org/springframework/pulsar/annotation/PulsarBootstrapConfiguration.java index bc37900f..079bdbab 100644 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/annotation/PulsarBootstrapConfiguration.java +++ b/spring-pulsar/src/main/java/org/springframework/pulsar/annotation/PulsarBootstrapConfiguration.java @@ -49,11 +49,6 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B new RootBeanDefinition(PulsarTemplateBeanCustomizerPostProcessor.class)); } - if (!registry.containsBeanDefinition("concurrentContainerFactoryCustomizerPostProcessor")) { - registry.registerBeanDefinition("concurrentContainerFactoryCustomizerPostProcessor", - new RootBeanDefinition(ConcurrentPulsarListenerContainerFactoryBeanCustomizerPostProcessor.class)); - } - if (!registry .containsBeanDefinition(PulsarAnnotationSupportBeanNames.PULSAR_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)) { registry.registerBeanDefinition( diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactory.java b/spring-pulsar/src/main/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactory.java index 4388b94d..88c7830c 100644 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactory.java +++ b/spring-pulsar/src/main/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactory.java @@ -51,17 +51,6 @@ public ConcurrentPulsarListenerContainerFactory(PulsarConsumerFactory super(consumerFactory, containerProperties); } - /** - * Specify the container concurrency. - * @param concurrency the number of consumers to create. - * @deprecated since 1.2.0 for removal in 2.0.0 in favor of - * {@link PulsarContainerProperties#setConcurrency} - */ - @Deprecated(since = "1.2.0", forRemoval = true) - public void setConcurrency(Integer concurrency) { - getContainerProperties().setConcurrency(concurrency); - } - @Override public ConcurrentPulsarMessageListenerContainer createContainer(String... topics) { PulsarListenerEndpoint endpoint = new PulsarListenerEndpoint() { diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactoryCustomizer.java b/spring-pulsar/src/main/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactoryCustomizer.java deleted file mode 100644 index 2d92a32e..00000000 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactoryCustomizer.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2022-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.pulsar.config; - -/** - * Callback interface that can be implemented to customize a - * {@link ConcurrentPulsarListenerContainerFactory}. - * - * @param The message payload type - * @author Chris Bono - * @deprecated since 1.2.0 for removal in 1.4.0 in favor of - * {@code org.springframework.boot.pulsar.autoconfigure.PulsarContainerFactoryCustomizer>} - */ -@FunctionalInterface -@Deprecated(since = "1.2.0", forRemoval = true) -public interface ConcurrentPulsarListenerContainerFactoryCustomizer { - - /** - * Customize a {@link ConcurrentPulsarListenerContainerFactory}. - * @param containerFactory the factory to customize - */ - void customize(ConcurrentPulsarListenerContainerFactory containerFactory); - -} diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/config/ListenerContainerFactory.java b/spring-pulsar/src/main/java/org/springframework/pulsar/config/ListenerContainerFactory.java index 136b500b..5e1f55b1 100644 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/config/ListenerContainerFactory.java +++ b/spring-pulsar/src/main/java/org/springframework/pulsar/config/ListenerContainerFactory.java @@ -30,17 +30,4 @@ public interface ListenerContainerFactory> extends PulsarContainerFactory { - /** - * Create a {@link MessageListenerContainer} for the given {@link ListenerEndpoint}. - * Containers created using this method are added to the listener endpoint registry. - * @param endpoint the endpoint to configure - * @return the created container - * @deprecated since 1.2.0 for removal in 1.4.0 in favor of - * {@link PulsarContainerFactory#createRegisteredContainer} - */ - @Deprecated(since = "1.2.0", forRemoval = true) - default C createListenerContainer(E endpoint) { - return createRegisteredContainer(endpoint); - } - } diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/config/ReaderContainerFactory.java b/spring-pulsar/src/main/java/org/springframework/pulsar/config/ReaderContainerFactory.java index 01d6c34d..beebdebc 100644 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/config/ReaderContainerFactory.java +++ b/spring-pulsar/src/main/java/org/springframework/pulsar/config/ReaderContainerFactory.java @@ -29,29 +29,4 @@ public interface ReaderContainerFactory> extends PulsarContainerFactory { - /** - * Create a message reader container for the given endpoint and register the container - * with the listener endpoint registry. - * @param endpoint reader endpoint - * @return the created container - * @deprecated since 1.2.0 for removal in 1.4.0 in favor of - * {@link PulsarContainerFactory#createRegisteredContainer} - */ - @Deprecated(since = "1.2.0", forRemoval = true) - default C createReaderContainer(E endpoint) { - return createRegisteredContainer(endpoint); - } - - /** - * Create a message reader container for the given endpoint. - * @param topics the topics to read from - * @return the created container - * @deprecated since 1.2.0 for removal in 1.4.0 in favor of - * {@link PulsarContainerFactory#createContainer} - */ - @Deprecated(since = "1.2.0", forRemoval = true) - default C createReaderContainer(String... topics) { - return createContainer(topics); - } - } diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/core/ProducerBuilderConfigurationUtil.java b/spring-pulsar/src/main/java/org/springframework/pulsar/core/ProducerBuilderConfigurationUtil.java deleted file mode 100644 index 58742463..00000000 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/core/ProducerBuilderConfigurationUtil.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2022-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.pulsar.core; - -import java.util.Collection; -import java.util.Map; - -import org.apache.pulsar.client.api.BatcherBuilder; -import org.apache.pulsar.client.api.CryptoKeyReader; -import org.apache.pulsar.client.api.MessageRouter; -import org.apache.pulsar.client.api.ProducerBuilder; - -/** - * Utility methods to help load configuration into a {@link ProducerBuilder}. - *

- * The main purpose is to work around the underlying - * Pulsar issue where - * {@link ProducerBuilder#loadConf} sets {@code @JsonIgnore} fields to null. - *

- * Should be removed once the above issue is fixed. - * - * @author Chris Bono - * @deprecated since 1.1.0 for removal in 1.2.0 - */ -@Deprecated(since = "1.1.0", forRemoval = true) -public final class ProducerBuilderConfigurationUtil { - - private ProducerBuilderConfigurationUtil() { - } - - /** - * Configures the specified properties onto the specified builder in a manner that - * loads non-serializable properties. See - * Pulsar PR. - * @param builder the builder - * @param properties the properties to set on the builder - * @param the payload type - */ - public static void loadConf(ProducerBuilder builder, Map properties) { - - builder.loadConf(properties); - - // Set fields that are not loaded by loadConf - if (properties.containsKey("encryptionKeys")) { - @SuppressWarnings("unchecked") - Collection keys = (Collection) properties.get("encryptionKeys"); - keys.forEach(builder::addEncryptionKey); - } - if (properties.containsKey("customMessageRouter")) { - builder.messageRouter((MessageRouter) properties.get("customMessageRouter")); - } - if (properties.containsKey("batcherBuilder")) { - builder.batcherBuilder((BatcherBuilder) properties.get("batcherBuilder")); - } - if (properties.containsKey("cryptoKeyReader")) { - builder.cryptoKeyReader((CryptoKeyReader) properties.get("cryptoKeyReader")); - } - } - -} diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/core/PulsarClientProxy.java b/spring-pulsar/src/main/java/org/springframework/pulsar/core/PulsarClientProxy.java index 21610ea1..41eba312 100644 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/core/PulsarClientProxy.java +++ b/spring-pulsar/src/main/java/org/springframework/pulsar/core/PulsarClientProxy.java @@ -170,19 +170,6 @@ public void updateServiceUrl(String serviceUrl) throws PulsarClientException { this.getRequiredInstance().updateServiceUrl(serviceUrl); } - /** - * Get the list of partitions for a given topic. - * @param topic the topic name - * @return a future that will yield a list of the topic partitions - * @deprecated in favor of {@link #getPartitionsForTopic(String, boolean)} - * @see PulsarClient#getPartitionsForTopic(String) - */ - @Override - @Deprecated(since = "1.2.0", forRemoval = true) - public CompletableFuture> getPartitionsForTopic(String topic) { - return this.getRequiredInstance().getPartitionsForTopic(topic); - } - @Override public CompletableFuture> getPartitionsForTopic(String topic, boolean metadataAutoCreationEnabled) { return this.getRequiredInstance().getPartitionsForTopic(topic, metadataAutoCreationEnabled); diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/core/PulsarTopic.java b/spring-pulsar/src/main/java/org/springframework/pulsar/core/PulsarTopic.java index 70cf2d4d..cb300551 100644 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/core/PulsarTopic.java +++ b/spring-pulsar/src/main/java/org/springframework/pulsar/core/PulsarTopic.java @@ -57,19 +57,6 @@ public record PulsarTopic(String topicName, int numberOfPartitions) { Assert.state(numberOfPartitions >= 0, "numberOfPartitions must be >= 0"); } - /** - * Convenience method to create a topic builder with the specified topic name. - * @param topicName the name of the topic - * @return the topic builder instance - * @deprecated since 1.2.0 for removal in 1.4.0 in favor of - * {@link PulsarTopicBuilder#PulsarTopicBuilder()} or - * {@link PulsarTopicBuilder#PulsarTopicBuilder(TopicDomain, String, String)} - */ - @Deprecated(since = "1.2.0", forRemoval = true) - public static PulsarTopicBuilder builder(String topicName) { - return new PulsarTopicBuilder().name(topicName); - } - /** * Checks if the topic is partitioned. * @return true if the topic is partitioned @@ -88,24 +75,6 @@ public TopicComponents getComponents() { return new TopicComponents(TopicDomain.getEnum(type), splitTopic[2], splitTopic[3], splitTopic[4]); } - /** - * Get the fully-qualified name of this topic in the format - * {@code domain://tenant/namespace/name} where the components have the following - * defaults when not specified in the original topic name used to build this topic. - *

-	 * - {@code domain} is one of ('persistent', 'non-persistent') with a default of 'persistent'
-	 * - {@code tenant} has default of 'public'
-	 * - {@code namespace} has default of 'default'
-	 * 
- * @return the fully-qualified topic name - * @deprecated As of version 1.2.0 topicName must always be fully qualified, use - * {@link #topicName()} instead. - */ - @Deprecated(since = "1.2.0", forRemoval = true) - public String getFullyQualifiedTopicName() { - return this.topicName(); - } - /** * Model class for the individual identifying components of a Pulsar topic. * diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/core/Resolved.java b/spring-pulsar/src/main/java/org/springframework/pulsar/core/Resolved.java index 4c223a93..9fd7debb 100644 --- a/spring-pulsar/src/main/java/org/springframework/pulsar/core/Resolved.java +++ b/spring-pulsar/src/main/java/org/springframework/pulsar/core/Resolved.java @@ -74,16 +74,6 @@ public static Resolved failed(RuntimeException reason) { return new Resolved<>(null, reason); } - /** - * Gets the optional resolved value. - * @return an optional with the resolved value or empty if failed to resolve - * @deprecated Use {@link #value()} instead - */ - @Deprecated(since = "1.1.0", forRemoval = true) - public Optional get() { - return value(); - } - /** * Gets the resolved value. * @return an optional with the resolved value or empty if failed to resolve diff --git a/spring-pulsar/src/test/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactoryTests.java b/spring-pulsar/src/test/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactoryTests.java index 89c5a772..436290cd 100644 --- a/spring-pulsar/src/test/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactoryTests.java +++ b/spring-pulsar/src/test/java/org/springframework/pulsar/config/ConcurrentPulsarListenerContainerFactoryTests.java @@ -18,8 +18,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.apache.pulsar.client.api.SubscriptionType; @@ -35,18 +33,6 @@ */ class ConcurrentPulsarListenerContainerFactoryTests { - @SuppressWarnings({ "removal", "unchecked" }) - @Test - void deprecatedCreateListenerContainerCallsReplacementApi() { - var containerFactory = spy(new ConcurrentPulsarListenerContainerFactory( - mock(PulsarConsumerFactory.class), new PulsarContainerProperties())); - var endpoint = mock(PulsarListenerEndpoint.class); - when(endpoint.getConcurrency()).thenReturn(1); - var createdContainer = containerFactory.createListenerContainer(endpoint); - assertThat(createdContainer).isNotNull(); - verify(containerFactory).createRegisteredContainer(endpoint); - } - @SuppressWarnings("unchecked") @Nested class SubscriptionTypeFrom { diff --git a/spring-pulsar/src/test/java/org/springframework/pulsar/config/DefaultPulsarReaderContainerFactoryTests.java b/spring-pulsar/src/test/java/org/springframework/pulsar/config/DefaultPulsarReaderContainerFactoryTests.java index dabc6d3f..12666350 100644 --- a/spring-pulsar/src/test/java/org/springframework/pulsar/config/DefaultPulsarReaderContainerFactoryTests.java +++ b/spring-pulsar/src/test/java/org/springframework/pulsar/config/DefaultPulsarReaderContainerFactoryTests.java @@ -16,41 +16,9 @@ package org.springframework.pulsar.config; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; - -import org.junit.jupiter.api.Test; - -import org.springframework.pulsar.core.PulsarReaderFactory; -import org.springframework.pulsar.reader.PulsarReaderContainerProperties; - /** * Unit tests for {@link DefaultPulsarReaderContainerFactory}. */ class DefaultPulsarReaderContainerFactoryTests { - @SuppressWarnings({ "removal", "unchecked" }) - @Test - void deprecatedCreateReaderContainerWithEndpointCallsReplacementApi() { - var containerFactory = spy(new DefaultPulsarReaderContainerFactory<>(mock(PulsarReaderFactory.class), - new PulsarReaderContainerProperties())); - var endpoint = mock(PulsarReaderEndpoint.class); - var createdContainer = containerFactory.createReaderContainer(endpoint); - assertThat(createdContainer).isNotNull(); - verify(containerFactory).createRegisteredContainer(endpoint); - } - - @SuppressWarnings({ "removal", "unchecked" }) - @Test - void deprecatedCreateReaderContainerWithTopicsCallsReplacementApi() { - var containerFactory = spy(new DefaultPulsarReaderContainerFactory<>(mock(PulsarReaderFactory.class), - new PulsarReaderContainerProperties())); - var createdContainer = containerFactory.createReaderContainer("my-topic"); - // reader does not implement this API - still ensure the replacement API is called - assertThat(createdContainer).isNull(); - verify(containerFactory).createContainer("my-topic"); - } - } diff --git a/spring-pulsar/src/test/java/org/springframework/pulsar/core/PulsarClientProxyTests.java b/spring-pulsar/src/test/java/org/springframework/pulsar/core/PulsarClientProxyTests.java index 0d674d77..7a489de5 100644 --- a/spring-pulsar/src/test/java/org/springframework/pulsar/core/PulsarClientProxyTests.java +++ b/spring-pulsar/src/test/java/org/springframework/pulsar/core/PulsarClientProxyTests.java @@ -169,13 +169,6 @@ void getPartitionsForTopic() { verify(this.delegateClient).getPartitionsForTopic("zTopic", true); } - @Test - @SuppressWarnings({ "deprecation", "removal" }) - void getPartitionsForTopicDeprecated() { - this.restartableClient.getPartitionsForTopic("zTopic"); - verify(this.delegateClient).getPartitionsForTopic("zTopic"); - } - @Test void close() throws PulsarClientException { this.restartableClient.close(); diff --git a/spring-pulsar/src/test/java/org/springframework/pulsar/core/PulsarTopicTests.java b/spring-pulsar/src/test/java/org/springframework/pulsar/core/PulsarTopicTests.java index dedbcec2..389b554c 100644 --- a/spring-pulsar/src/test/java/org/springframework/pulsar/core/PulsarTopicTests.java +++ b/spring-pulsar/src/test/java/org/springframework/pulsar/core/PulsarTopicTests.java @@ -94,18 +94,4 @@ void getComponentsReturnsProperComponents() { assertThat(components.name()).isEqualTo("my-topic"); } - @Test - @SuppressWarnings({ "deprecation", "removal" }) - void deprecatedBuilderMethodReturnsValidBuilder() { - var fullyQualifiedName = "persistent://public/default/my-topic"; - assertThat(PulsarTopic.builder("my-topic").build().topicName()).isEqualTo(fullyQualifiedName); - } - - @Test - @SuppressWarnings({ "deprecation", "removal" }) - void deprecatedGetFullyQualifiedTopicNameReturnsValidName() { - var topic = new PulsarTopic(FULLY_QUALIFIED_TOPIC, 0); - assertThat(topic.getFullyQualifiedTopicName()).isEqualTo(FULLY_QUALIFIED_TOPIC); - } - } diff --git a/spring-pulsar/src/test/java/org/springframework/pulsar/core/ResolvedTests.java b/spring-pulsar/src/test/java/org/springframework/pulsar/core/ResolvedTests.java index de0f430f..ef7312f4 100644 --- a/spring-pulsar/src/test/java/org/springframework/pulsar/core/ResolvedTests.java +++ b/spring-pulsar/src/test/java/org/springframework/pulsar/core/ResolvedTests.java @@ -28,7 +28,6 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; /** * Unit tests for {@link Resolved}. @@ -37,14 +36,6 @@ */ class ResolvedTests { - @SuppressWarnings("removal") - @Test - void deprecatedGetDelegatesToNewValueMethod() { - Resolved resolved = Mockito.spy(Resolved.of("hello")); - resolved.get(); - verify(resolved).value(); - } - @SuppressWarnings("unchecked") static Consumer mockValueAction() { return (Consumer) mock(Consumer.class); diff --git a/spring-pulsar/src/test/java/org/springframework/pulsar/listener/ConcurrentPulsarListenerContainerFactoryCustomizerTests.java b/spring-pulsar/src/test/java/org/springframework/pulsar/listener/ConcurrentPulsarListenerContainerFactoryCustomizerTests.java deleted file mode 100644 index 85b1b7f5..00000000 --- a/spring-pulsar/src/test/java/org/springframework/pulsar/listener/ConcurrentPulsarListenerContainerFactoryCustomizerTests.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2023-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.pulsar.listener; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.time.Duration; - -import org.junit.jupiter.api.Test; - -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Configuration; -import org.springframework.pulsar.annotation.EnablePulsar; -import org.springframework.pulsar.config.ConcurrentPulsarListenerContainerFactory; -import org.springframework.pulsar.config.ConcurrentPulsarListenerContainerFactoryCustomizer; - -/** - * Tests for applying {@link ConcurrentPulsarListenerContainerFactoryCustomizer} to the - * {@link ConcurrentPulsarListenerContainerFactory}. - * - * @author Chris Bono - */ -@SuppressWarnings("removal") -class ConcurrentPulsarListenerContainerFactoryCustomizerTests { - - @Test - void whenSingleCustomizerAvailableThenItIsApplied() { - var containerFactory = mock(ConcurrentPulsarListenerContainerFactory.class); - var containerProps = new PulsarContainerProperties(); - when(containerFactory.getContainerProperties()).thenReturn(containerProps); - ConcurrentPulsarListenerContainerFactoryCustomizer customizer = ( - cf) -> cf.getContainerProperties().transactions().setTimeout(Duration.ofSeconds(45)); - try (var appContext = new AnnotationConfigApplicationContext()) { - appContext.registerBean(ConcurrentPulsarListenerContainerFactory.class, () -> containerFactory); - appContext.registerBean(ConcurrentPulsarListenerContainerFactoryCustomizer.class, () -> customizer); - appContext.register(ConcurrentPulsarListenerContainerFactoryCustomizerTestsConfig.class); - appContext.refresh(); - assertThat(containerProps.transactions().getTimeout()).isEqualTo(Duration.ofSeconds(45)); - } - } - - @Test - void whenMultipleCustomizersAvailableThenNoneAreApplied() { - var containerFactory = mock(ConcurrentPulsarListenerContainerFactory.class); - var containerProps = new PulsarContainerProperties(); - when(containerFactory.getContainerProperties()).thenReturn(containerProps); - ConcurrentPulsarListenerContainerFactoryCustomizer customizer1 = ( - cf) -> cf.getContainerProperties().transactions().setTimeout(Duration.ofSeconds(45)); - ConcurrentPulsarListenerContainerFactoryCustomizer customizer2 = ( - cf) -> cf.getContainerProperties().transactions().setTimeout(Duration.ofSeconds(60)); - try (var appContext = new AnnotationConfigApplicationContext()) { - appContext.registerBean(ConcurrentPulsarListenerContainerFactory.class, () -> containerFactory); - appContext.registerBean("customizer1", ConcurrentPulsarListenerContainerFactoryCustomizer.class, - () -> customizer1); - appContext.registerBean("customizer2", ConcurrentPulsarListenerContainerFactoryCustomizer.class, - () -> customizer2); - appContext.register(ConcurrentPulsarListenerContainerFactoryCustomizerTestsConfig.class); - appContext.refresh(); - assertThat(containerProps.transactions().getTimeout()).isNull(); - } - } - - @Test - void whenNoCustomizersAvaiableThenContextStartsWithoutFailure() { - var containerFactory = mock(ConcurrentPulsarListenerContainerFactory.class); - try (var appContext = new AnnotationConfigApplicationContext()) { - appContext.registerBean(ConcurrentPulsarListenerContainerFactory.class, () -> containerFactory); - appContext.register(ConcurrentPulsarListenerContainerFactoryCustomizerTestsConfig.class); - appContext.refresh(); - } - } - - @Configuration(proxyBeanMethods = false) - @EnablePulsar - static class ConcurrentPulsarListenerContainerFactoryCustomizerTestsConfig { - - } - -} diff --git a/spring-pulsar/src/test/java/org/springframework/pulsar/listener/PulsarListenerTxnTests.java b/spring-pulsar/src/test/java/org/springframework/pulsar/listener/PulsarListenerTxnTests.java index 078eb120..1b8e4f20 100644 --- a/spring-pulsar/src/test/java/org/springframework/pulsar/listener/PulsarListenerTxnTests.java +++ b/spring-pulsar/src/test/java/org/springframework/pulsar/listener/PulsarListenerTxnTests.java @@ -33,7 +33,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.pulsar.annotation.EnablePulsar; import org.springframework.pulsar.annotation.PulsarListener; -import org.springframework.pulsar.config.ConcurrentPulsarListenerContainerFactoryCustomizer; import org.springframework.pulsar.config.PulsarListenerEndpointRegistry; import org.springframework.pulsar.core.PulsarTemplate; import org.springframework.pulsar.listener.PulsarListenerTxnTests.BatchListenerWithCommit.BatchListenerWithCommitConfig; @@ -50,6 +49,7 @@ * Tests for the transaction support in {@link PulsarListener @PulsarListener}. * * @author Chris Bono + * @author Andrey Litvitski */ @SuppressWarnings("removal") class PulsarListenerTxnTests extends PulsarTxnTestsBase { @@ -273,9 +273,8 @@ void throwsExceptionWhenTransactionsAreRequired() { assertThatIllegalStateException().isThrownBy(() -> { var context = new AnnotationConfigApplicationContext(); context.register(TopLevelConfig.class, TransactionsDisabledOnListenerConfig.class); - context.registerBean("containerPropsRequiredCustomizer", - ConcurrentPulsarListenerContainerFactoryCustomizer.class, - () -> (cf) -> cf.getContainerProperties().transactions().setRequired(true)); + context.registerBean("containerPropsRequiredCustomizer", TestPulsarContainerPropertiesCustomizer.class, + () -> containerProps -> containerProps.transactions().setRequired(true)); context.refresh(); }).withMessage("Listener w/ id [%s] requested no transactions but txn are required".formatted(LISTENER_ID)); } @@ -285,8 +284,8 @@ void disablesTransactionsWhenTransactionsAreNotRequired() { try (var context = new AnnotationConfigApplicationContext()) { context.register(TopLevelConfig.class, TransactionsDisabledOnListenerConfig.class); context.registerBean("containerPropsNotRequiredCustomizer", - ConcurrentPulsarListenerContainerFactoryCustomizer.class, - () -> (cf) -> cf.getContainerProperties().transactions().setRequired(false)); + TestPulsarContainerPropertiesCustomizer.class, + () -> containerProps -> containerProps.transactions().setRequired(false)); context.refresh(); var container = context.getBean(PulsarListenerEndpointRegistry.class).getListenerContainer(LISTENER_ID); assertThat(container).isNotNull(); @@ -317,9 +316,8 @@ void ignoresSettingWhenNoTxnManagerAvailable() { assertThatException().isThrownBy(() -> { var context = new AnnotationConfigApplicationContext(); context.register(TopLevelConfig.class, TransactionsEnabledOnListenerConfig.class); - context.registerBean("removeTxnManagerCustomizer", - ConcurrentPulsarListenerContainerFactoryCustomizer.class, - () -> (cf) -> cf.getContainerProperties().transactions().setTransactionManager(null)); + context.registerBean("removeTxnManagerCustomizer", TestPulsarContainerPropertiesCustomizer.class, + () -> containerProps -> containerProps.transactions().setTransactionManager(null)); context.refresh(); }) .withCauseInstanceOf(IllegalStateException.class) @@ -332,8 +330,8 @@ void enablesTransactionsWhenTxnManagerAvailable() { try (var context = new AnnotationConfigApplicationContext()) { context.register(TopLevelConfig.class, TransactionsEnabledOnListenerConfig.class); context.registerBean("containerPropsNotRequiredCustomizer", - ConcurrentPulsarListenerContainerFactoryCustomizer.class, - () -> (cf) -> cf.getContainerProperties().transactions().setEnabled(false)); + TestPulsarContainerPropertiesCustomizer.class, + () -> containerProps -> containerProps.transactions().setEnabled(false)); context.refresh(); var container = context.getBean(PulsarListenerEndpointRegistry.class).getListenerContainer(LISTENER_ID); assertThat(container).isNotNull(); diff --git a/spring-pulsar/src/test/java/org/springframework/pulsar/transaction/PulsarTxnTestsBase.java b/spring-pulsar/src/test/java/org/springframework/pulsar/transaction/PulsarTxnTestsBase.java index 2ef193e1..cd66461b 100644 --- a/spring-pulsar/src/test/java/org/springframework/pulsar/transaction/PulsarTxnTestsBase.java +++ b/spring-pulsar/src/test/java/org/springframework/pulsar/transaction/PulsarTxnTestsBase.java @@ -27,6 +27,7 @@ import org.apache.pulsar.client.api.Schema; import org.assertj.core.api.AbstractListAssert; import org.assertj.core.api.ObjectAssert; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeAll; import org.testcontainers.containers.PulsarContainer; import org.testcontainers.junit.jupiter.Testcontainers; @@ -103,6 +104,13 @@ protected AbstractListAssert, String, ObjectAssert pulsarConsumerFactory(PulsarClient pulsarClient, } @Bean - PulsarContainerProperties pulsarContainerProperties(PulsarAwareTransactionManager pulsarTransactionManager) { + PulsarContainerProperties pulsarContainerProperties(PulsarAwareTransactionManager pulsarTransactionManager, + @Nullable TestPulsarContainerPropertiesCustomizer containerPropsCustomizer) { var containerProps = new PulsarContainerProperties(); containerProps.transactions().setEnabled(true); containerProps.transactions().setRequired(false); containerProps.transactions().setTransactionManager(pulsarTransactionManager); + if (containerPropsCustomizer != null) { + containerPropsCustomizer.customize(containerProps); + } return containerProps; }