diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryConfigurationTests.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryConfigurationTests.java index 10c9fe284a21..b45ab8ec708a 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryConfigurationTests.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryConfigurationTests.java @@ -5,6 +5,7 @@ import com.azure.servicebus.jms.ServiceBusJmsConnectionFactory; import com.azure.spring.cloud.autoconfigure.implementation.context.properties.AzureGlobalProperties; +import jakarta.jms.ConnectionFactory; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.messaginghub.pooled.jms.JmsPoolConnectionFactory; @@ -140,6 +141,36 @@ void useCacheConnectionViaAdditionConfigurationFile(String pricingTier) { }); } + @ParameterizedTest + @ValueSource(strings = { "standard", "premium" }) + void cachingConnectionFactoryCachesProducersAndConsumersForSameDestination(String pricingTier) { + this.contextRunner + .withPropertyValues( + "spring.jms.servicebus.pricing-tier=" + pricingTier, + "spring.jms.servicebus.pool.enabled=false", + "spring.jms.cache.producers=true", + "spring.jms.cache.consumers=true" + ) + .run(context -> { + assertThat(context).hasSingleBean(CachingConnectionFactory.class); + + ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class); + assertThat(connectionFactory).isInstanceOf(CachingConnectionFactory.class); + + CachingConnectionFactory cachingFactory = (CachingConnectionFactory) connectionFactory; + + // Verify that producer and consumer caching is enabled + // When these properties are true, CachingConnectionFactory will cache and reuse + // MessageProducer and MessageConsumer instances for the same destination + assertThat(cachingFactory.isCacheProducers()) + .as("CachingConnectionFactory should cache MessageProducers for the same destination") + .isTrue(); + assertThat(cachingFactory.isCacheConsumers()) + .as("CachingConnectionFactory should cache MessageConsumers for the same destination") + .isTrue(); + }); + } + @Configuration @PropertySource("classpath:servicebus/additional.properties") static class AdditionalPropertySourceConfiguration {