Merge remote-tracking branch 'upstream/master' into 4.0.0-WIP

Conflicts:
	spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInterfaceTests.java
	spring-integration-core/src/test/java/org/springframework/integration/router/config/RouterWithMappingTests.java
	spring-integration-groovy/src/main/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessor.java
	spring-integration-http/src/test/java/org/springframework/integration/http/inbound/HttpRequestHandlingMessagingGatewayWithPathMappingTests.java
	spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/store/channel/AbstractTxTimeoutMessageStoreTests.java
	spring-integration-jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java

Resolved.
This commit is contained in:
Gary Russell
2013-10-30 23:13:27 -04:00
93 changed files with 1657 additions and 787 deletions

View File

@@ -1,213 +0,0 @@
/*
* Copyright 2002-2010 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.groovy;
import static org.junit.Assert.assertEquals;
import groovy.lang.GroovyObject;
import groovy.lang.Script;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Executors;
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.Test;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.scripting.groovy.GroovyObjectCustomizer;
import org.springframework.scripting.groovy.GroovyScriptFactory;
import org.springframework.scripting.support.ResourceScriptSource;
import org.springframework.util.Assert;
/**
* @author Dave Syer
*/
public class GroovyExpressionTests {
private static Log logger = LogFactory.getLog(GroovyExpressionTests.class);
@Before
public void setLogLevel() {
LogManager.getLogger(getClass()).setLevel(Level.DEBUG);
}
@After
public void resetLogLevel() {
LogManager.getLogger(getClass()).setLevel(Level.INFO);
}
@Test
public void testScriptFactoryCustomizer() throws Exception {
Customizer customizer = new Customizer(Collections.singletonMap("name", (Object) "foo"));
GroovyScriptFactory factory = new GroovyScriptFactory("Groovy Script", customizer);
ResourceScriptSource scriptSource = new ResourceScriptSource(new NamedByteArrayResource("\"name=${name}\"".getBytes(), "InlineScript"));
Object scriptedObject = factory.getScriptedObject(scriptSource, null);
assertEquals("name=foo", scriptedObject.toString());
customizer.setMap(Collections.singletonMap("name", (Object) "bar"));
scriptedObject = factory.getScriptedObject(scriptSource, null);
assertEquals("name=bar", scriptedObject.toString());
}
@Test
public void testScriptFactoryCustomizerThreadSafety() throws Exception {
final Customizer customizer = new Customizer(Collections.singletonMap("name", (Object) "foo"));
final GroovyScriptFactory factory = new GroovyScriptFactory("Groovy Script", customizer);
final ResourceScriptSource scriptSource = new ResourceScriptSource(new NamedByteArrayResource(
"\"name=${name}\"".getBytes(), "InlineScript"));
Object scriptedObject = factory.getScriptedObject(scriptSource, null);
assertEquals("name=foo", scriptedObject.toString());
CompletionService<String> completionService = new ExecutorCompletionService<String>(Executors.newFixedThreadPool(10));
for (int i = 0; i < 100; i++) {
final String name = "bar" + i;
completionService.submit(new Callable<String>() {
public String call() throws Exception {
Object scriptedObject;
synchronized (customizer) {
customizer.setMap(Collections.singletonMap("name", (Object) name));
scriptedObject = factory.getScriptedObject(scriptSource, null);
}
String result = scriptedObject.toString();
logger.debug("Result=" + result + " with name=" + name);
if (!("name=" + name).equals(result)) {
throw new IllegalStateException("Wrong value (" + result + ") for: " + name);
}
return name;
}
});
}
Set<String> set = new HashSet<String>();
for (int i = 0; i < 100; i++) {
set.add(completionService.take().get());
}
assertEquals(100, set.size());
}
@Test
public void testScriptFactoryCustomizerStatic() throws Exception {
final Customizer customizer = new Customizer(Collections.singletonMap("name", (Object) "foo"));
final GroovyScriptFactory factory = new GroovyScriptFactory("Groovy Script", customizer);
final ResourceScriptSource scriptSource = new ResourceScriptSource(new NamedByteArrayResource(
"\"name=${name}\"".getBytes(), "InlineScript"));
Object scriptedObject = factory.getScriptedObject(scriptSource, null);
assertEquals("name=foo", scriptedObject.toString());
CompletionService<String> completionService = new ExecutorCompletionService<String>(Executors.newFixedThreadPool(10));
for (int i = 0; i < 100; i++) {
final String name = "bar" + i;
completionService.submit(new Callable<String>() {
public String call() throws Exception {
Object scriptedObject = factory.getScriptedObject(scriptSource, null);
String result = scriptedObject.toString();
logger.debug("Result=" + result + " with name=" + name);
if (!("name=foo").equals(result)) {
throw new IllegalStateException("Wrong value (" + result + ") for: " + name);
}
return name;
}
});
}
Set<String> set = new HashSet<String>();
for (int i = 0; i < 100; i++) {
set.add(completionService.take().get());
}
assertEquals(100, set.size());
}
@Test
public void testScriptFactoryCustomizerThreadSafetyWithNewScript() throws Exception {
final Customizer customizer = new Customizer(Collections.singletonMap("name", (Object) "foo"));
final GroovyScriptFactory factory = new GroovyScriptFactory("Groovy Script", customizer);
CompletionService<String> completionService = new ExecutorCompletionService<String>(Executors.newFixedThreadPool(5));
for (int i = 0; i < 100; i++) {
final String name = "Bar" + i;
completionService.submit(new Callable<String>() {
public String call() throws Exception {
Object scriptedObject;
synchronized (customizer) {
customizer.setMap(Collections.singletonMap("name", (Object) name));
ResourceScriptSource scriptSource = new ResourceScriptSource(new NamedByteArrayResource(
"\"name=${name}\"".getBytes(), "InlineScript" + name));
scriptedObject = factory.getScriptedObject(scriptSource, null);
}
String result = scriptedObject.toString();
logger.debug("Result=" + result + " with name=" + name);
if (!("name=" + name).equals(result)) {
throw new IllegalStateException("Wrong value (" + result + ") for: " + name);
}
return name;
}
});
}
Set<String> set = new HashSet<String>();
for (int i = 0; i < 100; i++) {
set.add(completionService.take().get());
}
assertEquals(100, set.size());
}
private static class Customizer implements GroovyObjectCustomizer {
private Map<String, Object> map = new HashMap<String, Object>();
public Customizer(Map<String, Object> map) {
super();
this.map.putAll(map);
}
public void customize(GroovyObject goo) {
Assert.state(goo instanceof Script, "Expected a Script");
for (Map.Entry<String, Object> entry : map.entrySet()) {
((Script) goo).getBinding().setVariable(entry.getKey(), entry.getValue());
}
}
public void setMap(Map<String, Object> map) {
this.map.clear();
this.map.putAll(map);
}
}
private static class NamedByteArrayResource extends ByteArrayResource {
private final String fileName;
public NamedByteArrayResource(byte[] bytes, String fileName) {
super(bytes);
this.fileName = fileName;
}
@Override
public String getFilename() throws IllegalStateException {
return fileName;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@@ -18,26 +18,35 @@ package org.springframework.integration.groovy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.core.io.AbstractResource;
import org.springframework.messaging.Message;
import org.springframework.integration.handler.MessageProcessor;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.scripting.RefreshableResourceScriptSource;
import org.springframework.integration.scripting.ScriptVariableGenerator;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.scripting.ScriptSource;
import org.springframework.scripting.support.ResourceScriptSource;
import org.springframework.scripting.support.StaticScriptSource;
import org.springframework.test.annotation.Repeat;
import groovy.lang.Script;
/**
* @author Mark Fisher
* @author Dave Syer
@@ -176,6 +185,43 @@ public class GroovyScriptExecutingMessageProcessorTests {
assertEquals("payload is 'hello'", result.toString());
}
@Test
public void testInt3166GroovyScriptExecutingMessageProcessorPerformance() throws Exception {
final Message<?> message = new GenericMessage<Object>("test");
final AtomicInteger var1 = new AtomicInteger();
final AtomicInteger var2 = new AtomicInteger();
String script =
"var1.incrementAndGet(); Thread.sleep(100); var2.set(Math.max(var1.get(), var2.get())); var1.decrementAndGet()";
ScriptSource scriptSource = new StaticScriptSource(script, Script.class.getName());
final MessageProcessor<Object> processor =
new GroovyScriptExecutingMessageProcessor(scriptSource, new ScriptVariableGenerator() {
@Override
public Map<String, Object> generateScriptVariables(Message<?> message) {
Map<String, Object> variables = new HashMap<String, Object>(2);
variables.put("var1", var1);
variables.put("var2", var2);
return variables;
}
});
ExecutorService executor = Executors.newFixedThreadPool(10);
for (int i = 0; i < 10; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
processor.processMessage(message);
}
});
}
executor.shutdown();
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
assertTrue(var2.get() > 1);
}
private static class TestResource extends AbstractResource {

View File

@@ -16,9 +16,9 @@
package org.springframework.integration.groovy.config;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import groovy.lang.GroovyObject;
@@ -30,6 +30,7 @@ import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanCreationNotAllowedException;
import org.springframework.beans.factory.BeanIsAbstractException;
@@ -115,6 +116,8 @@ public class GroovyControlBusTests {
Message<?> message = MessageBuilder.withPayload("def result = requestScopedService.convert('testString')").build();
this.input.send(message);
assertEquals("cat", output.receive(0).getPayload());
RequestContextHolder.resetRequestAttributes();
}
@Test //INT-2567
@@ -180,7 +183,7 @@ public class GroovyControlBusTests {
private static class MockRequestAttributes implements RequestAttributes {
private Map<String, Object> fakeRequest = new HashMap<String, Object>();
private final Map<String, Object> fakeRequest = new HashMap<String, Object>();
public Object getAttribute(String name, int scope) {
return fakeRequest.get(name);

View File

@@ -97,6 +97,7 @@ public class GroovyFilterTests {
assertTrue(this.groovyFilterMessageHandler instanceof MessageFilter);
MessageSelector selector = TestUtils.getPropertyValue(this.groovyFilterMessageHandler, "selector",
MethodInvokingSelector.class);
@SuppressWarnings("rawtypes")
MessageProcessor messageProcessor = TestUtils.getPropertyValue(selector, "messageProcessor", MessageProcessor.class);
//before it was MethodInvokingMessageProcessor
assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);

View File

@@ -107,6 +107,7 @@ public class GroovyRouterTests {
@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
assertTrue(this.groovyRouterMessageHandler instanceof MethodInvokingRouter);
@SuppressWarnings("rawtypes")
MessageProcessor messageProcessor = TestUtils.getPropertyValue(this.groovyRouterMessageHandler,
"messageProcessor", MessageProcessor.class);
//before it was MethodInvokingMessageProcessor

View File

@@ -90,7 +90,6 @@ public class GroovyServiceActivatorTests {
String value1 = (String) replyChannel.receive(0).getPayload();
String value2 = (String) replyChannel.receive(0).getPayload();
String value3 = (String) replyChannel.receive(0).getPayload();
System.out.println(value1 + "\n" + value2 + "\n" + value3);
assertTrue(value1.startsWith("groovy-test-1-foo - bar"));
assertTrue(value2.startsWith("groovy-test-2-foo - bar"));
assertTrue(value3.startsWith("groovy-test-3-foo - bar"));

View File

@@ -82,10 +82,11 @@ public class GroovySplitterTests {
@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
assertTrue(this.groovySplitterMessageHandler instanceof MethodInvokingSplitter);
MessageProcessor messageProcessor = TestUtils.getPropertyValue(this.groovySplitterMessageHandler,
assertTrue(this.groovySplitterMessageHandler instanceof MethodInvokingSplitter);
@SuppressWarnings("rawtypes")
MessageProcessor messageProcessor = TestUtils.getPropertyValue(this.groovySplitterMessageHandler,
"messageProcessor", MessageProcessor.class);
//before it was MethodInvokingMessageProcessor
//before it was MethodInvokingMessageProcessor
assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}

View File

@@ -88,11 +88,12 @@ public class GroovyTransformerTests {
@Test
public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() {
assertTrue(this.groovyTransformerMessageHandler instanceof MessageTransformingHandler);
Transformer transformer = TestUtils.getPropertyValue(this.groovyTransformerMessageHandler, "transformer", Transformer.class);
assertTrue(transformer instanceof AbstractMessageProcessingTransformer);
MessageProcessor messageProcessor = TestUtils.getPropertyValue(transformer, "messageProcessor", MessageProcessor.class);
//before it was MethodInvokingMessageProcessor
assertTrue(this.groovyTransformerMessageHandler instanceof MessageTransformingHandler);
Transformer transformer = TestUtils.getPropertyValue(this.groovyTransformerMessageHandler, "transformer", Transformer.class);
assertTrue(transformer instanceof AbstractMessageProcessingTransformer);
@SuppressWarnings("rawtypes")
MessageProcessor messageProcessor = TestUtils.getPropertyValue(transformer, "messageProcessor", MessageProcessor.class);
//before it was MethodInvokingMessageProcessor
assertTrue(messageProcessor instanceof GroovyScriptExecutingMessageProcessor);
}
}