Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 14, 2025

Description

Adds a unit test verifying that Spring Cloud Azure Service Bus JMS correctly configures CachingConnectionFactory to cache and reuse MessageProducer instances for the same destination. Also updates the azure-servicebus-jms dependency to version 2.1.0.

Changes

  • New test: cachingConnectionFactoryReusesSameProducerForSameDestination in ServiceBusJmsConnectionFactoryConfigurationTests

    • Uses ServiceBusJmsSession.createQueue() to create actual ServiceBusJmsQueue instances
    • Uses when(mockInnerSession.createProducer(any(Destination.class))) to mock producer creation, returning different producers for each call
    • Verifies same producer is returned for ServiceBusJmsQueue instances with the same queue name (demonstrating caching works)
    • Verifies different producer is returned for different queue names
    • This test would fail with azure-servicebus-jms 2.0.0 at the assertion assertThat(producer1ForQueue1.toString()).isEqualTo(producer2ForQueue1.toString()) because ServiceBusJmsQueue.toString() returned unique values like "ServiceBusJmsQueue@hashcode", preventing CachingConnectionFactory from caching producers
    • With 2.1.0, toString() returns consistent values based on queue name, enabling proper caching
  • Dependency update: Updated azure-servicebus-jms from 2.0.0 to 2.1.0 in:

    • eng/versioning/external_dependencies.txt
    • sdk/spring/spring-cloud-azure-autoconfigure/pom.xml
    • sdk/spring/spring-cloud-azure-starter-servicebus-jms/pom.xml

The test ensures Spring Framework's CachingConnectionFactory will cache producers as documented in CachingConnectionFactory.java#L362. The key fix in azure-servicebus-jms 2.1.0 is that ServiceBusJmsQueue.toString() now returns the queue name, enabling proper caching (in 2.0.0, it returned unique values like "ServiceBusJmsQueue@11655" which prevented caching).

Fixes #47281

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.
Original prompt

This section details on the original issue you should resolve

<issue_title>[FEATURE REQ] Add UT for Spring Cloud Azure</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.
Add a new UT to make sure when using Spring Cloud Azure Service Bus JMS, with CachingConnectionFactory mode , the same object is always used when creating producers/consumers for the same destination.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
https://github.com/spring-projects/spring-framework/blob/92a186b44b4e58a9932c23fe71c243b5e944160a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java#L362

https://github.com/spring-projects/spring-framework/blob/92a186b44b4e58a9932c23fe71c243b5e944160a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java#L427

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Description Added
  • Expected solution specified
    </issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

…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 <92105726+Netyyyy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit test for Spring Cloud Azure Service Bus JMS Add unit test for CachingConnectionFactory producer/consumer reuse in Spring Cloud Azure Service Bus JMS Nov 14, 2025
Copilot AI requested a review from Netyyyy November 14, 2025 09:26
Copilot finished work on behalf of Netyyyy November 14, 2025 09:26
@Netyyyy Netyyyy requested a review from Copilot November 24, 2025 02:29
Copilot finished reviewing on behalf of Netyyyy November 24, 2025 02:32

This comment was marked as outdated.

- Updated azure-servicebus-jms version from 2.0.0 to 2.1.0 in:
  - eng/versioning/external_dependencies.txt
  - sdk/spring/spring-cloud-azure-autoconfigure/pom.xml
  - sdk/spring/spring-cloud-azure-starter-servicebus-jms/pom.xml
- Simplified test code per review feedback:
  - Removed unnecessary blank lines
  - Simplified bean retrieval by getting CachingConnectionFactory directly
  - Removed unused imports
