camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1222312 - in /camel/branches/camel-2.8.x: ./ components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/ components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/
Date Thu, 22 Dec 2011 16:12:19 GMT
Author: dkulp
Date: Thu Dec 22 16:12:18 2011
New Revision: 1222312

URL: http://svn.apache.org/viewvc?rev=1222312&view=rev
Log:
Merged revisions 1209377 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1209377 | ningjiang | 2011-12-02 02:27:25 -0500 (Fri, 02 Dec 2011) | 1 line
  
  CAMEL-4732 Allow camel-freemarker template cache duration to be specified
........

Modified:
    camel/branches/camel-2.8.x/   (props changed)
    camel/branches/camel-2.8.x/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerComponent.java
    camel/branches/camel-2.8.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerContentCacheTest.java

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.8.x/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerComponent.java?rev=1222312&r1=1222311&r2=1222312&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerComponent.java
(original)
+++ camel/branches/camel-2.8.x/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerComponent.java
Thu Dec 22 16:12:18 2011
@@ -46,6 +46,10 @@ public class FreemarkerComponent extends
         boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class,
Boolean.TRUE);
         if (cache) {
             config = getConfiguration();
+            int templateUpdateDelay = getAndRemoveParameter(parameters, "templateUpdateDelay",
Integer.class, 0);
+            if (templateUpdateDelay > 0) {
+                config.setTemplateUpdateDelay(templateUpdateDelay);
+            }
         } else {
             config = getNoCacheConfiguration();
         }

Modified: camel/branches/camel-2.8.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerContentCacheTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerContentCacheTest.java?rev=1222312&r1=1222311&r2=1222312&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerContentCacheTest.java
(original)
+++ camel/branches/camel-2.8.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerContentCacheTest.java
Thu Dec 22 16:12:18 2011
@@ -72,6 +72,36 @@ public class FreemarkerContentCacheTest 
         template.sendBodyAndHeader("direct:b", "Body", "name", "Paris");
         mock.assertIsSatisfied();
     }
+    
+    @Test
+    public void testTemplateUpdateDelay() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello London");
+
+        template.sendBodyAndHeader("direct:c", "Body", "name", "London");
+        mock.assertIsSatisfied();
+
+        // now change content in the file in the classpath and try again .... with no delay
+        template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/freemarker?fileExist=Override",
"Bye ${headers.name}", Exchange.FILE_NAME, "hello.ftl");
+
+        mock.reset();
+        // we must expected the original filecontent as the cache is enabled, so its Hello
and not Bye
+        mock.expectedBodiesReceived("Hello Paris");
+
+        template.sendBodyAndHeader("direct:c", "Body", "name", "Paris");
+        mock.assertIsSatisfied();
+
+        // now change content in the file in the classpath and try again .... after delaying
longer than the cache update delay
+        Thread.sleep(5000);
+        template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/freemarker?fileExist=Override",
"Bye ${headers.name}", Exchange.FILE_NAME, "hello.ftl");
+
+        mock.reset();
+        // we must expected the new content, because the cache has expired
+        mock.expectedBodiesReceived("Bye Paris");
+        template.sendBodyAndHeader("direct:c", "Body", "name", "Paris");
+        mock.assertIsSatisfied();
+    }
+
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
@@ -79,6 +109,8 @@ public class FreemarkerContentCacheTest 
                 from("direct:a").to("freemarker://org/apache/camel/component/freemarker/hello.ftl?contentCache=false").to("mock:result");
 
                 from("direct:b").to("freemarker://org/apache/camel/component/freemarker/hello.ftl?contentCache=true").to("mock:result");
+                
+                from("direct:c").to("freemarker://org/apache/camel/component/freemarker/hello.ftl?contentCache=true&templateUpdateDelay=4").to("mock:result");
             }
         };
     }



Mime
View raw message