Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Comment on lines +156 to +161
Copy link

Copilot AI Nov 24, 2025

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Nov 24, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.
Comment on lines +157 to +161
Copy link

Copilot AI Nov 24, 2025

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.

Suggested change
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
assertThat(connectionFactory).isInstanceOf(CachingConnectionFactory.class);
CachingConnectionFactory cachingFactory = (CachingConnectionFactory) connectionFactory;
CachingConnectionFactory cachingFactory = context.getBean(CachingConnectionFactory.class);

Copilot uses AI. Check for mistakes.
// Verify that producer and consumer caching is enabled
// When these properties are true, CachingConnectionFactory will cache and reuse
// MessageProducer and MessageConsumer instances for the same destination
assertThat(cachingFactory.isCacheProducers())
.as("CachingConnectionFactory should cache MessageProducers for the same destination")
.isTrue();
assertThat(cachingFactory.isCacheConsumers())
.as("CachingConnectionFactory should cache MessageConsumers for the same destination")
.isTrue();
});
}

@Configuration
@PropertySource("classpath:servicebus/additional.properties")
static class AdditionalPropertySourceConfiguration {
Expand Down
Loading