Use LogAccessor from SF
* Change main classes to use a `LogAccessor` API to simplify code flow * Fix tests according `LogAccessor` property * Fix some Sonar smells
This commit is contained in:
@@ -494,8 +494,8 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
logger.error("Failed to eagerly establish the connection.", e);
|
||||
catch (RuntimeException ex) {
|
||||
logger.error(ex, "Failed to eagerly establish the connection.");
|
||||
}
|
||||
}
|
||||
doStart();
|
||||
@@ -659,9 +659,7 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin
|
||||
protected void handleConfirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||
CorrelationDataWrapper wrapper = (CorrelationDataWrapper) correlationData;
|
||||
if (correlationData == null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("No correlation data provided for ack: " + ack + " cause:" + cause);
|
||||
}
|
||||
logger.debug(() -> "No correlation data provided for ack: " + ack + " cause:" + cause);
|
||||
return;
|
||||
}
|
||||
Object userCorrelationData = wrapper.getUserData();
|
||||
@@ -675,11 +673,8 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin
|
||||
sendOutput(buildConfirmMessage(ack, cause, wrapper, userCorrelationData), nackChannel, true);
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Nowhere to send publisher confirm "
|
||||
+ (ack ? "ack" : "nack") + " for "
|
||||
+ userCorrelationData);
|
||||
}
|
||||
logger.debug(() -> "Nowhere to send publisher confirm " + (ack ? "ack" : "nack") + " for "
|
||||
+ userCorrelationData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public class AsyncAmqpOutboundGateway extends AbstractAmqpOutboundEndpoint {
|
||||
new MessagingException(replyMessageBuilder.build(), exceptionToLogAndSend);
|
||||
}
|
||||
}
|
||||
logger.error("Failed to send async reply: " + result.toString(), exceptionToLogAndSend);
|
||||
logger.error(exceptionToLogAndSend, () -> "Failed to send async reply: " + result.toString());
|
||||
sendErrorMessage(this.requestMessage, exceptionToLogAndSend);
|
||||
}
|
||||
}
|
||||
@@ -139,9 +139,7 @@ public class AsyncAmqpOutboundGateway extends AbstractAmqpOutboundEndpoint {
|
||||
new ReplyRequiredException(this.requestMessage, "Timeout on async request/reply", ex);
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Reply not required and async timeout for " + this.requestMessage);
|
||||
}
|
||||
logger.debug(() -> "Reply not required and async timeout for " + this.requestMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -36,9 +36,7 @@ import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.amqp.core.MessageDeliveryMode;
|
||||
@@ -56,6 +54,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.log.LogAccessor;
|
||||
import org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint;
|
||||
import org.springframework.integration.amqp.support.AmqpHeaderMapper;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
@@ -70,8 +69,7 @@ import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import com.rabbitmq.client.AMQP.BasicProperties;
|
||||
@@ -83,10 +81,10 @@ import com.rabbitmq.client.Channel;
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @author Gunnar Hillert
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class AmqpOutboundChannelAdapterParserTests {
|
||||
|
||||
@@ -326,19 +324,19 @@ public class AmqpOutboundChannelAdapterParserTests {
|
||||
doThrow(toBeThrown).when(connectionFactory).createConnection();
|
||||
when(amqpTemplate.getConnectionFactory()).thenReturn(connectionFactory);
|
||||
AmqpOutboundEndpoint handler = new AmqpOutboundEndpoint(amqpTemplate);
|
||||
Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class));
|
||||
LogAccessor logger = spy(TestUtils.getPropertyValue(handler, "logger", LogAccessor.class));
|
||||
new DirectFieldAccessor(handler).setPropertyValue("logger", logger);
|
||||
doNothing().when(logger).error("Failed to eagerly establish the connection.", toBeThrown);
|
||||
doNothing().when(logger).error(toBeThrown, "Failed to eagerly establish the connection.");
|
||||
ApplicationContext context = mock(ApplicationContext.class);
|
||||
handler.setApplicationContext(context);
|
||||
handler.setBeanFactory(context);
|
||||
handler.afterPropertiesSet();
|
||||
handler.start();
|
||||
handler.stop();
|
||||
verify(logger, never()).error(anyString(), any(RuntimeException.class));
|
||||
verify(logger, never()).error(any(RuntimeException.class), anyString());
|
||||
handler.setLazyConnect(false);
|
||||
handler.start();
|
||||
verify(logger).error("Failed to eagerly establish the connection.", toBeThrown);
|
||||
verify(logger).error(toBeThrown, "Failed to eagerly establish the connection.");
|
||||
handler.stop();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user