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
32171f5ed6
commit
f2ca6cdd06
@@ -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;
|
||||
@@ -34,7 +35,6 @@ import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
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;
|
||||
@@ -62,9 +62,6 @@ public class ChannelTests {
|
||||
@Autowired
|
||||
private CachingConnectionFactory factory;
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void pubSubLostConnectionTest() throws Exception {
|
||||
final CyclicBarrier latch = new CyclicBarrier(2);
|
||||
@@ -85,7 +82,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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user