|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -50,13 +50,12 @@ class ActiveMQAutoConfigurationTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void brokerIsEmbeddedByDefault() {
|
|
|
|
void brokerIsEmbeddedByDefault() {
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
|
|
|
|
assertThat(context).hasSingleBean(CachingConnectionFactory.class);
|
|
|
|
assertThat(context).hasSingleBean(CachingConnectionFactory.class).hasBean("jmsConnectionFactory");
|
|
|
|
CachingConnectionFactory cachingConnectionFactory = context.getBean(CachingConnectionFactory.class);
|
|
|
|
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
|
|
|
assertThat(cachingConnectionFactory.getTargetConnectionFactory())
|
|
|
|
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
|
|
|
.isInstanceOf(ActiveMQConnectionFactory.class);
|
|
|
|
assertThat(connectionFactory.getTargetConnectionFactory()).isInstanceOf(ActiveMQConnectionFactory.class);
|
|
|
|
assertThat(
|
|
|
|
assertThat(((ActiveMQConnectionFactory) connectionFactory.getTargetConnectionFactory()).getBrokerURL())
|
|
|
|
((ActiveMQConnectionFactory) cachingConnectionFactory.getTargetConnectionFactory()).getBrokerURL())
|
|
|
|
.isEqualTo("vm://localhost?broker.persistent=false");
|
|
|
|
.isEqualTo("vm://localhost?broker.persistent=false");
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -69,9 +68,10 @@ class ActiveMQAutoConfigurationTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void connectionFactoryIsCachedByDefault() {
|
|
|
|
void connectionFactoryIsCachedByDefault() {
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class);
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(CachingConnectionFactory.class)
|
|
|
|
assertThat(context).hasSingleBean(CachingConnectionFactory.class);
|
|
|
|
.hasBean("jmsConnectionFactory");
|
|
|
|
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
|
|
|
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
|
|
|
|
|
|
|
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
|
|
|
assertThat(connectionFactory.getTargetConnectionFactory()).isInstanceOf(ActiveMQConnectionFactory.class);
|
|
|
|
assertThat(connectionFactory.getTargetConnectionFactory()).isInstanceOf(ActiveMQConnectionFactory.class);
|
|
|
|
assertThat(connectionFactory.isCacheConsumers()).isFalse();
|
|
|
|
assertThat(connectionFactory.isCacheConsumers()).isFalse();
|
|
|
|
assertThat(connectionFactory.isCacheProducers()).isTrue();
|
|
|
|
assertThat(connectionFactory.isCacheProducers()).isTrue();
|
|
|
@ -85,9 +85,10 @@ class ActiveMQAutoConfigurationTests {
|
|
|
|
.withPropertyValues("spring.jms.cache.consumers=true", "spring.jms.cache.producers=false",
|
|
|
|
.withPropertyValues("spring.jms.cache.consumers=true", "spring.jms.cache.producers=false",
|
|
|
|
"spring.jms.cache.session-cache-size=10")
|
|
|
|
"spring.jms.cache.session-cache-size=10")
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class);
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class)
|
|
|
|
assertThat(context).hasSingleBean(CachingConnectionFactory.class);
|
|
|
|
.hasSingleBean(CachingConnectionFactory.class).hasBean("jmsConnectionFactory");
|
|
|
|
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
|
|
|
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
|
|
|
|
|
|
|
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
|
|
|
assertThat(connectionFactory.isCacheConsumers()).isTrue();
|
|
|
|
assertThat(connectionFactory.isCacheConsumers()).isTrue();
|
|
|
|
assertThat(connectionFactory.isCacheProducers()).isFalse();
|
|
|
|
assertThat(connectionFactory.isCacheProducers()).isFalse();
|
|
|
|
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10);
|
|
|
|
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10);
|
|
|
@ -98,8 +99,10 @@ class ActiveMQAutoConfigurationTests {
|
|
|
|
void connectionFactoryCachingCanBeDisabled() {
|
|
|
|
void connectionFactoryCachingCanBeDisabled() {
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
|
|
|
.withPropertyValues("spring.jms.cache.enabled=false").run((context) -> {
|
|
|
|
.withPropertyValues("spring.jms.cache.enabled=false").run((context) -> {
|
|
|
|
assertThat(context.getBeansOfType(ActiveMQConnectionFactory.class)).hasSize(1);
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class)
|
|
|
|
|
|
|
|
.hasSingleBean(ActiveMQConnectionFactory.class).hasBean("jmsConnectionFactory");
|
|
|
|
ActiveMQConnectionFactory connectionFactory = context.getBean(ActiveMQConnectionFactory.class);
|
|
|
|
ActiveMQConnectionFactory connectionFactory = context.getBean(ActiveMQConnectionFactory.class);
|
|
|
|
|
|
|
|
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
|
|
|
ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory(
|
|
|
|
ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory(
|
|
|
|
"vm://localhost?broker.persistent=false");
|
|
|
|
"vm://localhost?broker.persistent=false");
|
|
|
|
assertThat(connectionFactory.getUserName()).isEqualTo(defaultFactory.getUserName());
|
|
|
|
assertThat(connectionFactory.getUserName()).isEqualTo(defaultFactory.getUserName());
|
|
|
@ -123,8 +126,10 @@ class ActiveMQAutoConfigurationTests {
|
|
|
|
"spring.activemq.nonBlockingRedelivery=true", "spring.activemq.sendTimeout=1000",
|
|
|
|
"spring.activemq.nonBlockingRedelivery=true", "spring.activemq.sendTimeout=1000",
|
|
|
|
"spring.activemq.packages.trust-all=false", "spring.activemq.packages.trusted=com.example.acme")
|
|
|
|
"spring.activemq.packages.trust-all=false", "spring.activemq.packages.trusted=com.example.acme")
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
assertThat(context.getBeansOfType(ActiveMQConnectionFactory.class)).hasSize(1);
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class)
|
|
|
|
|
|
|
|
.hasSingleBean(ActiveMQConnectionFactory.class).hasBean("jmsConnectionFactory");
|
|
|
|
ActiveMQConnectionFactory connectionFactory = context.getBean(ActiveMQConnectionFactory.class);
|
|
|
|
ActiveMQConnectionFactory connectionFactory = context.getBean(ActiveMQConnectionFactory.class);
|
|
|
|
|
|
|
|
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
|
|
|
assertThat(connectionFactory.getUserName()).isEqualTo("foo");
|
|
|
|
assertThat(connectionFactory.getUserName()).isEqualTo("foo");
|
|
|
|
assertThat(connectionFactory.getPassword()).isEqualTo("bar");
|
|
|
|
assertThat(connectionFactory.getPassword()).isEqualTo("bar");
|
|
|
|
assertThat(connectionFactory.getCloseTimeout()).isEqualTo(500);
|
|
|
|
assertThat(connectionFactory.getCloseTimeout()).isEqualTo(500);
|
|
|
@ -139,8 +144,10 @@ class ActiveMQAutoConfigurationTests {
|
|
|
|
void defaultPoolConnectionFactoryIsApplied() {
|
|
|
|
void defaultPoolConnectionFactoryIsApplied() {
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
|
|
|
.withPropertyValues("spring.activemq.pool.enabled=true").run((context) -> {
|
|
|
|
.withPropertyValues("spring.activemq.pool.enabled=true").run((context) -> {
|
|
|
|
assertThat(context.getBeansOfType(JmsPoolConnectionFactory.class)).hasSize(1);
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class)
|
|
|
|
|
|
|
|
.hasSingleBean(JmsPoolConnectionFactory.class).hasBean("jmsConnectionFactory");
|
|
|
|
JmsPoolConnectionFactory connectionFactory = context.getBean(JmsPoolConnectionFactory.class);
|
|
|
|
JmsPoolConnectionFactory connectionFactory = context.getBean(JmsPoolConnectionFactory.class);
|
|
|
|
|
|
|
|
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
|
|
|
JmsPoolConnectionFactory defaultFactory = new JmsPoolConnectionFactory();
|
|
|
|
JmsPoolConnectionFactory defaultFactory = new JmsPoolConnectionFactory();
|
|
|
|
assertThat(connectionFactory.isBlockIfSessionPoolIsFull())
|
|
|
|
assertThat(connectionFactory.isBlockIfSessionPoolIsFull())
|
|
|
|
.isEqualTo(defaultFactory.isBlockIfSessionPoolIsFull());
|
|
|
|
.isEqualTo(defaultFactory.isBlockIfSessionPoolIsFull());
|
|
|
@ -167,8 +174,10 @@ class ActiveMQAutoConfigurationTests {
|
|
|
|
"spring.activemq.pool.timeBetweenExpirationCheck=2048",
|
|
|
|
"spring.activemq.pool.timeBetweenExpirationCheck=2048",
|
|
|
|
"spring.activemq.pool.useAnonymousProducers=false")
|
|
|
|
"spring.activemq.pool.useAnonymousProducers=false")
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
assertThat(context.getBeansOfType(JmsPoolConnectionFactory.class)).hasSize(1);
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class)
|
|
|
|
|
|
|
|
.hasSingleBean(JmsPoolConnectionFactory.class).hasBean("jmsConnectionFactory");
|
|
|
|
JmsPoolConnectionFactory connectionFactory = context.getBean(JmsPoolConnectionFactory.class);
|
|
|
|
JmsPoolConnectionFactory connectionFactory = context.getBean(JmsPoolConnectionFactory.class);
|
|
|
|
|
|
|
|
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
|
|
|
assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isFalse();
|
|
|
|
assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isFalse();
|
|
|
|
assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()).isEqualTo(64);
|
|
|
|
assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()).isEqualTo(64);
|
|
|
|
assertThat(connectionFactory.getConnectionIdleTimeout()).isEqualTo(512);
|
|
|
|
assertThat(connectionFactory.getConnectionIdleTimeout()).isEqualTo(512);
|
|
|
@ -183,7 +192,10 @@ class ActiveMQAutoConfigurationTests {
|
|
|
|
void poolConnectionFactoryConfiguration() {
|
|
|
|
void poolConnectionFactoryConfiguration() {
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
|
|
|
.withPropertyValues("spring.activemq.pool.enabled:true").run((context) -> {
|
|
|
|
.withPropertyValues("spring.activemq.pool.enabled:true").run((context) -> {
|
|
|
|
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class)
|
|
|
|
|
|
|
|
.hasSingleBean(JmsPoolConnectionFactory.class).hasBean("jmsConnectionFactory");
|
|
|
|
ConnectionFactory factory = context.getBean(ConnectionFactory.class);
|
|
|
|
ConnectionFactory factory = context.getBean(ConnectionFactory.class);
|
|
|
|
|
|
|
|
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(factory);
|
|
|
|
assertThat(factory).isInstanceOf(JmsPoolConnectionFactory.class);
|
|
|
|
assertThat(factory).isInstanceOf(JmsPoolConnectionFactory.class);
|
|
|
|
context.getSourceApplicationContext().close();
|
|
|
|
context.getSourceApplicationContext().close();
|
|
|
|
assertThat(factory.createConnection()).isNull();
|
|
|
|
assertThat(factory.createConnection()).isNull();
|
|
|
@ -194,14 +206,20 @@ class ActiveMQAutoConfigurationTests {
|
|
|
|
void cachingConnectionFactoryNotOnTheClasspathThenSimpleConnectionFactoryAutoConfigured() {
|
|
|
|
void cachingConnectionFactoryNotOnTheClasspathThenSimpleConnectionFactoryAutoConfigured() {
|
|
|
|
this.contextRunner.withClassLoader(new FilteredClassLoader(CachingConnectionFactory.class))
|
|
|
|
this.contextRunner.withClassLoader(new FilteredClassLoader(CachingConnectionFactory.class))
|
|
|
|
.withPropertyValues("spring.activemq.pool.enabled=false", "spring.jms.cache.enabled=false")
|
|
|
|
.withPropertyValues("spring.activemq.pool.enabled=false", "spring.jms.cache.enabled=false")
|
|
|
|
.run((context) -> assertThat(context).hasSingleBean(ActiveMQConnectionFactory.class));
|
|
|
|
.run((context) -> {
|
|
|
|
|
|
|
|
assertThat(context).hasSingleBean(ConnectionFactory.class)
|
|
|
|
|
|
|
|
.hasSingleBean(ActiveMQConnectionFactory.class).hasBean("jmsConnectionFactory");
|
|
|
|
|
|
|
|
ActiveMQConnectionFactory connectionFactory = context.getBean(ActiveMQConnectionFactory.class);
|
|
|
|
|
|
|
|
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void cachingConnectionFactoryNotOnTheClasspathAndCacheEnabledThenSimpleConnectionFactoryNotConfigured() {
|
|
|
|
void cachingConnectionFactoryNotOnTheClasspathAndCacheEnabledThenSimpleConnectionFactoryNotConfigured() {
|
|
|
|
this.contextRunner.withClassLoader(new FilteredClassLoader(CachingConnectionFactory.class))
|
|
|
|
this.contextRunner.withClassLoader(new FilteredClassLoader(CachingConnectionFactory.class))
|
|
|
|
.withPropertyValues("spring.activemq.pool.enabled=false", "spring.jms.cache.enabled=true")
|
|
|
|
.withPropertyValues("spring.activemq.pool.enabled=false", "spring.jms.cache.enabled=true")
|
|
|
|
.run((context) -> assertThat(context).doesNotHaveBean(ActiveMQConnectionFactory.class));
|
|
|
|
.run((context) -> assertThat(context).doesNotHaveBean(ConnectionFactory.class)
|
|
|
|
|
|
|
|
.doesNotHaveBean(ActiveMQConnectionFactory.class).doesNotHaveBean("jmsConnectionFactory"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|