Add the ability to pass a map of connection properties to the Redis service connection creator for more control over the created ConnectionFactory. Move connection properties in Rabbit XML configuration up one level.
This commit is contained in:
@@ -3,6 +3,7 @@ package org.springframework.cloud.config.xml;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.cloud.service.messaging.RabbitConnectionFactoryConfig;
|
||||
import org.springframework.cloud.service.messaging.RabbitConnectionFactoryFactory;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
@@ -30,28 +31,30 @@ public class CloudRabbitConnectionFactoryParser extends AbstractNestedElementClo
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
|
||||
BeanDefinition cloudRabbitConfiguration = null;
|
||||
Element rabbitOptionsElement = DomUtils.getChildElementByTagName(element, RABBIT_OPTIONS);
|
||||
if (rabbitOptionsElement != null) {
|
||||
cloudRabbitConfiguration = parseRabbitOptionsElement(rabbitOptionsElement, parserContext);
|
||||
}
|
||||
BeanDefinition cloudRabbitConfiguration = parseRabbitOptionsElement(element, parserContext);
|
||||
|
||||
builder.addConstructorArgValue(cloudRabbitConfiguration);
|
||||
}
|
||||
|
||||
private BeanDefinition parseRabbitOptionsElement(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder configBeanBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition("org.springframework.cloud.service.messaging.RabbitConnectionFactoryConfig");
|
||||
BeanDefinitionBuilder.genericBeanDefinition(RabbitConnectionFactoryConfig.class.getName());
|
||||
|
||||
Element propertiesElement = DomUtils.getChildElementByTagName(element, CONNECTION_PROPERTIES);
|
||||
if (propertiesElement != null) {
|
||||
Map<?, ?> map = parserContext.getDelegate().parseMapElement(propertiesElement, configBeanBuilder.getRawBeanDefinition());
|
||||
configBeanBuilder.addConstructorArgValue(map);
|
||||
Map<?, ?> properties = parserContext.getDelegate().parseMapElement(propertiesElement, configBeanBuilder.getRawBeanDefinition());
|
||||
configBeanBuilder.addConstructorArgValue(properties);
|
||||
}
|
||||
|
||||
String channelCacheSize = element.getAttribute(CHANNEL_CACHE_SIZE);
|
||||
configBeanBuilder.addConstructorArgValue(channelCacheSize);
|
||||
Element rabbitOptionsElement = DomUtils.getChildElementByTagName(element, RABBIT_OPTIONS);
|
||||
if (rabbitOptionsElement != null) {
|
||||
String channelCacheSize = rabbitOptionsElement.getAttribute(CHANNEL_CACHE_SIZE);
|
||||
configBeanBuilder.addConstructorArgValue(channelCacheSize);
|
||||
}
|
||||
|
||||
if (propertiesElement == null && rabbitOptionsElement == null) {
|
||||
return null;
|
||||
}
|
||||
return configBeanBuilder.getBeanDefinition();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,13 @@ package org.springframework.cloud.config.xml;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.cloud.service.keyval.RedisConnectionFactoryConfig;
|
||||
import org.springframework.cloud.service.keyval.RedisConnectionFactoryFactory;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Parser for the {@code <cloud:redis-connection-factory>} namespace element
|
||||
*
|
||||
@@ -17,6 +20,7 @@ import org.w3c.dom.Element;
|
||||
public class CloudRedisConnectionFactoryParser extends AbstractPoolingCloudServiceFactoryParser {
|
||||
|
||||
private static final String ELEMENT_POOL = "pool";
|
||||
private static final String CONNECTION_PROPERTIES = "connection-properties";
|
||||
|
||||
public CloudRedisConnectionFactoryParser() {
|
||||
super(RedisConnectionFactoryFactory.class);
|
||||
@@ -26,16 +30,22 @@ public class CloudRedisConnectionFactoryParser extends AbstractPoolingCloudServi
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
|
||||
BeanDefinitionBuilder redisConfigBeanBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(RedisConnectionFactoryConfig.class.getName());
|
||||
|
||||
BeanDefinition cloudPoolConfiguration = null;
|
||||
Element poolElement = DomUtils.getChildElementByTagName(element, ELEMENT_POOL);
|
||||
if (poolElement != null) {
|
||||
cloudPoolConfiguration = parsePoolElement(poolElement, parserContext);
|
||||
}
|
||||
|
||||
BeanDefinitionBuilder redisConfigBeanBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition("org.springframework.cloud.service.PooledServiceConnectorConfig");
|
||||
redisConfigBeanBuilder.addConstructorArgValue(cloudPoolConfiguration);
|
||||
|
||||
Element propertiesElement = DomUtils.getChildElementByTagName(element, CONNECTION_PROPERTIES);
|
||||
if (propertiesElement != null) {
|
||||
Map<?, ?> properties = parserContext.getDelegate().parseMapElement(propertiesElement, builder.getRawBeanDefinition());
|
||||
redisConfigBeanBuilder.addConstructorArgValue(properties);
|
||||
}
|
||||
|
||||
builder.addConstructorArgValue(redisConfigBeanBuilder.getBeanDefinition());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.springframework.cloud.service.keyval;
|
||||
|
||||
import org.springframework.cloud.service.MapServiceConnectorConfig;
|
||||
import org.springframework.cloud.service.PooledServiceConnectorConfig;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
public class RedisConnectionFactoryConfig extends PooledServiceConnectorConfig {
|
||||
private MapServiceConnectorConfig connectionConfig;
|
||||
|
||||
public RedisConnectionFactoryConfig(PoolConfig poolConfig) {
|
||||
this(poolConfig, null);
|
||||
}
|
||||
|
||||
public RedisConnectionFactoryConfig(Map<String, Object> properties) {
|
||||
this(null, properties);
|
||||
}
|
||||
|
||||
public RedisConnectionFactoryConfig(PoolConfig poolConfig, Map<String, Object> properties) {
|
||||
super(poolConfig);
|
||||
this.connectionConfig = new MapServiceConnectorConfig(properties);
|
||||
}
|
||||
|
||||
public MapServiceConnectorConfig getConnectionProperties() {
|
||||
return connectionConfig;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package org.springframework.cloud.service.keyval;
|
||||
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
import org.springframework.cloud.service.MapServiceConnectionConfigurer;
|
||||
import org.springframework.cloud.service.MapServiceConnectorConfig;
|
||||
import org.springframework.cloud.service.PooledServiceConnectorConfig;
|
||||
import org.springframework.cloud.service.ServiceConnectorConfigurer;
|
||||
import org.springframework.cloud.service.Util;
|
||||
@@ -12,20 +14,43 @@ import redis.clients.jedis.JedisPoolConfig;
|
||||
/**
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Scott Frederick
|
||||
*
|
||||
*/
|
||||
public class RedisConnectionFactoryConfigurer implements ServiceConnectorConfigurer<JedisConnectionFactory, PooledServiceConnectorConfig> {
|
||||
public class RedisConnectionFactoryConfigurer implements ServiceConnectorConfigurer<JedisConnectionFactory, RedisConnectionFactoryConfig> {
|
||||
private MapServiceConnectionConfigurer<JedisConnectionFactory, MapServiceConnectorConfig> mapServiceConnectionConfigurer =
|
||||
new MapServiceConnectionConfigurer<JedisConnectionFactory, MapServiceConnectorConfig>();
|
||||
|
||||
@Override
|
||||
public JedisConnectionFactory configure(JedisConnectionFactory connectionFactory, RedisConnectionFactoryConfig config) {
|
||||
if (config != null) {
|
||||
configurePool(connectionFactory, config);
|
||||
configureConnection(connectionFactory, config);
|
||||
}
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
public JedisConnectionFactory configure(JedisConnectionFactory connectionFactory, PooledServiceConnectorConfig config) {
|
||||
if (config != null && config.getPoolConfig() != null) {
|
||||
if (config != null) {
|
||||
configurePool(connectionFactory, config);
|
||||
}
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
private void configurePool(JedisConnectionFactory connectionFactory, PooledServiceConnectorConfig config) {
|
||||
if (config.getPoolConfig() != null) {
|
||||
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
BeanWrapper target = new BeanWrapperImpl(poolConfig);
|
||||
BeanWrapper source = new BeanWrapperImpl(config.getPoolConfig());
|
||||
Util.setCorrespondingProperties(target, source);
|
||||
connectionFactory.setPoolConfig(poolConfig);
|
||||
}
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
private void configureConnection(JedisConnectionFactory connectionFactory, RedisConnectionFactoryConfig config) {
|
||||
if (config.getConnectionProperties() != null) {
|
||||
mapServiceConnectionConfigurer.configure(connectionFactory, config.getConnectionProperties());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,11 @@ public class RedisConnectionFactoryCreator extends AbstractServiceConnectorCreat
|
||||
connectionFactory.setHostName(serviceInfo.getHost());
|
||||
connectionFactory.setPort(serviceInfo.getPort());
|
||||
connectionFactory.setPassword(serviceInfo.getPassword());
|
||||
configurer.configure(connectionFactory, (PooledServiceConnectorConfig) serviceConnectorConfig);
|
||||
if (serviceConnectorConfig instanceof RedisConnectionFactoryConfig) {
|
||||
configurer.configure(connectionFactory, (RedisConnectionFactoryConfig) serviceConnectorConfig);
|
||||
} else {
|
||||
configurer.configure(connectionFactory, (PooledServiceConnectorConfig) serviceConnectorConfig);
|
||||
}
|
||||
connectionFactory.afterPropertiesSet();
|
||||
return connectionFactory;
|
||||
} else {
|
||||
|
||||
@@ -15,12 +15,11 @@ public class RabbitConnectionFactoryConfig extends MapServiceConnectorConfig {
|
||||
private Integer channelCacheSize;
|
||||
|
||||
public RabbitConnectionFactoryConfig(Map<String, Object> properties) {
|
||||
super(properties);
|
||||
this(properties, null);
|
||||
}
|
||||
|
||||
public RabbitConnectionFactoryConfig(Integer channelCacheSize) {
|
||||
super(null);
|
||||
this.channelCacheSize = channelCacheSize;
|
||||
this(null, channelCacheSize);
|
||||
}
|
||||
|
||||
public RabbitConnectionFactoryConfig(Map<String, Object> properties, Integer channelCacheSize) {
|
||||
|
||||
@@ -32,7 +32,10 @@ public class RabbitConnectionFactoryCreator extends AbstractServiceConnectorCrea
|
||||
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory);
|
||||
|
||||
if (serviceConnectorConfiguration != null) {
|
||||
cachingConnectionFactory.setChannelCacheSize(((RabbitConnectionFactoryConfig)serviceConnectorConfiguration).getChannelCacheSize());
|
||||
Integer channelCacheSize = ((RabbitConnectionFactoryConfig) serviceConnectorConfiguration).getChannelCacheSize();
|
||||
if (channelCacheSize != null) {
|
||||
cachingConnectionFactory.setChannelCacheSize(channelCacheSize);
|
||||
}
|
||||
}
|
||||
|
||||
return cachingConnectionFactory;
|
||||
|
||||
@@ -87,6 +87,7 @@
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="rabbit-options" type="rabbitOptionsType" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element ref="connection-properties" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
@@ -115,6 +116,7 @@
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="pool" type="poolType" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element ref="connection-properties" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
@@ -282,9 +284,6 @@
|
||||
Element defining optional Rabbit configuration settings.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element ref="connection-properties" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="channel-cache-size" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
*
|
||||
*/
|
||||
public class RabbitConnectionFactoryCloudConfigTestHelper {
|
||||
public static final int DEFAULT_CHANNEL_CACHE_SIZE = 1;
|
||||
|
||||
public static void assertConfigProperties(ConnectionFactory connector, Integer channelCacheSize,
|
||||
Integer requestedHeartbeat, Integer connectionTimeout) {
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package org.springframework.cloud.config;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Scott Frederick
|
||||
*
|
||||
*/
|
||||
public class RedisConnectionFactoryCloudConfigTestHelper extends CommonPoolCloudConfigTestHelper {
|
||||
@@ -16,5 +19,10 @@ public class RedisConnectionFactoryCloudConfigTestHelper extends CommonPoolCloud
|
||||
JedisPoolConfig poolConfig = (JedisPoolConfig) ReflectionTestUtils.getField(connector, "poolConfig");
|
||||
assertCommonsPoolProperties(poolConfig, maxActive, minIdle, maxWait);
|
||||
}
|
||||
|
||||
|
||||
public static void assertConnectionProperties(RedisConnectionFactory connector, int timeout) {
|
||||
JedisConnectionFactory jedisConnector = (JedisConnectionFactory) connector;
|
||||
assertEquals(timeout, jedisConnector.getTimeout());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.springframework.context.annotation.Bean;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper.DEFAULT_CHANNEL_CACHE_SIZE;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
@@ -36,7 +38,25 @@ public class RabbitConnectionFactoryJavaConfigTest extends AbstractServiceJavaCo
|
||||
getTestApplicationContext(RabbitConnectionFactoryConfigWithServiceConfig.class, createService("my-service"));
|
||||
|
||||
ConnectionFactory connector = testContext.getBean("connectionFactoryWithConfig", getConnectorType());
|
||||
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, 5, 10);
|
||||
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloudRabbitConnectionFactoryWithProperties() {
|
||||
ApplicationContext testContext =
|
||||
getTestApplicationContext(RabbitConnectionFactoryConfigWithServiceConfig.class, createService("my-service"));
|
||||
|
||||
ConnectionFactory connector = testContext.getBean("connectionFactoryWithProperties", getConnectorType());
|
||||
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, DEFAULT_CHANNEL_CACHE_SIZE, 5, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloudRabbitConnectionFactoryWithConfigAndProperties() {
|
||||
ApplicationContext testContext =
|
||||
getTestApplicationContext(RabbitConnectionFactoryConfigWithServiceConfig.class, createService("my-service"));
|
||||
|
||||
ConnectionFactory connector = testContext.getBean("connectionFactoryWithConfigAndProperties", getConnectorType());
|
||||
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 300, 15, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,10 +77,25 @@ class RabbitConnectionFactoryConfigWithoutId extends AbstractCloudConfig {
|
||||
class RabbitConnectionFactoryConfigWithServiceConfig extends AbstractCloudConfig {
|
||||
@Bean
|
||||
public ConnectionFactory connectionFactoryWithConfig() {
|
||||
RabbitConnectionFactoryConfig serviceConfig = new RabbitConnectionFactoryConfig(200);
|
||||
return connectionFactory().rabbitConnectionFactory("my-service", serviceConfig);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConnectionFactory connectionFactoryWithProperties() {
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put("requestedHeartbeat", 5);
|
||||
properties.put("connectionTimeout", 10);
|
||||
RabbitConnectionFactoryConfig serviceConfig = new RabbitConnectionFactoryConfig(properties, 200);
|
||||
RabbitConnectionFactoryConfig serviceConfig = new RabbitConnectionFactoryConfig(properties);
|
||||
return connectionFactory().rabbitConnectionFactory("my-service", serviceConfig);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConnectionFactory connectionFactoryWithConfigAndProperties() {
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put("requestedHeartbeat", 15);
|
||||
properties.put("connectionTimeout", 20);
|
||||
RabbitConnectionFactoryConfig serviceConfig = new RabbitConnectionFactoryConfig(properties, 300);
|
||||
return connectionFactory().rabbitConnectionFactory("my-service", serviceConfig);
|
||||
}
|
||||
}
|
||||
@@ -5,58 +5,82 @@ import org.springframework.cloud.config.RedisConnectionFactoryCloudConfigTestHel
|
||||
import org.springframework.cloud.service.PooledServiceConnectorConfig;
|
||||
import org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig;
|
||||
import org.springframework.cloud.service.ServiceInfo;
|
||||
import org.springframework.cloud.service.keyval.RedisConnectionFactoryConfig;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
*
|
||||
* @author Scott Frederick
|
||||
*/
|
||||
public class RedisConnectionFactoryJavaConfigTest extends AbstractServiceJavaConfigTest<RedisConnectionFactory> {
|
||||
public RedisConnectionFactoryJavaConfigTest() {
|
||||
super(RedisConnectionFactoryConfigWithId.class, RedisConnectionFactoryConfigWithoutId.class);
|
||||
}
|
||||
|
||||
|
||||
protected ServiceInfo createService(String id) {
|
||||
return createRedisService(id);
|
||||
}
|
||||
|
||||
|
||||
protected Class<RedisConnectionFactory> getConnectorType() {
|
||||
return RedisConnectionFactory.class;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void cloudRedisConnectionFactoryWithMaxPool() {
|
||||
ApplicationContext testContext =
|
||||
getTestApplicationContext(RedisConnectionFactoryConfigWithServiceConfig.class,
|
||||
createService("my-service"));
|
||||
|
||||
ApplicationContext testContext =
|
||||
getTestApplicationContext(RedisConnectionFactoryConfigWithServiceConfig.class,
|
||||
createService("my-service"));
|
||||
|
||||
RedisConnectionFactory connector = testContext.getBean("pool20Wait200", getConnectorType());
|
||||
RedisConnectionFactoryCloudConfigTestHelper.assertPoolProperties(connector, 20, 0, 200);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void cloudRedisConnectionFactoryWithMinMaxPool() {
|
||||
ApplicationContext testContext =
|
||||
getTestApplicationContext(RedisConnectionFactoryConfigWithServiceConfig.class,
|
||||
createService("my-service"));
|
||||
|
||||
ApplicationContext testContext =
|
||||
getTestApplicationContext(RedisConnectionFactoryConfigWithServiceConfig.class,
|
||||
createService("my-service"));
|
||||
|
||||
RedisConnectionFactory connector = testContext.getBean("pool5_30Wait3000", getConnectorType());
|
||||
RedisConnectionFactoryCloudConfigTestHelper.assertPoolProperties(connector, 30, 5, 3000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloudRedisConnectionFactoryWithTimeout() {
|
||||
ApplicationContext testContext =
|
||||
getTestApplicationContext(RedisConnectionFactoryConfigWithServiceConfig.class,
|
||||
createService("my-service"));
|
||||
|
||||
RedisConnectionFactory connector = testContext.getBean("timeout10", getConnectorType());
|
||||
RedisConnectionFactoryCloudConfigTestHelper.assertConnectionProperties(connector, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloudRedisConnectionFactoryWithWithMaxPoolAndTimeout() {
|
||||
ApplicationContext testContext =
|
||||
getTestApplicationContext(RedisConnectionFactoryConfigWithServiceConfig.class,
|
||||
createService("my-service"));
|
||||
|
||||
RedisConnectionFactory connector = testContext.getBean("pool30Wait300_timeout20", getConnectorType());
|
||||
RedisConnectionFactoryCloudConfigTestHelper.assertPoolProperties(connector, 30, 0, 300);
|
||||
RedisConnectionFactoryCloudConfigTestHelper.assertConnectionProperties(connector, 20);
|
||||
}
|
||||
}
|
||||
|
||||
class RedisConnectionFactoryConfigWithId extends AbstractCloudConfig {
|
||||
@Bean(name="my-service")
|
||||
@Bean(name = "my-service")
|
||||
public RedisConnectionFactory testRedisConnectionFactory() {
|
||||
return connectionFactory().redisConnectionFactory("my-service");
|
||||
}
|
||||
}
|
||||
|
||||
class RedisConnectionFactoryConfigWithoutId extends AbstractCloudConfig {
|
||||
@Bean(name="my-service")
|
||||
@Bean(name = "my-service")
|
||||
public RedisConnectionFactory testRedisConnectionFactory() {
|
||||
return connectionFactory().redisConnectionFactory();
|
||||
}
|
||||
@@ -69,12 +93,28 @@ class RedisConnectionFactoryConfigWithServiceConfig extends AbstractCloudConfig
|
||||
PooledServiceConnectorConfig serviceConfig = new PooledServiceConnectorConfig(poolConfig);
|
||||
return connectionFactory().redisConnectionFactory("my-service", serviceConfig);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public RedisConnectionFactory pool5_30Wait3000() {
|
||||
PoolConfig poolConfig = new PoolConfig(5, 30, 3000);
|
||||
PooledServiceConnectorConfig serviceConfig = new PooledServiceConnectorConfig(poolConfig);
|
||||
PooledServiceConnectorConfig serviceConfig = new RedisConnectionFactoryConfig(poolConfig);
|
||||
return connectionFactory().redisConnectionFactory("my-service", serviceConfig);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisConnectionFactory timeout10() {
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put("timeout", 10);
|
||||
RedisConnectionFactoryConfig serviceConfig = new RedisConnectionFactoryConfig(properties);
|
||||
return connectionFactory().redisConnectionFactory("my-service", serviceConfig);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisConnectionFactory pool30Wait300_timeout20() {
|
||||
Map<String, Object> properties = new HashMap<String, Object>();
|
||||
properties.put("timeout", 20);
|
||||
PoolConfig poolConfig = new PoolConfig(30, 300);
|
||||
RedisConnectionFactoryConfig serviceConfig = new RedisConnectionFactoryConfig(poolConfig, properties);
|
||||
return connectionFactory().redisConnectionFactory("my-service", serviceConfig);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHe
|
||||
import org.springframework.cloud.service.ServiceInfo;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import static org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper.DEFAULT_CHANNEL_CACHE_SIZE;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
@@ -34,7 +36,22 @@ public class RabbitConnectionFactoryXmlConfigTest extends AbstractServiceXmlConf
|
||||
ApplicationContext testContext = getTestApplicationContext("cloud-rabbit-with-config.xml", createService("my-service"));
|
||||
|
||||
ConnectionFactory connector = testContext.getBean("service-channelCacheSize200", getConnectorType());
|
||||
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, 5, 10);
|
||||
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloudRabbitConnectionFactoryWithProperties() {
|
||||
ApplicationContext testContext = getTestApplicationContext("cloud-rabbit-with-config.xml", createService("my-service"));
|
||||
|
||||
ConnectionFactory connector = testContext.getBean("service-properties", getConnectorType());
|
||||
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, DEFAULT_CHANNEL_CACHE_SIZE, 5, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloudRabbitConnectionFactoryWithConfigurationAndProperties() {
|
||||
ApplicationContext testContext = getTestApplicationContext("cloud-rabbit-with-config.xml", createService("my-service"));
|
||||
|
||||
ConnectionFactory connector = testContext.getBean("service-channelCacheSize200-properties", getConnectorType());
|
||||
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, 5, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,4 +44,21 @@ public class RedisConnectionFactoryXmlConfigTest extends AbstractServiceXmlConfi
|
||||
RedisConnectionFactory connector = testContext.getBean("service-pool5-30-wait3000", getConnectorType());
|
||||
RedisConnectionFactoryCloudConfigTestHelper.assertPoolProperties(connector, 30, 5, 3000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloudRedisConnectionFactoryWithTimeout() {
|
||||
ApplicationContext testContext = getTestApplicationContext("cloud-redis-with-config.xml", createService("my-service"));
|
||||
|
||||
RedisConnectionFactory connector = testContext.getBean("service-timeout10", getConnectorType());
|
||||
RedisConnectionFactoryCloudConfigTestHelper.assertConnectionProperties(connector, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloudRedisConnectionFactoryWithMaxPoolAndTimeout() {
|
||||
ApplicationContext testContext = getTestApplicationContext("cloud-redis-with-config.xml", createService("my-service"));
|
||||
|
||||
RedisConnectionFactory connector = testContext.getBean("service-pool30-wait300-timeout20", getConnectorType());
|
||||
RedisConnectionFactoryCloudConfigTestHelper.assertPoolProperties(connector, 30, 0, 300);
|
||||
RedisConnectionFactoryCloudConfigTestHelper.assertConnectionProperties(connector, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,21 @@
|
||||
http://www.springframework.org/schema/cloud http://www.springframework.org/schema/cloud/spring-cloud.xsd">
|
||||
|
||||
<cloud:rabbit-connection-factory id="service-channelCacheSize200" service-name="my-service">
|
||||
<cloud:rabbit-options channel-cache-size="200">
|
||||
<cloud:connection-properties>
|
||||
<entry key="requestedHeartbeat" value="5"/>
|
||||
<entry key="connectionTimeout" value="10"/>
|
||||
</cloud:connection-properties>
|
||||
</cloud:rabbit-options>
|
||||
<cloud:rabbit-options channel-cache-size="200"/>
|
||||
</cloud:rabbit-connection-factory>
|
||||
|
||||
<cloud:rabbit-connection-factory id="service-channelCacheSize200-properties" service-name="my-service">
|
||||
<cloud:rabbit-options channel-cache-size="200"/>
|
||||
<cloud:connection-properties>
|
||||
<entry key="requestedHeartbeat" value="5"/>
|
||||
<entry key="connectionTimeout" value="10"/>
|
||||
</cloud:connection-properties>
|
||||
</cloud:rabbit-connection-factory>
|
||||
|
||||
<cloud:rabbit-connection-factory id="service-properties" service-name="my-service">
|
||||
<cloud:connection-properties>
|
||||
<entry key="requestedHeartbeat" value="5"/>
|
||||
<entry key="connectionTimeout" value="10"/>
|
||||
</cloud:connection-properties>
|
||||
</cloud:rabbit-connection-factory>
|
||||
</beans>
|
||||
|
||||
@@ -4,14 +4,27 @@
|
||||
xmlns:cloud="http://www.springframework.org/schema/cloud"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/cloud http://www.springframework.org/schema/cloud/spring-cloud.xsd">
|
||||
|
||||
|
||||
|
||||
|
||||
<cloud:redis-connection-factory id="service-pool20-wait200" service-name="my-service">
|
||||
<cloud:pool pool-size="20" max-wait-time="200"/>
|
||||
<cloud:pool pool-size="20" max-wait-time="200"/>
|
||||
</cloud:redis-connection-factory>
|
||||
|
||||
<cloud:redis-connection-factory id="service-pool5-30-wait3000" service-name="my-service">
|
||||
<cloud:pool pool-size="5-30" max-wait-time="3000"/>
|
||||
<cloud:pool pool-size="5-30" max-wait-time="3000"/>
|
||||
</cloud:redis-connection-factory>
|
||||
|
||||
|
||||
<cloud:redis-connection-factory id="service-timeout10" service-name="my-service">
|
||||
<cloud:connection-properties>
|
||||
<entry key="timeout" value="10"/>
|
||||
</cloud:connection-properties>
|
||||
</cloud:redis-connection-factory>
|
||||
|
||||
<cloud:redis-connection-factory id="service-pool30-wait300-timeout20" service-name="my-service">
|
||||
<cloud:pool pool-size="30" max-wait-time="300"/>
|
||||
<cloud:connection-properties>
|
||||
<entry key="timeout" value="20"/>
|
||||
</cloud:connection-properties>
|
||||
</cloud:redis-connection-factory>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user