|
5 | 5 |
|
6 | 6 | import com.azure.servicebus.jms.ServiceBusJmsConnectionFactory; |
7 | 7 | import com.azure.spring.cloud.autoconfigure.implementation.context.properties.AzureGlobalProperties; |
| 8 | +import jakarta.jms.ConnectionFactory; |
8 | 9 | import org.junit.jupiter.params.ParameterizedTest; |
9 | 10 | import org.junit.jupiter.params.provider.ValueSource; |
10 | 11 | import org.messaginghub.pooled.jms.JmsPoolConnectionFactory; |
@@ -140,6 +141,36 @@ void useCacheConnectionViaAdditionConfigurationFile(String pricingTier) { |
140 | 141 | }); |
141 | 142 | } |
142 | 143 |
|
| 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 | + |
143 | 174 | @Configuration |
144 | 175 | @PropertySource("classpath:servicebus/additional.properties") |
145 | 176 | static class AdditionalPropertySourceConfiguration { |
|
0 commit comments