GH-154 Fix Rabbit Tests with 3.6 Client

Fixes GH-154
This commit is contained in:
Gary Russell
2016-01-15 09:53:25 -05:00
parent 10efbb536f
commit bed0d7f83c
3 changed files with 82 additions and 26 deletions

View File

@@ -1,3 +1,15 @@
/*
* Copyright 2015-2016 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. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.springframework.cloud.config;
import static org.junit.Assert.assertEquals;
@@ -7,23 +19,33 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.test.util.ReflectionTestUtils;
/**
*
*
* @author Ramnivas Laddad
* @author Scott Frederick
* @author Gary Russell
*
*/
public class RabbitConnectionFactoryCloudConfigTestHelper {
public static final int DEFAULT_CHANNEL_CACHE_SIZE = 1;
private final static Integer DEFAULT_FACTORY_TIMEOUT =
(Integer) ReflectionTestUtils.getField(new com.rabbitmq.client.ConnectionFactory(), "connectionTimeout");
private final static Integer DEFAULT_FACTORY_HEARTBEAT =
(Integer) ReflectionTestUtils.getField(new com.rabbitmq.client.ConnectionFactory(), "requestedHeartbeat");
public static void assertConfigProperties(ConnectionFactory connector, Integer channelCacheSize,
Integer requestedHeartbeat, Integer connectionTimeout) {
Integer timeoutToTest = connectionTimeout < 0 ? DEFAULT_FACTORY_TIMEOUT : connectionTimeout;
Integer heartBeatToTest = requestedHeartbeat < 0 ? DEFAULT_FACTORY_HEARTBEAT : requestedHeartbeat;
assertNotNull(connector);
assertEquals(channelCacheSize, ReflectionTestUtils.getField(connector, "channelCacheSize"));
Object rabbitConnectionFactory = ReflectionTestUtils.getField(connector, "rabbitConnectionFactory");
assertNotNull(rabbitConnectionFactory);
assertEquals(requestedHeartbeat, ReflectionTestUtils.getField(rabbitConnectionFactory, "requestedHeartbeat"));
assertEquals(connectionTimeout, ReflectionTestUtils.getField(rabbitConnectionFactory, "connectionTimeout"));
assertEquals(heartBeatToTest, ReflectionTestUtils.getField(rabbitConnectionFactory, "requestedHeartbeat"));
assertEquals(timeoutToTest, ReflectionTestUtils.getField(rabbitConnectionFactory, "connectionTimeout"));
}
}

View File

@@ -1,6 +1,24 @@
/*
* Copyright 2015-2016 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. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.springframework.cloud.config.java;
import static org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper.DEFAULT_CHANNEL_CACHE_SIZE;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper;
import org.springframework.cloud.service.ServiceInfo;
@@ -8,37 +26,35 @@ import org.springframework.cloud.service.messaging.RabbitConnectionFactoryConfig
import org.springframework.context.ApplicationContext;
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
* @author Scott Frederick
* @author Gary Russell
*
*/
public class RabbitConnectionFactoryJavaConfigTest extends AbstractServiceJavaConfigTest<ConnectionFactory> {
public RabbitConnectionFactoryJavaConfigTest() {
super(RabbitConnectionFactoryConfigWithId.class, RabbitConnectionFactoryConfigWithoutId.class);
}
@Override
protected ServiceInfo createService(String id) {
return createRabbitService(id);
}
@Override
protected Class<ConnectionFactory> getConnectorType() {
return ConnectionFactory.class;
}
@Test
public void cloudRabbitConnectionFactoryWithConfig() {
ApplicationContext testContext =
ApplicationContext testContext =
getTestApplicationContext(RabbitConnectionFactoryConfigWithServiceConfig.class, createService("my-service"));
ConnectionFactory connector = testContext.getBean("connectionFactoryWithConfig", getConnectorType());
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, 0, 0);
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, -1, -1);
}
@Test
@@ -98,4 +114,4 @@ class RabbitConnectionFactoryConfigWithServiceConfig extends AbstractCloudConfig
RabbitConnectionFactoryConfig serviceConfig = new RabbitConnectionFactoryConfig(properties, 300);
return connectionFactory().rabbitConnectionFactory("my-service", serviceConfig);
}
}
}

View File

@@ -1,44 +1,62 @@
/*
* Copyright 2015-2016 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. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.springframework.cloud.config.xml;
import static org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper.DEFAULT_CHANNEL_CACHE_SIZE;
import org.junit.Test;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.cloud.config.RabbitConnectionFactoryCloudConfigTestHelper;
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
* @author Gary Russell
*
*/
public class RabbitConnectionFactoryXmlConfigTest extends AbstractServiceXmlConfigTest<ConnectionFactory> {
@Override
protected ServiceInfo createService(String id) {
return createRabbitService(id);
}
@Override
protected String getWithServiceIdContextFileName() {
return "cloud-rabbit-with-service-id.xml";
}
@Override
protected String getWithoutServiceIdContextFileName() {
return "cloud-rabbit-without-service-id.xml";
}
@Override
protected Class<ConnectionFactory> getConnectorType() {
return ConnectionFactory.class;
}
@Test
public void cloudRabbitConnectionFactoryWithConfiguration() {
ApplicationContext testContext = getTestApplicationContext("cloud-rabbit-with-config.xml", createService("my-service"));
ConnectionFactory connector = testContext.getBean("service-channelCacheSize200", getConnectorType());
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, 0, 0);
RabbitConnectionFactoryCloudConfigTestHelper.assertConfigProperties(connector, 200, -1, -1);
}
@Test
public void cloudRabbitConnectionFactoryWithProperties() {
ApplicationContext testContext = getTestApplicationContext("cloud-rabbit-with-config.xml", createService("my-service"));