Upgrade to SF 5.1; Remove Deprecated Code

Polishing - PR Comments

Remove direct log4j usage in tests

- hazelcast depends on it; retain the dependency just in jmx

Fix hazelcast logger type
This commit is contained in:
Gary Russell
2018-04-10 14:30:46 -04:00
committed by Artem Bilan
parent 27318c7ee5
commit b940e3872b
16 changed files with 33 additions and 314 deletions

View File

@@ -122,7 +122,7 @@ subprojects { subproject ->
junitVintageVersion = '5.1.0'
jythonVersion = '2.5.3'
kryoShadedVersion = '3.0.3'
log4jVersion = '2.10.0'
log4jVersion = '2.11.0'
micrometerVersion = '1.0.3'
mockitoVersion = '2.11.0'
mysqlVersion = '6.0.6'
@@ -141,7 +141,7 @@ subprojects { subproject ->
springSecurityVersion = '5.1.0.BUILD-SNAPSHOT'
springSocialTwitterVersion = '1.1.2.RELEASE'
springRetryVersion = '1.2.2.RELEASE'
springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.0.5.BUILD-SNAPSHOT'
springVersion = project.hasProperty('springVersion') ? project.springVersion : '5.1.0.BUILD-SNAPSHOT'
springWsVersion = '3.0.1.RELEASE'
tomcatVersion = "8.5.23"
xmlUnitVersion = '1.6'
@@ -291,7 +291,6 @@ project('spring-integration-test-support') {
compile "org.springframework:spring-messaging:$springVersion"
compile "org.springframework:spring-test:$springVersion"
compile ("org.apache.logging.log4j:log4j-core:$log4jVersion" , optional)
compile ('log4j:log4j:1.2.17', optional)
}
}

View File

@@ -23,7 +23,6 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -39,8 +38,6 @@ import org.springframework.core.OrderComparator;
import org.springframework.integration.channel.ChannelInterceptorAware;
import org.springframework.integration.channel.interceptor.GlobalChannelInterceptorWrapper;
import org.springframework.integration.channel.interceptor.VetoCapableInterceptor;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.context.IntegrationProperties;
import org.springframework.integration.support.utils.PatternMatchUtils;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.util.Assert;
@@ -105,12 +102,7 @@ public final class GlobalChannelInterceptorProcessor
}
}
// TODO Remove this logic in 5.1
Properties integrationProperties = IntegrationContextUtils.getIntegrationProperties(this.beanFactory);
this.singletonsInstantiated =
Boolean.parseBoolean(integrationProperties.getProperty(
IntegrationProperties.POST_PROCESS_DYNAMIC_BEANS));
this.singletonsInstantiated = true;
}
@Override

View File

