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");
|
||||
* 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" };
|
||||
|
||||
@Bean
|
||||
public ConnectionFactory connectionFactory(JmsProperties properties) throws NamingException {
|
||||
public ConnectionFactory jmsConnectionFactory(JmsProperties properties) throws NamingException {
|
||||
JndiLocatorDelegate jndiLocatorDelegate = JndiLocatorDelegate.createDefaultResourceRefLocator();
|
||||
if (StringUtils.hasLength(properties.getJndiName())) {
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -73,8 +73,7 @@ class ActiveMQConnectionFactoryConfiguration {
|
|||
static class CachingConnectionFactoryConfiguration {
|
||||
|
||||
@Bean
|
||||
CachingConnectionFactory cachingJmsConnectionFactory(JmsProperties jmsProperties,
|
||||
ActiveMQProperties properties,
|
||||
CachingConnectionFactory jmsConnectionFactory(JmsProperties jmsProperties, ActiveMQProperties properties,
|
||||
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
|
||||
JmsProperties.Cache cacheProperties = jmsProperties.getCache();
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
|
||||
|
@ -95,7 +94,7 @@ class ActiveMQConnectionFactoryConfiguration {
|
|||
|
||||
@Bean(destroyMethod = "stop")
|
||||
@ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "true")
|
||||
JmsPoolConnectionFactory pooledJmsConnectionFactory(ActiveMQProperties properties,
|
||||
JmsPoolConnectionFactory jmsConnectionFactory(ActiveMQProperties properties,
|
||||
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties,
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -58,7 +58,7 @@ class ArtemisConnectionFactoryConfiguration {
|
|||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Bean(name = "jmsConnectionFactory")
|
||||
@ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
CachingConnectionFactory cachingJmsConnectionFactory(JmsProperties jmsProperties) {
|
||||
|
@ -70,7 +70,7 @@ class ArtemisConnectionFactoryConfiguration {
|
|||
return connectionFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Bean(name = "jmsConnectionFactory")
|
||||
@ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "false")
|
||||
ActiveMQConnectionFactory jmsConnectionFactory() {
|
||||
return createConnectionFactory();
|
||||
|
@ -85,13 +85,11 @@ class ArtemisConnectionFactoryConfiguration {
|
|||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass({ JmsPoolConnectionFactory.class, PooledObject.class })
|
||||
@ConditionalOnProperty(prefix = "spring.artemis.pool", name = "enabled", havingValue = "true")
|
||||
static class PooledConnectionFactoryConfiguration {
|
||||
|
||||
@Bean(destroyMethod = "stop")
|
||||
@ConditionalOnProperty(prefix = "spring.artemis.pool", name = "enabled", havingValue = "true",
|
||||
matchIfMissing = false)
|
||||
JmsPoolConnectionFactory pooledJmsConnectionFactory(ListableBeanFactory beanFactory,
|
||||
ArtemisProperties properties) {
|
||||
JmsPoolConnectionFactory jmsConnectionFactory(ListableBeanFactory beanFactory, ArtemisProperties properties) {
|
||||
ActiveMQConnectionFactory connectionFactory = new ArtemisConnectionFactoryFactory(beanFactory, properties)
|
||||
.createConnectionFactory(ActiveMQConnectionFactory.class);
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -111,8 +111,9 @@ class JndiConnectionFactoryAutoConfigurationTests {
|
|||
|
||||
private ContextConsumer<AssertableApplicationContext> assertConnectionFactory(ConnectionFactory connectionFactory) {
|
||||
return (context) -> {
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class);
|
||||
assertThat(context.getBean(ConnectionFactory.class)).isSameAs(connectionFactory);
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class).hasBean("jmsConnectionFactory");
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -50,12 +50,11 @@ class ActiveMQAutoConfigurationTests {
|
|||
@Test
|
||||
void brokerIsEmbeddedByDefault() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(CachingConnectionFactory.class);
|
||||
CachingConnectionFactory cachingConnectionFactory = context.getBean(CachingConnectionFactory.class);
|
||||
assertThat(cachingConnectionFactory.getTargetConnectionFactory())
|
||||
.isInstanceOf(ActiveMQConnectionFactory.class);
|
||||
assertThat(
|
||||
((ActiveMQConnectionFactory) cachingConnectionFactory.getTargetConnectionFactory()).getBrokerURL())
|
||||
assertThat(context).hasSingleBean(CachingConnectionFactory.class).hasBean("jmsConnectionFactory");
|
||||
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
||||
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
||||
assertThat(connectionFactory.getTargetConnectionFactory()).isInstanceOf(ActiveMQConnectionFactory.class);
|
||||
assertThat(((ActiveMQConnectionFactory) connectionFactory.getTargetConnectionFactory()).getBrokerURL())
|
||||
.isEqualTo("vm://localhost?broker.persistent=false");
|
||||
});
|
||||
}
|
||||
|
@ -69,9 +68,10 @@ class ActiveMQAutoConfigurationTests {
|
|||
@Test
|
||||
void connectionFactoryIsCachedByDefault() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class);
|
||||
assertThat(context).hasSingleBean(CachingConnectionFactory.class);
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(CachingConnectionFactory.class)
|
||||
.hasBean("jmsConnectionFactory");
|
||||
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
||||
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
||||
assertThat(connectionFactory.getTargetConnectionFactory()).isInstanceOf(ActiveMQConnectionFactory.class);
|
||||
assertThat(connectionFactory.isCacheConsumers()).isFalse();
|
||||
assertThat(connectionFactory.isCacheProducers()).isTrue();
|
||||
|
@ -85,9 +85,10 @@ class ActiveMQAutoConfigurationTests {
|
|||
.withPropertyValues("spring.jms.cache.consumers=true", "spring.jms.cache.producers=false",
|
||||
"spring.jms.cache.session-cache-size=10")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class);
|
||||
assertThat(context).hasSingleBean(CachingConnectionFactory.class);
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class)
|
||||
.hasSingleBean(CachingConnectionFactory.class).hasBean("jmsConnectionFactory");
|
||||
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
||||
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
||||
assertThat(connectionFactory.isCacheConsumers()).isTrue();
|
||||
assertThat(connectionFactory.isCacheProducers()).isFalse();
|
||||
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10);
|
||||
|
@ -98,8 +99,10 @@ class ActiveMQAutoConfigurationTests {
|
|||
void connectionFactoryCachingCanBeDisabled() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
.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);
|
||||
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
||||
ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory(
|
||||
"vm://localhost?broker.persistent=false");
|
||||
assertThat(connectionFactory.getUserName()).isEqualTo(defaultFactory.getUserName());
|
||||
|
@ -123,8 +126,10 @@ class ActiveMQAutoConfigurationTests {
|
|||
"spring.activemq.nonBlockingRedelivery=true", "spring.activemq.sendTimeout=1000",
|
||||
"spring.activemq.packages.trust-all=false", "spring.activemq.packages.trusted=com.example.acme")
|
||||
.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);
|
||||
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
||||
assertThat(connectionFactory.getUserName()).isEqualTo("foo");
|
||||
assertThat(connectionFactory.getPassword()).isEqualTo("bar");
|
||||
assertThat(connectionFactory.getCloseTimeout()).isEqualTo(500);
|
||||
|
@ -139,8 +144,10 @@ class ActiveMQAutoConfigurationTests {
|
|||
void defaultPoolConnectionFactoryIsApplied() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
.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);
|
||||
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
||||
JmsPoolConnectionFactory defaultFactory = new JmsPoolConnectionFactory();
|
||||
assertThat(connectionFactory.isBlockIfSessionPoolIsFull())
|
||||
.isEqualTo(defaultFactory.isBlockIfSessionPoolIsFull());
|
||||
|
@ -167,8 +174,10 @@ class ActiveMQAutoConfigurationTests {
|
|||
"spring.activemq.pool.timeBetweenExpirationCheck=2048",
|
||||
"spring.activemq.pool.useAnonymousProducers=false")
|
||||
.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);
|
||||
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
||||
assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isFalse();
|
||||
assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()).isEqualTo(64);
|
||||
assertThat(connectionFactory.getConnectionIdleTimeout()).isEqualTo(512);
|
||||
|
@ -183,7 +192,10 @@ class ActiveMQAutoConfigurationTests {
|
|||
void poolConnectionFactoryConfiguration() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
.withPropertyValues("spring.activemq.pool.enabled:true").run((context) -> {
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class)
|
||||
.hasSingleBean(JmsPoolConnectionFactory.class).hasBean("jmsConnectionFactory");
|
||||
ConnectionFactory factory = context.getBean(ConnectionFactory.class);
|
||||
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(factory);
|
||||
assertThat(factory).isInstanceOf(JmsPoolConnectionFactory.class);
|
||||
context.getSourceApplicationContext().close();
|
||||
assertThat(factory.createConnection()).isNull();
|
||||
|
@ -194,14 +206,20 @@ class ActiveMQAutoConfigurationTests {
|
|||
void cachingConnectionFactoryNotOnTheClasspathThenSimpleConnectionFactoryAutoConfigured() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(CachingConnectionFactory.class))
|
||||
.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
|
||||
void cachingConnectionFactoryNotOnTheClasspathAndCacheEnabledThenSimpleConnectionFactoryNotConfigured() {
|
||||
this.contextRunner.withClassLoader(new FilteredClassLoader(CachingConnectionFactory.class))
|
||||
.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)
|
||||
|
|
|
@ -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");
|
||||
* 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.jms.JmsAutoConfiguration;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -70,9 +71,10 @@ class ArtemisAutoConfigurationTests {
|
|||
@Test
|
||||
void connectionFactoryIsCachedByDefault() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class);
|
||||
assertThat(context).hasSingleBean(CachingConnectionFactory.class);
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(CachingConnectionFactory.class)
|
||||
.hasBean("jmsConnectionFactory");
|
||||
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
||||
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
||||
assertThat(connectionFactory.getTargetConnectionFactory()).isInstanceOf(ActiveMQConnectionFactory.class);
|
||||
assertThat(connectionFactory.isCacheConsumers()).isFalse();
|
||||
assertThat(connectionFactory.isCacheProducers()).isTrue();
|
||||
|
@ -86,9 +88,10 @@ class ArtemisAutoConfigurationTests {
|
|||
.withPropertyValues("spring.jms.cache.consumers=true", "spring.jms.cache.producers=false",
|
||||
"spring.jms.cache.session-cache-size=10")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class);
|
||||
assertThat(context).hasSingleBean(CachingConnectionFactory.class);
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.class)
|
||||
.hasSingleBean(CachingConnectionFactory.class).hasBean("jmsConnectionFactory");
|
||||
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
||||
assertThat(context.getBean("jmsConnectionFactory")).isSameAs(connectionFactory);
|
||||
assertThat(connectionFactory.isCacheConsumers()).isTrue();
|
||||
assertThat(connectionFactory.isCacheProducers()).isFalse();
|
||||
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10);
|
||||
|
@ -99,9 +102,9 @@ class ArtemisAutoConfigurationTests {
|
|||
void connectionFactoryCachingCanBeDisabled() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
.withPropertyValues("spring.jms.cache.enabled=false").run((context) -> {
|
||||
assertThat(context).hasSingleBean(ConnectionFactory.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)
|
||||
.withPropertyValues("spring.artemis.mode:native").run((context) -> {
|
||||
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = getConnectionFactory(context);
|
||||
assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory());
|
||||
ActiveMQConnectionFactory activeMQConnectionFactory = getActiveMQConnectionFactory(
|
||||
connectionFactory);
|
||||
|
@ -126,7 +129,7 @@ class ArtemisAutoConfigurationTests {
|
|||
.withPropertyValues("spring.artemis.mode:native", "spring.artemis.host:192.168.1.144",
|
||||
"spring.artemis.port:9876")
|
||||
.run((context) -> assertNettyConnectionFactory(
|
||||
getActiveMQConnectionFactory(context.getBean(ConnectionFactory.class)), "192.168.1.144", 9876));
|
||||
getActiveMQConnectionFactory(getConnectionFactory(context)), "192.168.1.144", 9876));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -136,7 +139,7 @@ class ArtemisAutoConfigurationTests {
|
|||
"spring.artemis.password:secret")
|
||||
.run((context) -> {
|
||||
JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
|
||||
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
|
||||
ConnectionFactory connectionFactory = getConnectionFactory(context);
|
||||
assertThat(connectionFactory).isEqualTo(jmsTemplate.getConnectionFactory());
|
||||
ActiveMQConnectionFactory activeMQConnectionFactory = getActiveMQConnectionFactory(
|
||||
connectionFactory);
|
||||
|
@ -157,7 +160,7 @@ class ArtemisAutoConfigurationTests {
|
|||
.getBean(org.apache.activemq.artemis.core.config.Configuration.class);
|
||||
assertThat(configuration.isPersistenceEnabled()).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);
|
||||
assertThat(configuration.isPersistenceEnabled()).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)
|
||||
.withPropertyValues("spring.artemis.embedded.enabled:false").run((context) -> {
|
||||
assertThat(context).doesNotHaveBean(ActiveMQServer.class);
|
||||
assertNettyConnectionFactory(getActiveMQConnectionFactory(context.getBean(ConnectionFactory.class)),
|
||||
assertNettyConnectionFactory(getActiveMQConnectionFactory(getConnectionFactory(context)),
|
||||
"localhost", 61616);
|
||||
});
|
||||
}
|
||||
|
@ -192,7 +195,7 @@ class ArtemisAutoConfigurationTests {
|
|||
.withPropertyValues("spring.artemis.mode:embedded", "spring.artemis.embedded.enabled:false")
|
||||
.run((context) -> {
|
||||
assertThat(context.getBeansOfType(ActiveMQServer.class)).isEmpty();
|
||||
assertInVmConnectionFactory(getActiveMQConnectionFactory(context.getBean(ConnectionFactory.class)));
|
||||
assertInVmConnectionFactory(getActiveMQConnectionFactory(getConnectionFactory(context)));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -344,13 +347,20 @@ class ArtemisAutoConfigurationTests {
|
|||
@Test
|
||||
void poolConnectionFactoryConfiguration() {
|
||||
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);
|
||||
context.getSourceApplicationContext().close();
|
||||
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) {
|
||||
assertThat(connectionFactory).isInstanceOf(CachingConnectionFactory.class);
|
||||
return (ActiveMQConnectionFactory) ((CachingConnectionFactory) connectionFactory).getTargetConnectionFactory();
|
||||
|
|
Loading…
Reference in New Issue