INT-3543: Remove context.close() from tests
JIRA: https://jira.spring.io/browse/INT-3543 Quoting Sam Brannen: > However, one should *never* programmatically close the injected application context in a test, since the Spring TestContext Framework caches all contexts across the entire JVM process. If you need to close a context after a test method or test class for some reason, the only supported and reliable mechanism is `@DirtiesContext`. **Cherry-pick to 4.0.x**
This commit is contained in:
committed by
Gary Russell
parent
c588288c49
commit
39a1c3ce30
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.amqp.channel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -27,7 +28,6 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.integration.amqp.rule.BrokerRunning;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -55,9 +55,6 @@ public class ChannelTests {
|
||||
@Autowired
|
||||
private CachingConnectionFactory factory;
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void pubSubLostConnectionTest() throws Exception {
|
||||
final CyclicBarrier latch = new CyclicBarrier(2);
|
||||
@@ -78,7 +75,7 @@ public class ChannelTests {
|
||||
factory.destroy();
|
||||
channel.send(new GenericMessage<String>("bar"));
|
||||
latch.await(10, TimeUnit.SECONDS);
|
||||
context.close();
|
||||
channel.destroy();
|
||||
assertEquals(0, TestUtils.getPropertyValue(factory, "connectionListener.delegates", Collection.class).size());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -28,13 +28,11 @@ import javax.jms.Queue;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.Topic;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.integration.jms.PollableJmsChannel;
|
||||
import org.springframework.integration.jms.SubscribableJmsChannel;
|
||||
import org.springframework.integration.support.MessageBuilderFactory;
|
||||
@@ -47,6 +45,7 @@ import org.springframework.jms.support.destination.DestinationResolver;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.messaging.support.ChannelInterceptorAdapter;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -56,6 +55,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext
|
||||
public class JmsChannelParserTests {
|
||||
|
||||
@Autowired
|
||||
@@ -115,18 +115,9 @@ public class JmsChannelParserTests {
|
||||
@Autowired
|
||||
private MessageChannel withContainerClass;
|
||||
|
||||
@Autowired
|
||||
private AbstractApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
private MessageBuilderFactory messageBuilderFactory;
|
||||
|
||||
|
||||
@After
|
||||
public void closeContext() {
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queueReferenceChannel() {
|
||||
assertEquals(SubscribableJmsChannel.class, queueReferenceChannel.getClass());
|
||||
@@ -271,9 +262,9 @@ public class JmsChannelParserTests {
|
||||
@Test
|
||||
public void withPlaceholders() {
|
||||
DefaultMessageListenerContainer container = TestUtils.getPropertyValue(withPlaceholders, "container", DefaultMessageListenerContainer.class);
|
||||
System.out.println(container.getDestination());
|
||||
System.out.println(container.getConcurrentConsumers());
|
||||
System.out.println(container.getMaxConcurrentConsumers());
|
||||
assertEquals("queue://test.queue", container.getDestination().toString());
|
||||
assertEquals(5, container.getConcurrentConsumers());
|
||||
assertEquals(25, container.getMaxConcurrentConsumers());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user