-
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?
Conversation
…nFactory 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]>
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.
Pull request overview
This PR adds a unit test to verify that Spring Cloud Azure Service Bus JMS correctly configures CachingConnectionFactory to enable caching of MessageProducer and MessageConsumer instances when the appropriate cache properties are set.
Key Changes:
- Adds parameterized test
cachingConnectionFactoryCachesProducersAndConsumersForSameDestinationcovering bothstandardandpremiumpricing tiers - Verifies that
CachingConnectionFactory.isCacheProducers()andisCacheConsumers()returntruewhen configured with cache properties
|
|
||
| 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] 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.
| ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class); | |
| assertThat(connectionFactory).isInstanceOf(CachingConnectionFactory.class); | |
| CachingConnectionFactory cachingFactory = (CachingConnectionFactory) connectionFactory; | |
| ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class); | |
| assertThat(connectionFactory).isInstanceOf(CachingConnectionFactory.class); | |
| CachingConnectionFactory cachingFactory = (CachingConnectionFactory) connectionFactory; |
| 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] Remove this blank line to maintain consistency with the rest of the test file. Other tests in this file do not have blank lines between assertions.
| 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); | |
Description
Adds unit test verifying that Spring Cloud Azure Service Bus JMS correctly configures
CachingConnectionFactoryto cache and reuseMessageProducerandMessageConsumerinstances for the same destination.Changes
cachingConnectionFactoryCachesProducersAndConsumersForSameDestinationinServiceBusJmsConnectionFactoryConfigurationTestsisCacheProducers()returnstruewhen cache properties are enabledisCacheConsumers()returnstruewhen cache properties are enabledstandardandpremiumpricing tiersThe test ensures Spring Framework's
CachingConnectionFactorywill cache producers/consumers as documented in CachingConnectionFactory.java#L362 and L427.Fixes #issue_number
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
oss.jfrog.org/usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/azure-sdk-for-java/azure-sdk-for-java/sdk/spring/spring-cloud-azure-autoconfigure org.codehaus.plexus.classworlds.launcher.Launcher test -Dtest=ServiceBusJmsConnectionFactoryConfigurationTests#cachingConnectionFactoryCachesProducersAndConsumersForSameDestination -DfailIfNoTests=false(dns block)test-namespace.servicebus.windows.net/usr/lib/jvm/temurin-17-jdk-amd64/bin/java -javaagent:/home/REDACTED/.m2/repository/org/jacoco/org.jacoco.agent/0.8.13/org.jacoco.agent-0.8.13-runtime.jar=destfile=/home/REDACTED/work/azure-sdk-for-java/azure-sdk-for-java/sdk/spring/spring-cloud-azure-autoconfigure/target/jacoco-unit.exec,excludes=META-INF/** -Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/REDACTED/work/azure-sdk-for-java/azure-sdk-for-java/sdk/spring/spring-cloud-azure-autoconfigure/target/spring-cloud-azure-autoconfigure-oom.hprof -XX:+CrashOnOutOfMemoryError --add-opens java.base/java.lang.invoke=com.azure.core org.apache.maven.surefire.booter.ForkedBooter /home/REDACTED/work/azure-sdk-for-java/azure-sdk-for-java/sdk/spring/spring-cloud-azure-autoconfigure/target/surefire 2025-11-14T08-58-38_759-jvmRun1 surefire-20251114085840322_1tmp surefire_0-20251114085840322_2tmp(dns block)/usr/lib/jvm/temurin-17-jdk-amd64/bin/java -javaagent:/home/REDACTED/.m2/repository/org/jacoco/org.jacoco.agent/0.8.13/org.jacoco.agent-0.8.13-runtime.jar=destfile=/home/REDACTED/work/azure-sdk-for-java/azure-sdk-for-java/sdk/spring/spring-cloud-azure-autoconfigure/target/jacoco-unit.exec,excludes=META-INF/** -Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/REDACTED/work/azure-sdk-for-java/azure-sdk-for-java/sdk/spring/spring-cloud-azure-autoconfigure/target/spring-cloud-azure-autoconfigure-oom.hprof -XX:+CrashOnOutOfMemoryError --add-opens java.base/java.lang.invoke=com.azure.core org.apache.maven.surefire.booter.ForkedBooter /home/REDACTED/work/azure-sdk-for-java/azure-sdk-for-java/sdk/spring/spring-cloud-azure-autoconfigure/target/surefire 2025-11-14T09-05-27_458-jvmRun1 surefire-20251114090527520_1tmp surefire_0-20251114090527520_2tmp(dns block)/usr/lib/jvm/temurin-17-jdk-amd64/bin/java -javaagent:/home/REDACTED/.m2/repository/org/jacoco/org.jacoco.agent/0.8.13/org.jacoco.agent-0.8.13-runtime.jar=destfile=/home/REDACTED/work/azure-sdk-for-java/azure-sdk-for-java/sdk/spring/spring-cloud-azure-autoconfigure/target/jacoco-unit.exec,excludes=META-INF/** -Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/REDACTED/work/azure-sdk-for-java/azure-sdk-for-java/sdk/spring/spring-cloud-azure-autoconfigure/target/spring-cloud-azure-autoconfigure-oom.hprof -XX:+CrashOnOutOfMemoryError --add-opens java.base/java.lang.invoke=com.azure.core org.apache.maven.surefire.booter.ForkedBooter /home/REDACTED/work/azure-sdk-for-java/azure-sdk-for-java/sdk/spring/spring-cloud-azure-autoconfigure/target/surefire 2025-11-14T09-14-40_918-jvmRun1 surefire-20251114091440979_1tmp surefire_0-20251114091440979_2tmp(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.