From 6947b31a674b231faf7ec28645701f34ffc97489 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 22 Apr 2015 20:23:06 +0300 Subject: [PATCH] AMQP-490: Suppress ERROR on Normal Close JIRA: https://jira.spring.io/browse/AMQP-490 Currently, we suppress the error log if the channel is closed normally. However, we should also suppress if the channel is closed because the connection is closed normally. (cherry picked from commit d21b795) --- .../amqp/rabbit/connection/RabbitUtils.java | 7 ++++--- ...achingConnectionFactoryIntegrationTests.java | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitUtils.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitUtils.java index 31b42bee..bce71067 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitUtils.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitUtils.java @@ -184,9 +184,10 @@ public abstract class RabbitUtils { public static boolean isNormalChannelClose(ShutdownSignalException sig) { Object shutdownReason = determineShutdownReason(sig); - return shutdownReason instanceof AMQP.Channel.Close - && AMQP.REPLY_SUCCESS == ((AMQP.Channel.Close) shutdownReason).getReplyCode() - && "OK".equals(((AMQP.Channel.Close) shutdownReason).getReplyText()); + return isNormalShutdown(sig) || + (shutdownReason instanceof AMQP.Channel.Close + && AMQP.REPLY_SUCCESS == ((AMQP.Channel.Close) shutdownReason).getReplyCode() + && "OK".equals(((AMQP.Channel.Close) shutdownReason).getReplyText())); } public static boolean isPassiveDeclarationChannelClose(ShutdownSignalException sig) { diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryIntegrationTests.java index 13ee79af..a85b6b7a 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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 @@ -18,6 +18,10 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; import java.net.ServerSocket; import java.net.Socket; @@ -53,6 +57,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.test.BrokerRunning; import org.springframework.amqp.rabbit.test.BrokerTestUtils; import org.springframework.amqp.utils.test.TestUtils; +import org.springframework.beans.DirectFieldAccessor; import com.rabbitmq.client.Channel; import com.rabbitmq.client.DefaultConsumer; @@ -337,6 +342,16 @@ public class CachingConnectionFactoryIntegrationTests { assertEquals(null, result); } + @Test + public void testConnectionCloseLog() { + Log logger = spy(TestUtils.getPropertyValue(this.connectionFactory, "logger", Log.class)); + new DirectFieldAccessor(this.connectionFactory).setPropertyValue("logger", logger); + Connection conn = this.connectionFactory.createConnection(); + conn.createChannel(false); + this.connectionFactory.destroy(); + verify(logger, never()).error(anyString()); + } + @Test @Ignore // Don't run this on the CI build server public void hangOnClose() throws Exception {