INT-550: Optimize AbstractIntNamespaceHandler

JIRA: https://jira.spring.io/browse/INT-550

* We need verify schema version and register `IntegrationRegistrar`
only once, not on parsing each element
* `@Ignore` time-sensitive `GroovyScriptExecutingMessageProcessorTests`
* Upgrade to Gradle-4.3.1 to overcome NPE with caches
This commit is contained in:
Artem Bilan
2017-11-17 16:53:19 -05:00
committed by Gary Russell
parent 41a47171c2
commit f3072af192
4 changed files with 30 additions and 15 deletions

Binary file not shown.

View File

@@ -1,6 +1,5 @@
#Wed Sep 06 12:46:29 EDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-bin.zip

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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,6 +16,8 @@
package org.springframework.integration.config.xml;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Element;
@@ -42,24 +44,29 @@ import org.springframework.util.StringUtils;
*/
public abstract class AbstractIntegrationNamespaceHandler implements NamespaceHandler {
protected final Log logger = LogFactory.getLog(this.getClass());
private static final String VERSION = "5.0";
protected final Log logger = LogFactory.getLog(this.getClass());
private final NamespaceHandlerDelegate delegate = new NamespaceHandlerDelegate();
private final AtomicBoolean initialized = new AtomicBoolean();
@Override
public final BeanDefinition parse(Element element, ParserContext parserContext) {
this.verifySchemaVersion(element, parserContext);
IntegrationRegistrar integrationRegistrar = new IntegrationRegistrar();
integrationRegistrar.setBeanClassLoader(parserContext.getReaderContext().getBeanClassLoader());
integrationRegistrar.registerBeanDefinitions(null, parserContext.getRegistry());
if (!this.initialized.getAndSet(true)) {
verifySchemaVersion(element, parserContext);
IntegrationRegistrar integrationRegistrar = new IntegrationRegistrar();
integrationRegistrar.setBeanClassLoader(parserContext.getReaderContext().getBeanClassLoader());
integrationRegistrar.registerBeanDefinitions(null, parserContext.getRegistry());
}
return this.delegate.parse(element, parserContext);
}
@Override
public final BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder definition, ParserContext parserContext) {
public final BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder definition,
ParserContext parserContext) {
return this.delegate.decorate(source, definition, parserContext);
}
@@ -67,7 +74,9 @@ public abstract class AbstractIntegrationNamespaceHandler implements NamespaceHa
this.delegate.doRegisterBeanDefinitionDecorator(elementName, decorator);
}
protected final void registerBeanDefinitionDecoratorForAttribute(String attributeName, BeanDefinitionDecorator decorator) {
protected final void registerBeanDefinitionDecoratorForAttribute(String attributeName,
BeanDefinitionDecorator decorator) {
this.delegate.doRegisterBeanDefinitionDecoratorForAttribute(attributeName, decorator);
}
@@ -79,7 +88,8 @@ public abstract class AbstractIntegrationNamespaceHandler implements NamespaceHa
if (!(matchesVersion(element) && matchesVersion(element.getOwnerDocument().getDocumentElement()))) {
parserContext.getReaderContext().error(
"You cannot use prior versions of Spring Integration schemas with Spring Integration " + VERSION +
". Please upgrade your schema declarations or use versionless aliases (e.g. spring-integration.xsd).", element);
". Please upgrade your schema declarations " +
"or use versionless aliases (e.g. spring-integration.xsd).", element);
}
}
@@ -106,7 +116,9 @@ public abstract class AbstractIntegrationNamespaceHandler implements NamespaceHa
super.registerBeanDefinitionDecorator(elementName, decorator);
}
private void doRegisterBeanDefinitionDecoratorForAttribute(String attributeName, BeanDefinitionDecorator decorator) {
private void doRegisterBeanDefinitionDecoratorForAttribute(String attributeName,
BeanDefinitionDecorator decorator) {
super.registerBeanDefinitionDecoratorForAttribute(attributeName, decorator);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -30,6 +30,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@@ -52,6 +53,7 @@ import groovy.lang.Script;
* @author Dave Syer
* @author Oleg Zhurakousky
* @author Artem Bilan
*
* @since 2.0
*/
public class GroovyScriptExecutingMessageProcessorTests {
@@ -83,6 +85,7 @@ public class GroovyScriptExecutingMessageProcessorTests {
ScriptSource scriptSource = new ResourceScriptSource(resource);
Object result = null;
class CustomScriptVariableGenerator implements ScriptVariableGenerator {
@Override
public Map<String, Object> generateScriptVariables(Message<?> message) {
Map<String, Object> variables = new HashMap<String, Object>();
@@ -125,6 +128,7 @@ public class GroovyScriptExecutingMessageProcessorTests {
}
@Test
@Ignore("Very sensitive to the time")
public void testRefreshableScriptExecution() throws Exception {
String script = "return \"payload is $payload, header is $headers.testHeader\"";
Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar").build();
@@ -134,7 +138,7 @@ public class GroovyScriptExecutingMessageProcessorTests {
// should be the original script
Object result = processor.processMessage(message);
assertEquals("payload is foo, header is bar", result.toString());
//reset the script with the new strimg
//reset the script with the new string
resource.setScript("return \"payload is $payload\"");
Thread.sleep(20L);
// should still assert to the old script because not enough time elapsed for refresh to kick in