From 552432c7d5a4fb3b94ad9ef06d9c424cff4cd7ff Mon Sep 17 00:00:00 2001 From: David Syer Date: Thu, 2 Sep 2010 06:46:00 +0000 Subject: [PATCH] Patch for groovy support from Oleg --- .../RefreshableResourceScriptSource.java | 4 +--- ...yScriptExecutingMessageProcessorTests.java | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSource.java b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSource.java index 0cf7f7e669..360c94bae9 100644 --- a/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSource.java +++ b/spring-integration-groovy/src/main/java/org/springframework/integration/groovy/config/RefreshableResourceScriptSource.java @@ -50,9 +50,7 @@ public class RefreshableResourceScriptSource implements ScriptSource { } public String getScriptAsString() throws IOException { - if (isModified()) { - this.script = source.getScriptAsString(); - } + this.script = source.getScriptAsString(); return script; } diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessorTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessorTests.java index e365eb2e9f..ec02aa0243 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessorTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/GroovyScriptExecutingMessageProcessorTests.java @@ -79,10 +79,21 @@ public class GroovyScriptExecutingMessageProcessorTests { TestResource resource = new TestResource(script, "simpleTest"); ScriptSource scriptSource = new RefreshableResourceScriptSource(resource, 1000L); MessageProcessor processor = new GroovyScriptExecutingMessageProcessor(scriptSource); - Thread.sleep(20L); - resource.setScript("return \"payload is $payload\""); + // 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 + 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 + result = processor.processMessage(message); + assertEquals("payload is foo, header is bar", result.toString()); + // sleep some more, past refresh time + Thread.sleep(1000L); + // now you go the new script + resource.setScript("return \"payload is $payload\""); + result = processor.processMessage(message); + assertEquals("payload is foo", result.toString()); } @Test @@ -92,9 +103,14 @@ public class GroovyScriptExecutingMessageProcessorTests { TestResource resource = new TestResource(script, "simpleTest"); ScriptSource scriptSource = new RefreshableResourceScriptSource(resource, -1L); MessageProcessor processor = new GroovyScriptExecutingMessageProcessor(scriptSource); - resource.setScript("return \"payload is $payload\""); + // process with the first script Object result = processor.processMessage(message); assertEquals("payload is foo, header is bar", result.toString()); + // change script, but since refresh-delay is less then 0 we should still se old script executing + resource.setScript("return \"payload is $payload\""); + // process and see assert that the old script is used + result = processor.processMessage(message); + assertEquals("payload is foo, header is bar", result.toString()); }