Skip to content

Commit 20e588a

Browse files
CopilotNetyyyy
andcommitted
Add unit test for Spring Cloud Azure Service Bus JMS CachingConnectionFactory behavior
Verify that when using CachingConnectionFactory mode, producer and consumer caching is properly configured for reusing MessageProducer and MessageConsumer instances for the same destination. Test covers both standard and premium pricing tiers. Co-authored-by: Netyyyy <[email protected]>
1 parent 50e2b79 commit 20e588a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryConfigurationTests.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.azure.servicebus.jms.ServiceBusJmsConnectionFactory;
77
import com.azure.spring.cloud.autoconfigure.implementation.context.properties.AzureGlobalProperties;
8+
import jakarta.jms.ConnectionFactory;
89
import org.junit.jupiter.params.ParameterizedTest;
910
import org.junit.jupiter.params.provider.ValueSource;
1011
import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
@@ -140,6 +141,36 @@ void useCacheConnectionViaAdditionConfigurationFile(String pricingTier) {
140141
});
141142
}
142143

144+
@ParameterizedTest
145+
@ValueSource(strings = { "standard", "premium" })
146+
void cachingConnectionFactoryCachesProducersAndConsumersForSameDestination(String pricingTier) {
147+
this.contextRunner
148+
.withPropertyValues(
149+
"spring.jms.servicebus.pricing-tier=" + pricingTier,
150+
"spring.jms.servicebus.pool.enabled=false",
151+
"spring.jms.cache.producers=true",
152+
"spring.jms.cache.consumers=true"
153+
)
154+
.run(context -> {
155+
assertThat(context).hasSingleBean(CachingConnectionFactory.class);
156+
157+
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
158+
assertThat(connectionFactory).isInstanceOf(CachingConnectionFactory.class);
159+
160+
CachingConnectionFactory cachingFactory = (CachingConnectionFactory) connectionFactory;
161+
162+
// Verify that producer and consumer caching is enabled
163+
// When these properties are true, CachingConnectionFactory will cache and reuse
164+
// MessageProducer and MessageConsumer instances for the same destination
165+
assertThat(cachingFactory.isCacheProducers())
166+
.as("CachingConnectionFactory should cache MessageProducers for the same destination")
167+
.isTrue();
168+
assertThat(cachingFactory.isCacheConsumers())
169+
.as("CachingConnectionFactory should cache MessageConsumers for the same destination")
170+
.isTrue();
171+
});
172+
}
173+
143174
@Configuration
144175
@PropertySource("classpath:servicebus/additional.properties")
145176
static class AdditionalPropertySourceConfiguration {

0 commit comments

Comments
 (0)