commit
00b10e655e
|
@ -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.
|
||||||
|
@ -55,7 +55,7 @@ public class JndiConnectionFactoryAutoConfiguration {
|
||||||
private static final String[] JNDI_LOCATIONS = { "java:/JmsXA", "java:/XAConnectionFactory" };
|
private static final String[] JNDI_LOCATIONS = { "java:/JmsXA", "java:/XAConnectionFactory" };
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ConnectionFactory connectionFactory(JmsProperties properties) throws NamingException {
|
public ConnectionFactory jmsConnectionFactory(JmsProperties properties) throws NamingException {
|
||||||
JndiLocatorDelegate jndiLocatorDelegate = JndiLocatorDelegate.createDefaultResourceRefLocator();
|
JndiLocatorDelegate jndiLocatorDelegate = JndiLocatorDelegate.createDefaultResourceRefLocator();
|
||||||
if (StringUtils.hasLength(properties.getJndiName())) {
|
if (StringUtils.hasLength(properties.getJndiName())) {
|
||||||
return jndiLocatorDelegate.lookup(properties.getJndiName(), ConnectionFactory.class);
|
return jndiLocatorDelegate.lookup(properties.getJndiName(), ConnectionFactory.class);
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -73,8 +73,7 @@ class ActiveMQConnectionFactoryConfiguration {
|
||||||
static class CachingConnectionFactoryConfiguration {
|
static class CachingConnectionFactoryConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
CachingConnectionFactory cachingJmsConnectionFactory(JmsProperties jmsProperties,
|
CachingConnectionFactory jmsConnectionFactory(JmsProperties jmsProperties, ActiveMQProperties properties,
|
||||||
ActiveMQProperties properties,
|
|
||||||
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
|
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
|
||||||
JmsProperties.Cache cacheProperties = jmsProperties.getCache();
|
JmsProperties.Cache cacheProperties = jmsProperties.getCache();
|
||||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
|
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
|
||||||
|
@ -95,7 +94,7 @@ class ActiveMQConnectionFactoryConfiguration {
|
||||||
|
|
||||||
@Bean(destroyMethod = "stop")
|
@Bean(destroyMethod = "stop")
|
||||||
@ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true")
|
@ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true")
|
||||||
JmsPoolConnectionFactory pooledJmsConnectionFactory(ActiveMQProperties properties,
|
JmsPoolConnectionFactory jmsConnectionFactory(ActiveMQProperties properties,
|
||||||
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
|
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
|
||||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties,
|
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties,
|
||||||
factoryCustomizers.orderedStream().collect(Collectors.toList()))
|
factoryCustomizers.orderedStream().collect(Collectors.toList()))
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -58,7 +58,7 @@ class ArtemisConnectionFactoryConfiguration {
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean(name = "jmsConnectionFactory")
|
||||||
@ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "true",
|
@ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "true",
|
||||||
matchIfMissing = true)
|
matchIfMissing = true)
|
||||||
CachingConnectionFactory cachingJmsConnectionFactory(JmsProperties jmsProperties) {
|
CachingConnectionFactory cachingJmsConnectionFactory(JmsProperties jmsProperties) {
|
||||||
|
@ -70,7 +70,7 @@ class ArtemisConnectionFactoryConfiguration {
|
||||||
return connectionFactory;
|
return connectionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean(name = "jmsConnectionFactory")
|
||||||
@ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "false")
|
@ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "false")
|
||||||
ActiveMQConnectionFactory jmsConnectionFactory() {
|
ActiveMQConnectionFactory jmsConnectionFactory() {
|
||||||
return createConnectionFactory();
|
return createConnectionFactory();
|
||||||
|
@ -85,13 +85,11 @@ class ArtemisConnectionFactoryConfiguration {
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass({ JmsPoolConnectionFactory.class, PooledObject.class })
|
@ConditionalOnClass({ JmsPoolConnectionFactory.class, PooledObject.class })
|
||||||
|
@ConditionalOnProperty(prefix = "spring.artemis.pool", name = "enabled", havingValue = "true")
|
||||||
static class PooledConnectionFactoryConfiguration {
|
static class PooledConnectionFactoryConfiguration {
|
||||||
|
|
||||||
@Bean(destroyMethod = "stop")
|
@Bean(destroyMethod = "stop")
|
||||||
@ConditionalOnProperty(prefix = "spring.artemis.pool", name = "enabled", havingValue = "true",
|
JmsPoolConnectionFactory jmsConnectionFactory(ListableBeanFactory beanFactory, ArtemisProperties properties) {
|
||||||
matchIfMissing = false)
|
|
||||||
JmsPoolConnectionFactory pooledJmsConnectionFactory(ListableBeanFactory beanFactory,
|
|
||||||
ArtemisProperties properties) {
|
|
||||||
ActiveMQConnectionFactory connectionFactory = new ArtemisConnectionFactoryFactory(beanFactory, properties)
|
ActiveMQConnectionFactory connectionFactory = new ArtemisConnectionFactoryFactory(beanFactory, properties)
|
||||||
.createConnectionFactory(ActiveMQConnectionFactory.class);
|
.createConnectionFactory(ActiveMQConnectionFactory.class);
|
||||||
return new JmsPoolConnectionFactoryFactory(properties.getPool())
|
return new JmsPoolConnectionFactoryFactory(properties.getPool())
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -111,8 +111,9 @@ class JndiConnectionFactoryAutoConfigurationTests {
|
||||||
|
|
||||||
private ContextConsumer<AssertableApplicationContext> assertConnectionFactory(ConnectionFactory connectionFactory) {
|
private ContextConsumer<AssertableApplicationContext> assertConnectionFactory(ConnectionFactory connectionFactory) {
|
||||||
return (context) -> {
|
return (context) -> {
|
||||||
assertThat(context).hasSingleBean(ConnectionFactory.class);
|
assertThat(context).hasSingleBean(ConnectionFactory.class).hasBean("jmsConnectionFactory");
|
||||||
assertThat(context.getBean(ConnectionFactory.class)).isSameAs(connectionFactory);
|
assertThat(context.getBean(ConnectionFactory.class)).isSameAs(connectionFactory)
|
||||||
|
.isSameAs(context.getBean("jmsConnectionFactory"));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,12 +50,11 @@ 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)
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -47,6 +47,7 @@ import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
@ -70,9 +71,10 @@ class ArtemisAutoConfigurationTests {
|
||||||
@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();
|
||||||
|
@ -86,9 +88,10 @@ class ArtemisAutoConfigurationTests {
|
||||||
.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);
|
||||||
|
@ -99,9 +102,9 @@ class ArtemisAutoConfigurationTests {
|
||||||
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).hasSingleBean(ConnectionFactory.class);
|
|
||||||
assertThat(context).doesNotHaveBean(CachingConnectionFactory.class);
|
assertThat(context).doesNotHaveBean(CachingConnectionFactory.class);
|
||||||
assertThat(context.getBean(ConnectionFactory.class)).isInstanceOf(ActiveMQConnectionFactory.class);
|
ConnectionFactory connectionFactory = getConnectionFactory(context);
|
||||||
|
assertThat(connectionFactory).isInstanceOf(ActiveMQConnectionFactory.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +113,7 @@ class ArtemisAutoConfigurationTests {
|
||||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.mode:native").run((context) -> {
|
.withPropertyValues("spring.artemis.mode:native").run((context) -> {
|
||||||
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
ConnectionFactory connectionFactory = getConnectionFactory(context);
|
||||||
assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory());
|
assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory());
|
||||||
ActiveMQConnectionFactory activeMQConnectionFactory = getActiveMQConnectionFactory(
|
ActiveMQConnectionFactory activeMQConnectionFactory = getActiveMQConnectionFactory(
|
||||||
connectionFactory);
|
connectionFactory);
|
||||||
|
@ -126,7 +129,7 @@ class ArtemisAutoConfigurationTests {
|
||||||
.withPropertyValues("spring.artemis.mode:native", "spring.artemis.host:192.168.1.144",
|
.withPropertyValues("spring.artemis.mode:native", "spring.artemis.host:192.168.1.144",
|
||||||
"spring.artemis.port:9876")
|
"spring.artemis.port:9876")
|
||||||
.run((context) -> assertNettyConnectionFactory(
|
.run((context) -> assertNettyConnectionFactory(
|
||||||
getActiveMQConnectionFactory(context.getBean(ConnectionFactory.class)), "192.168.1.144", 9876));
|
getActiveMQConnectionFactory(getConnectionFactory(context)), "192.168.1.144", 9876));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -136,7 +139,7 @@ class ArtemisAutoConfigurationTests {
|
||||||
"spring.artemis.password:secret")
|
"spring.artemis.password:secret")
|
||||||
.run((context) -> {
|
.run((context) -> {
|
||||||
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||||
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
ConnectionFactory connectionFactory = getConnectionFactory(context);
|
||||||
assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory());
|
assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory());
|
||||||
ActiveMQConnectionFactory activeMQConnectionFactory = getActiveMQConnectionFactory(
|
ActiveMQConnectionFactory activeMQConnectionFactory = getActiveMQConnectionFactory(
|
||||||
connectionFactory);
|
connectionFactory);
|
||||||
|
@ -157,7 +160,7 @@ class ArtemisAutoConfigurationTests {
|
||||||
.getBean(org.apache.activemq.artemis.core.config.Configuration.class);
|
.getBean(org.apache.activemq.artemis.core.config.Configuration.class);
|
||||||
assertThat(configuration.isPersistenceEnabled()).isFalse();
|
assertThat(configuration.isPersistenceEnabled()).isFalse();
|
||||||
assertThat(configuration.isSecurityEnabled()).isFalse();
|
assertThat(configuration.isSecurityEnabled()).isFalse();
|
||||||
assertInVmConnectionFactory(getActiveMQConnectionFactory(context.getBean(ConnectionFactory.class)));
|
assertInVmConnectionFactory(getActiveMQConnectionFactory(getConnectionFactory(context)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +173,7 @@ class ArtemisAutoConfigurationTests {
|
||||||
.getBean(org.apache.activemq.artemis.core.config.Configuration.class);
|
.getBean(org.apache.activemq.artemis.core.config.Configuration.class);
|
||||||
assertThat(configuration.isPersistenceEnabled()).isFalse();
|
assertThat(configuration.isPersistenceEnabled()).isFalse();
|
||||||
assertThat(configuration.isSecurityEnabled()).isFalse();
|
assertThat(configuration.isSecurityEnabled()).isFalse();
|
||||||
assertInVmConnectionFactory(getActiveMQConnectionFactory(context.getBean(ConnectionFactory.class)));
|
assertInVmConnectionFactory(getActiveMQConnectionFactory(getConnectionFactory(context)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +183,7 @@ class ArtemisAutoConfigurationTests {
|
||||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
.withPropertyValues("spring.artemis.embedded.enabled:false").run((context) -> {
|
.withPropertyValues("spring.artemis.embedded.enabled:false").run((context) -> {
|
||||||
assertThat(context).doesNotHaveBean(ActiveMQServer.class);
|
assertThat(context).doesNotHaveBean(ActiveMQServer.class);
|
||||||
assertNettyConnectionFactory(getActiveMQConnectionFactory(context.getBean(ConnectionFactory.class)),
|
assertNettyConnectionFactory(getActiveMQConnectionFactory(getConnectionFactory(context)),
|
||||||
"localhost", 61616);
|
"localhost", 61616);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -192,7 +195,7 @@ class ArtemisAutoConfigurationTests {
|
||||||
.withPropertyValues("spring.artemis.mode:embedded", "spring.artemis.embedded.enabled:false")
|
.withPropertyValues("spring.artemis.mode:embedded", "spring.artemis.embedded.enabled:false")
|
||||||
.run((context) -> {
|
.run((context) -> {
|
||||||
assertThat(context.getBeansOfType(ActiveMQServer.class)).isEmpty();
|
assertThat(context.getBeansOfType(ActiveMQServer.class)).isEmpty();
|
||||||
assertInVmConnectionFactory(getActiveMQConnectionFactory(context.getBean(ConnectionFactory.class)));
|
assertInVmConnectionFactory(getActiveMQConnectionFactory(getConnectionFactory(context)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,13 +347,20 @@ class ArtemisAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
void poolConnectionFactoryConfiguration() {
|
void poolConnectionFactoryConfiguration() {
|
||||||
this.contextRunner.withPropertyValues("spring.artemis.pool.enabled:true").run((context) -> {
|
this.contextRunner.withPropertyValues("spring.artemis.pool.enabled:true").run((context) -> {
|
||||||
ConnectionFactory factory = context.getBean(ConnectionFactory.class);
|
ConnectionFactory factory = getConnectionFactory(context);
|
||||||
assertThat(factory).isInstanceOf(JmsPoolConnectionFactory.class);
|
assertThat(factory).isInstanceOf(JmsPoolConnectionFactory.class);
|
||||||
context.getSourceApplicationContext().close();
|
context.getSourceApplicationContext().close();
|
||||||
assertThat(factory.createConnection()).isNull();
|
assertThat(factory.createConnection()).isNull();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ConnectionFactory getConnectionFactory(AssertableApplicationContext context) {
|
||||||
|
assertThat(context).hasSingleBean(ConnectionFactory.class).hasBean("jmsConnectionFactory");
|
||||||
|
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
||||||
|
assertThat(connectionFactory).isSameAs(context.getBean("jmsConnectionFactory"));
|
||||||
|
return connectionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
private ActiveMQConnectionFactory getActiveMQConnectionFactory(ConnectionFactory connectionFactory) {
|
private ActiveMQConnectionFactory getActiveMQConnectionFactory(ConnectionFactory connectionFactory) {
|
||||||
assertThat(connectionFactory).isInstanceOf(CachingConnectionFactory.class);
|
assertThat(connectionFactory).isInstanceOf(CachingConnectionFactory.class);
|
||||||
return (ActiveMQConnectionFactory) ((CachingConnectionFactory) connectionFactory).getTargetConnectionFactory();
|
return (ActiveMQConnectionFactory) ((CachingConnectionFactory) connectionFactory).getTargetConnectionFactory();
|
||||||
|
|
Loading…
Reference in New Issue