@@ -77,13 +77,6 @@ public final class IntegrationProperties {
*/
public static final String ENDPOINTS_NO_AUTO_STARTUP = INTEGRATION_PROPERTIES_PREFIX + "endpoints.noAutoStartup";
/**
* Whether {@link org.springframework.beans.factory.config.BeanPostProcessor}s should process beans registered at runtime.
* Will be removed in 5.1.
*/
public static final String POST_PROCESS_DYNAMIC_BEANS = INTEGRATION_PROPERTIES_PREFIX + "postProcessDynamicBeans";
private static Properties defaults;
static {

View File

@@ -21,10 +21,9 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.integration.support.utils.IntegrationUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.util.Assert;
/**
@@ -117,41 +116,13 @@ public abstract class AbstractDispatcher implements MessageDispatcher {
return true;
}
catch (Exception e) {
throw wrapExceptionIfNecessary(message, e);
throw IntegrationUtils.wrapInDeliveryExceptionIfNecessary(message,
() -> "Dispatcher failed to deliver Message", e);
}
}
return false;
}
/**
* If the exception is not a {@link MessagingException} or does not have a
* {@link MessagingException#getFailedMessage() failedMessage}, wrap it in a new
* {@link MessagingException} with the message. There is some inconsistency here in
* that {@link MessagingException}s are wrapped in a {@link MessagingException} whereas
* {@link Exception}s are wrapped in {@link MessageDeliveryException}. It is retained
* for backwards compatibility and will be resolved in 5.1.
* It also does not wrap other {@link RuntimeException}s.
* TODO: Remove this in favor of
* {@code #wrapInDeliveryExceptionIfNecessary(Message, Supplier, Exception)} in 5.1.
* @param message the message.
* @param e the exception.
* @return the wrapper, if necessary, or the original exception.
* @deprecated in favor of
* {@code IntegrationUtils#wrapInDeliveryExceptionIfNecessary(Message, Supplier, Exception)}
*/
@Deprecated
protected RuntimeException wrapExceptionIfNecessary(Message<?> message, Exception e) {
RuntimeException runtimeException = (e instanceof RuntimeException)
? (RuntimeException) e
: new MessageDeliveryException(message,
"Dispatcher failed to deliver Message.", e);
if (e instanceof MessagingException &&
((MessagingException) e).getFailedMessage() == null) {
runtimeException = new MessagingException(message, "Dispatcher failed to deliver Message", e);
}
return runtimeException;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " with handlers: " + this.handlers.toString();

View File

@@ -22,6 +22,7 @@ import java.util.List;
import java.util.concurrent.Executor;
import org.springframework.integration.MessageDispatchingException;
import org.springframework.integration.support.utils.IntegrationUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.MessageHandler;
@@ -145,8 +146,8 @@ public class UnicastingDispatcher extends AbstractDispatcher {
success = true; // we have a winner.
}
catch (Exception e) {
@SuppressWarnings("deprecation")
RuntimeException runtimeException = wrapExceptionIfNecessary(message, e);
RuntimeException runtimeException = IntegrationUtils.wrapInDeliveryExceptionIfNecessary(message,
() -> "Dispatcher failed to deliver Message", e);
exceptions.add(runtimeException);
this.handleExceptions(exceptions, message, !handlerIterator.hasNext());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -135,14 +135,12 @@ public class PollingConsumer extends AbstractPollingEndpoint implements Integrat
if (!CollectionUtils.isEmpty(interceptorStack)) {
triggerAfterMessageHandled(theMessage, ex, interceptorStack);
}
// TODO: In 5.1 remove this; adding the failed message to the text is redundant
final Message<?> messageForText = theMessage;
throw IntegrationUtils.wrapInDeliveryExceptionIfNecessary(theMessage,
() -> "Failed to handle " + messageForText + " to " + this + " in " + this.handler, ex);
() -> "Failed to handle message to " + this + " in " + this.handler, ex);
}
catch (Error ex) { //NOSONAR - ok, we re-throw below
if (!CollectionUtils.isEmpty(interceptorStack)) {
String description = "Failed to handle " + theMessage + " to " + this + " in " + this.handler;
String description = "Failed to handle message to " + this + " in " + this.handler;
triggerAfterMessageHandled(theMessage,
new MessageDeliveryException(theMessage, description, ex),
interceptorStack);

View File

@@ -6,4 +6,3 @@ spring.integration.messagingTemplate.throwExceptionOnLateReply=false
# Defaults to MessageHeaders.ID and MessageHeaders.TIMESTAMP
spring.integration.readOnly.headers=
spring.integration.endpoints.noAutoStartup=
spring.integration.postProcessDynamicBeans=false

View File

@@ -22,10 +22,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -67,20 +63,6 @@ public class InterceptedSharedConnectionTests {
@Autowired
Listener listener;
private static Level existingLogLevel;
// temporary hooks to investigate CI failures
@BeforeClass
public static void setup() {
existingLogLevel = LogManager.getLogger("org.springframework.integration").getLevel();
LogManager.getLogger("org.springframework.integration").setLevel(Level.DEBUG);
}
@AfterClass
public static void tearDown() {
LogManager.getLogger("org.springframework.integration").setLevel(existingLogLevel);
}
/**
* Tests a loopback. The client-side outbound adapter sends a message over
* a connection from the client connection factory; the server side

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -27,7 +27,8 @@ import java.util.Map;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
@@ -52,7 +53,7 @@ import com.google.common.cache.CacheStats;
*/
public class StoredProcExecutorTests {
private static final Logger LOGGER = Logger.getLogger(StoredProcExecutorTests.class);
private static final Log LOGGER = LogFactory.getLog(StoredProcExecutorTests.class);
@Test
public void testStoredProcExecutorWithNullDataSource() {

View File

@@ -26,10 +26,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -54,11 +51,6 @@ public class PipelineJmsTests extends ActiveMQMultiContextTests {
@Rule
public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
@Before
public void setLogLevel() {
LogManager.getLogger(getClass()).setLevel(Level.INFO);
}
@After
public void tearDown() {
this.executor.shutdownNow();

View File

@@ -29,10 +29,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -59,11 +56,6 @@ public class PipelineNamedReplyQueuesJmsTests extends ActiveMQMultiContextTests
@Rule
public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
@Before
public void setLogLevel() {
LogManager.getLogger(getClass()).setLevel(Level.INFO);
}
@After
public void tearDown() {
this.executor.shutdownNow();

View File

@@ -250,7 +250,7 @@ public class IdempotentReceiverIntegrationTests {
@Bean
public HazelcastInstance hazelcastInstance() {
return Hazelcast.newHazelcastInstance(new Config().setProperty("hazelcast.logging.type", "log4j"));
return Hazelcast.newHazelcastInstance(new Config().setProperty("hazelcast.logging.type", "slf4j"));
}

View File

@@ -1,112 +0,0 @@
/*
* Copyright 2015-2018 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.integration.test.rule;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
/**
* A JUnit method &#064;Rule that changes the logger level for a set of classes
* or packages
* while a test method is running. Useful for performance or scalability tests
* where we don't want to generate a large log in a tight inner loop, or
* enabling debug logging for a test case.
*
* @author Dave Syer
* @author Gary Russell
*
* @deprecated since 5.0.1 in favor of {@link Log4j2LevelAdjuster}.
* Will be removed in 5.1.
*
*/
@Deprecated
@SuppressWarnings("deprecation")
public class Log4jLevelAdjuster implements MethodRule {
private static final Log logger =
LogFactory.getLog(org.springframework.integration.test.rule.Log4jLevelAdjuster.class);
private final Class<?>[] classes;
private final Level level;
private final String[] categories;
public Log4jLevelAdjuster(Level level, Class<?>... classes) {
this.level = level;
this.classes = classes;
this.categories = new String[0];
}
public Log4jLevelAdjuster(Level level, String... categories) {
this.level = level;
this.classes = new Class<?>[0];
Set<String> cats = new LinkedHashSet<String>(Arrays.asList(categories));
cats.add(getClass().getPackage().getName());
this.categories = new ArrayList<String>(cats).toArray(new String[cats.size()]);
}
@Override
public Statement apply(final Statement base, final FrameworkMethod method, Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
Map<Class<?>, Level> oldLevels = new HashMap<Class<?>, Level>();
for (Class<?> cls : classes) {
oldLevels.put(cls, LogManager.getLogger(cls).getEffectiveLevel());
LogManager.getLogger(cls).setLevel(level);
}
Map<String, Level> oldCatLevels = new HashMap<String, Level>();
for (String category : categories) {
oldCatLevels.put(category, LogManager.getLogger(category).getEffectiveLevel());
LogManager.getLogger(category).setLevel(level);
}
logger.debug("++++++++++++++++++++++++++++ "
+ "Overridden log level setting for: " + Arrays.asList(classes) + " and "
+ Arrays.asList(categories) + " for test " + method.getName());
try {
base.evaluate();
}
finally {
logger.debug("++++++++++++++++++++++++++++ "
+ "Restoring log level setting for: " + Arrays.asList(classes) + " and "
+ Arrays.asList(categories) + " for test " + method.getName());
// raw Class type used to avoid http://bugs.sun.com/view_bug.do?bug_id=6682380
for (@SuppressWarnings("rawtypes") Class cls : classes) {
LogManager.getLogger(cls).setLevel(oldLevels.get(cls));
}
for (String category : categories) {
LogManager.getLogger(category).setLevel(oldCatLevels.get(category));
}
}
}
};
}
}

View File

@@ -1,92 +0,0 @@
/*
* Copyright 2015-2018 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.integration.test.support;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestName;
/**
* Base class for module tests where logging is set to TRACE for the duration
* of the test and reverted to the previous value. Also logs a start/end
* message. Duplicated in s-i-core/src/test for use there, to avoid circular dep.
*
* @author Artem Bilan
* @author Gary Russell
*
* @since 4.2.2
*
* @deprecated since 5.0.1 in favor of {@link org.springframework.integration.test.rule.Log4j2LevelAdjuster}.
* Will be removed in 5.1.
*
*/
@Deprecated
public class LogAdjustingTestSupport {
/*
* If you make changes here, consider doing the same in the core version.
*/
@Rule
public TestName testName = new TestName();
protected final Log logger = LogFactory.getLog(this.getClass());
private final Collection<Logger> loggersToAdjust = new ArrayList<Logger>();
private final Collection<Level> oldCategories = new ArrayList<Level>();
public LogAdjustingTestSupport() {
this("org.springframework.integration");
}
public LogAdjustingTestSupport(String... loggersToAdjust) {
for (String loggerToAdjust : loggersToAdjust) {
this.loggersToAdjust.add(LogManager.getLogger(loggerToAdjust));
}
}
@Before
public void beforeTest() {
for (Logger loggerToAdjust : this.loggersToAdjust) {
this.oldCategories.add(loggerToAdjust.getEffectiveLevel());
loggerToAdjust.setLevel(Level.TRACE);
}
this.logger.warn("!!!! Starting test: " + this.testName.getMethodName() + " !!!!");
}
@After
public void afterTest() {
logger.warn("!!!! Finished test: " + this.testName.getMethodName() + " !!!!");
Iterator<Level> oldCategory = this.oldCategories.iterator();
for (Logger loggerToAdjust : this.loggersToAdjust) {
loggerToAdjust.setLevel(oldCategory.next());
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 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.
@@ -16,13 +16,12 @@
package org.springframework.integration.webflux.support;
import org.springframework.integration.http.config.HttpContextUtils;
/**
* Utility class for accessing WebFlux integration components
* from the {@link org.springframework.beans.factory.BeanFactory}.
*
* @author Artem Bilan
* @author Gary Russell
*
* @since 5.0
*/
@@ -32,16 +31,6 @@ public final class WebFluxContextUtils {
super();
}
/**
* The {@code boolean} flag to indicate if the
* {@code org.springframework.web.reactive.result.method.RequestMappingInfo}
* is present in the CLASSPATH to allow to register the Integration server reactive components.
* @deprecated since 5.0.2 in favor of {@link HttpContextUtils#WEB_FLUX_PRESENT}.
* Will be removed in the 5.1.
*/
@Deprecated
public static final boolean WEB_FLUX_PRESENT = HttpContextUtils.WEB_FLUX_PRESENT;
/**
* The name for the infrastructure
* {@link org.springframework.integration.webflux.inbound.WebFluxIntegrationRequestMappingHandlerMapping} bean.

View File

@@ -19,3 +19,17 @@ See <<amqp-strict-ordering>>.
==== Java DSL
The `IntegrationFlowContext` is now an interface and `IntegrationFlowRegistration` is an inner interface of the `IntegrationFlowContext`.
==== Dispatcher Exceptions
Exceptions caught and re-thrown by `AbstractDispatcher` are now more consistent:
- A `MessagingException` of any kind, with a `failedMessage` property, is re-thrown unchanged
- All other exceptions are wrapped in a `MessageDeliveryException` with the `failedMessage` property set
Previously:
- A `MessagingException` of any kind, with a `failedMessage` property, was re-thrown unchanged
- A `MessagingException`, with no `failedMessage` property, was wrapped in a `MessagingException` with the `failedMessage` property set
- Other `RuntimeException` s were re-thrown unchanged
- Checked exceptions were wrapped in a `MessageDeliveryException` with the `failedMessage` property set