-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add unit test for CachingConnectionFactory producer/consumer reuse in Spring Cloud Azure Service Bus JMS #47282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||||||||||||
|
|
||||||||||||||||||
|
||||||||||||||||||
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Simplify bean retrieval and casting. Since line 155 already asserts that a CachingConnectionFactory bean exists, these lines can be simplified to:
CachingConnectionFactory cachingFactory = context.getBean(CachingConnectionFactory.class);This eliminates the intermediate ConnectionFactory variable and the redundant isInstanceOf assertion.
| ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class); | |
| assertThat(connectionFactory).isInstanceOf(CachingConnectionFactory.class); | |
| CachingConnectionFactory cachingFactory = (CachingConnectionFactory) connectionFactory; | |
| CachingConnectionFactory cachingFactory = context.getBean(CachingConnectionFactory.class); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Remove this extra blank line to maintain consistency with the rest of the test file. Other tests in this file do not have blank lines between assertions within the same test method.