- Test verifies that CachingConnectionFactory caches producers/consumers
  for the same destination when configured with appropriate properties

Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
Copilot AI changed the title Add unit test for CachingConnectionFactory producer/consumer reuse in Spring Cloud Azure Service Bus JMS Add unit test for CachingConnectionFactory producer/consumer reuse and update azure-servicebus-jms to 2.1.0 Dec 1, 2025
Copilot finished work on behalf of Netyyyy December 1, 2025 09:10
Copilot AI and others added 2 commits December 2, 2025 01:30
Added new test method cachingConnectionFactoryReusesSameProducerForSameDestination
that:
- Demonstrates the same producer is returned for the same destination (queue1)
- Demonstrates a different producer is returned for different destinations (queue2)
- Uses Mockito.verify to prove createProducer is only called once per destination,
  confirming the caching behavior

Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
- Use statically imported verify and times instead of fully qualified names
- Improve comment formatting for better readability

Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
Copilot finished work on behalf of Netyyyy December 2, 2025 01:34
…tion caching

The test now demonstrates the specific fix in azure-servicebus-jms 2.1.0:
- In 2.0.0, each Queue instance had unique toString() like "ServiceBusJmsQueue@11655"
  which prevented CachingConnectionFactory from caching producers for the same queue
- In 2.1.0, toString() returns the queue name, enabling proper caching

Test verifies that:
- Multiple Queue instances with same toString() value use cached producer
- Different Queue instances with different toString() values use different producers
- Mockito.verify confirms createProducer is only called once for same-named queues

Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
Copilot finished work on behalf of Netyyyy December 2, 2025 06:07
Added new test cachingConnectionFactoryFailsToReuseProducerWithUniqueToString
that demonstrates the bug in azure-servicebus-jms 2.0.0 where each Queue instance
had a unique toString() like "ServiceBusJmsQueue@11655", which prevented
CachingConnectionFactory from caching producers for the same queue name.

The test verifies that:
- When toString() returns unique values, createProducer is called twice
- Different producers are returned even for the same queue name
- This contrasts with the fixed 2.1.0 behavior where toString() returns
  the queue name, enabling proper caching

Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
Copilot finished work on behalf of Netyyyy December 2, 2025 06:27
Updated tests to use actual ServiceBusJmsQueue instances instead of mocked Queue:
- Added test serviceBusJmsQueueToStringReturnsConsistentValueForSameQueueName
  that verifies ServiceBusJmsQueue.toString() returns consistent values for
  the same queue name (the key fix in azure-servicebus-jms 2.1.0)
- Updated cachingConnectionFactoryReusesSameProducerForSameDestination to use
  ServiceBusJmsQueue instances via reflection
- This test would fail with azure-servicebus-jms 2.0.0 because toString()
  returned unique values like "ServiceBusJmsQueue@hashcode"

Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
Copilot finished work on behalf of Netyyyy December 2, 2025 07:01
@Azure Azure deleted a comment from Copilot AI Dec 3, 2025
@Azure Azure deleted a comment from Copilot AI Dec 3, 2025
@Azure Azure deleted a comment from Copilot AI Dec 3, 2025
@Azure Azure deleted a comment from Copilot AI Dec 3, 2025
@Azure Azure deleted a comment from Copilot AI Dec 3, 2025
@Azure Azure deleted a comment from Copilot AI Dec 3, 2025
@Azure Azure deleted a comment from Copilot AI Dec 3, 2025
@Azure Azure deleted a comment from Copilot AI Dec 3, 2025
@Netyyyy Netyyyy assigned Copilot and unassigned Copilot Dec 3, 2025
@Netyyyy Netyyyy requested a review from Copilot December 3, 2025 00:57
Copilot finished reviewing on behalf of Netyyyy December 3, 2025 01:01
@Netyyyy Netyyyy marked this pull request as ready for review December 3, 2025 01:04

This comment was marked as resolved.

Copy link
Member

@rujche rujche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Netyyyy
Copy link
Member

Netyyyy commented Dec 3, 2025

/check-enforcer override

@Netyyyy Netyyyy merged commit f20192b into main Dec 3, 2025
36 of 37 checks passed
@Netyyyy Netyyyy deleted the copilot/add-ut-spring-cloud-azure branch December 3, 2025 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE REQ] Add UT for Spring Cloud Azure

3 participants