camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject git commit: CAMEL-6476: Introducing StreamCachingStrategy SPI to make it easier to configure and allow 3rd party to plugin custom strategies. Work in progress.
Date Fri, 19 Jul 2013 11:18:13 GMT
Updated Branches:
  refs/heads/master a9ec7554d -> df4210b37


CAMEL-6476: Introducing StreamCachingStrategy SPI to make it easier to configure and allow
3rd party to plugin custom strategies. Work in progress.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/df4210b3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/df4210b3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/df4210b3

Branch: refs/heads/master
Commit: df4210b3769ee2ac14aba486b79f521ec08b1c32
Parents: a9ec755
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Jul 19 11:04:23 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Jul 19 13:18:01 2013 +0200

----------------------------------------------------------------------
 .../ManagedStreamCachingStrategyMBean.java      |  3 +
 .../properties/PropertiesComponent.java         | 33 +-------
 .../impl/DefaultManagementNameStrategy.java     |  8 +-
 .../impl/DefaultStreamCachingStrategy.java      | 62 +++++++++++++--
 .../mbean/ManagedStreamCachingStrategy.java     |  4 +
 .../camel/spi/ManagementNameStrategy.java       | 11 +++
 .../apache/camel/spi/StreamCachingStrategy.java |  5 ++
 .../org/apache/camel/util/FilePathResolver.java | 80 ++++++++++++++++++++
 .../java/org/apache/camel/util/FileUtil.java    |  7 +-
 .../ManagedStreamCachingStrategyTest.java       | 13 +++-
 .../apache/camel/util/FilePathResolverTest.java | 32 ++++++++
 11 files changed, 211 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedStreamCachingStrategyMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedStreamCachingStrategyMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedStreamCachingStrategyMBean.java
index 4ce4583..d9887b2 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedStreamCachingStrategyMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedStreamCachingStrategyMBean.java
@@ -47,4 +47,7 @@ public interface ManagedStreamCachingStrategyMBean {
     @ManagedAttribute(description = "Whether to remove spool directory when stopping")
     boolean isRemoveSpoolDirectoryWhenStopping();
 
+    @ManagedAttribute(description = "Number of StreamCache created")
+    long getCacheCounter();
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index be2efef..605a117 100644
--- a/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -25,6 +25,7 @@ import java.util.regex.Pattern;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.FilePathResolver;
 import org.apache.camel.util.LRUSoftCache;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
@@ -67,10 +68,6 @@ public class PropertiesComponent extends DefaultComponent {
      */
     public static final String OVERRIDE_PROPERTIES = PropertiesComponent.class.getName()
+ ".OverrideProperties";
 
-    // must be non greedy patterns
-    private static final Pattern ENV_PATTERN = Pattern.compile("\\$\\{env:(.*?)\\}", Pattern.DOTALL);
-    private static final Pattern SYS_PATTERN = Pattern.compile("\\$\\{(.*?)\\}", Pattern.DOTALL);
-
     private static final transient Logger LOG = LoggerFactory.getLogger(PropertiesComponent.class);
     private final Map<CacheKey, Properties> cacheMap = new LRUSoftCache<CacheKey,
Properties>(1000);
     private PropertiesResolver propertiesResolver = new DefaultPropertiesResolver();
@@ -292,33 +289,7 @@ public class PropertiesComponent extends DefaultComponent {
             String location = locations[i];
             LOG.trace("Parsing location: {} ", location);
 
-            Matcher matcher = ENV_PATTERN.matcher(location);
-            while (matcher.find()) {
-                String key = matcher.group(1);
-                String value = System.getenv(key);
-                if (ObjectHelper.isEmpty(value)) {
-                    throw new IllegalArgumentException("Cannot find system environment with
key: " + key);
-                }
-                // must quote the replacement to have it work as literal replacement
-                value = Matcher.quoteReplacement(value);
-                location = matcher.replaceFirst(value);
-                // must match again as location is changed
-                matcher = ENV_PATTERN.matcher(location);
-            }
-
-            matcher = SYS_PATTERN.matcher(location);
-            while (matcher.find()) {
-                String key = matcher.group(1);
-                String value = System.getProperty(key);
-                if (ObjectHelper.isEmpty(value)) {
-                    throw new IllegalArgumentException("Cannot find JVM system property with
key: " + key);
-                }
-                // must quote the replacement to have it work as literal replacement
-                value = Matcher.quoteReplacement(value);
-                location = matcher.replaceFirst(value);
-                // must match again as location is changed
-                matcher = SYS_PATTERN.matcher(location);
-            }
+            location = FilePathResolver.resolvePath(location);
 
             LOG.debug("Parsed location: {} ", location);
             answer[i] = location;

http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/main/java/org/apache/camel/impl/DefaultManagementNameStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultManagementNameStrategy.java
b/camel-core/src/main/java/org/apache/camel/impl/DefaultManagementNameStrategy.java
index 7455c3e..efc0be0 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultManagementNameStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultManagementNameStrategy.java
@@ -69,7 +69,7 @@ public class DefaultManagementNameStrategy implements ManagementNameStrategy
{
                 // fallback and use the default pattern which is the same name as the CamelContext
has been given
                 pattern = defaultPattern;
             }
-            name = resolveManagementName(pattern, camelContext.getName());
+            name = resolveManagementName(pattern, camelContext.getName(), true);
         }
         return name;
     }
@@ -86,7 +86,7 @@ public class DefaultManagementNameStrategy implements ManagementNameStrategy
{
                 // use a pattern that has a counter to ensure unique next name
                 pattern = nextPattern;
             }
-            return resolveManagementName(pattern, camelContext.getName());
+            return resolveManagementName(pattern, camelContext.getName(), true);
         }
     }
 
@@ -109,7 +109,7 @@ public class DefaultManagementNameStrategy implements ManagementNameStrategy
{
      * @return the management name
      * @throws IllegalArgumentException if the pattern or name is invalid or empty
      */
-    protected String resolveManagementName(String pattern, String name) {
+    public String resolveManagementName(String pattern, String name, boolean invalidCheck)
{
         ObjectHelper.notEmpty(pattern, "pattern");
         ObjectHelper.notEmpty(name, "name");
 
@@ -131,7 +131,7 @@ public class DefaultManagementNameStrategy implements ManagementNameStrategy
{
         answer = customResolveManagementName(pattern, answer);
 
         // are there any #word# combos left, if so they should be considered invalid tokens
-        if (INVALID_PATTERN.matcher(answer).matches()) {
+        if (invalidCheck && INVALID_PATTERN.matcher(answer).matches()) {
             throw new IllegalArgumentException("Pattern is invalid: " + pattern);
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
b/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
index 0b28cd6..0fcbf07 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
@@ -17,12 +17,14 @@
 package org.apache.camel.impl;
 
 import java.io.File;
+import java.util.UUID;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.Exchange;
 import org.apache.camel.StreamCache;
 import org.apache.camel.spi.StreamCachingStrategy;
+import org.apache.camel.util.FilePathResolver;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.IOHelper;
 import org.slf4j.Logger;
@@ -33,7 +35,10 @@ import org.slf4j.LoggerFactory;
  */
 public class DefaultStreamCachingStrategy extends org.apache.camel.support.ServiceSupport
implements CamelContextAware, StreamCachingStrategy {
 
-    // TODO: Maybe use #syntax# for default temp dir so ppl can easily configure this
+    // TODO: add JMX counters for in memory vs spooled
+    // TODO: Add support for mark
+    // TODO: logic for spool to disk in this class so we can control this
+    // TODO: add memory based watermarks for spool to disk
 
     @Deprecated
     public static final String THRESHOLD = "CamelCachedOutputStreamThreshold";
@@ -49,10 +54,12 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi
     private CamelContext camelContext;
     private boolean enabled;
     private File spoolDirectory;
+    private transient String spoolDirectoryName = "${java.io.tmpdir}camel-tmp-#uuid#";
     private long spoolThreshold = StreamCache.DEFAULT_SPOOL_THRESHOLD;
     private String spoolChiper;
     private int bufferSize = IOHelper.DEFAULT_BUFFER_SIZE;
     private boolean removeSpoolDirectoryWhenStopping = true;
+    private volatile long cacheCounter;
 
     public CamelContext getCamelContext() {
         return camelContext;
@@ -71,7 +78,7 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi
     }
 
     public void setSpoolDirectory(String path) {
-        this.spoolDirectory = new File(path);
+        this.spoolDirectoryName = path;
     }
 
     public void setSpoolDirectory(File path) {
@@ -114,8 +121,16 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi
         this.removeSpoolDirectoryWhenStopping = removeSpoolDirectoryWhenStopping;
     }
 
+    public long getCacheCounter() {
+        return cacheCounter;
+    }
+
     public StreamCache cache(Exchange exchange) {
-        return exchange.getIn().getBody(StreamCache.class);
+        StreamCache cache = exchange.getIn().getBody(StreamCache.class);
+        if (cache != null) {
+            cacheCounter++;
+        }
+        return cache;
     }
 
     @Override
@@ -153,11 +168,20 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi
 
         // if we can overflow to disk then make sure directory exists / is created
         if (spoolThreshold > 0) {
-            // create random temporary directory if none has been created
-            if (spoolDirectory == null) {
-                spoolDirectory = FileUtil.createNewTempDir();
-                LOG.debug("Created temporary spool directory: {}", spoolDirectory);
-            } else if (spoolDirectory.exists()) {
+
+            if (spoolDirectory == null && spoolDirectoryName == null) {
+                throw new IllegalArgumentException("SpoolDirectory must be configured when
using SpoolThreshold > 0");
+            }
+
+            if (spoolDirectory == null && spoolDirectoryName != null) {
+                String name = resolveSpoolDirectory(spoolDirectoryName);
+                if (name != null) {
+                    spoolDirectory = new File(name);
+                    spoolDirectoryName = null;
+                }
+            }
+
+            if (spoolDirectory.exists()) {
                 if (spoolDirectory.isDirectory()) {
                     LOG.debug("Using spool directory: {}", spoolDirectory);
                 } else {
@@ -182,12 +206,34 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi
         }
     }
 
+    protected String resolveSpoolDirectory(String path) {
+        String name = camelContext.getManagementNameStrategy().resolveManagementName(path,
camelContext.getName(), false);
+        if (name != null) {
+            name = customResolveManagementName(name);
+        }
+        // and then check again with invalid check to ensure all ## is resolved
+        if (name != null) {
+            name = camelContext.getManagementNameStrategy().resolveManagementName(name, camelContext.getName(),
true);
+        }
+        return name;
+    }
+
+    protected String customResolveManagementName(String pattern) {
+        if (pattern.contains("#uuid#")) {
+            String uuid = UUID.randomUUID().toString();
+            pattern = pattern.replaceFirst("#uuid#", uuid);
+        }
+        return FilePathResolver.resolvePath(pattern);
+    }
+
     @Override
     protected void doStop() throws Exception {
         if (spoolThreshold > 0 & spoolDirectory != null  && isRemoveSpoolDirectoryWhenStopping())
{
             LOG.debug("Removing spool directory: {}", spoolDirectory);
             FileUtil.removeDir(spoolDirectory);
         }
+
+        cacheCounter = 0;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedStreamCachingStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedStreamCachingStrategy.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedStreamCachingStrategy.java
index 7a7d511..f20ee87 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedStreamCachingStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedStreamCachingStrategy.java
@@ -81,4 +81,8 @@ public class ManagedStreamCachingStrategy extends ManagedService implements
Mana
     public boolean isRemoveSpoolDirectoryWhenStopping() {
         return streamCachingStrategy.isRemoveSpoolDirectoryWhenStopping();
     }
+
+    public long getCacheCounter() {
+        return streamCachingStrategy.getCacheCounter();
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/main/java/org/apache/camel/spi/ManagementNameStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/ManagementNameStrategy.java b/camel-core/src/main/java/org/apache/camel/spi/ManagementNameStrategy.java
index 5ed65dc..053dac7 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/ManagementNameStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/ManagementNameStrategy.java
@@ -77,4 +77,15 @@ public interface ManagementNameStrategy {
      * @return <tt>true</tt> for fixed names, <tt>false</tt> for
names which can re-calculated
      */
     boolean isFixedName();
+
+    /**
+     * Creates a new management name with the given pattern.
+     *
+     * @param pattern the pattern
+     * @param name    the name
+     * @param invalidCheck whether to check for invalid pattern
+     * @return the management name
+     * @throws IllegalArgumentException if the pattern or name is invalid or empty
+     */
+    String resolveManagementName(String pattern, String name, boolean invalidCheck);
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java b/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
index fe75702..d7d6f39 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
@@ -86,6 +86,11 @@ public interface StreamCachingStrategy extends Service {
     boolean isRemoveSpoolDirectoryWhenStopping();
 
     /**
+     * Gets the counter for number of {@link StreamCache} created.
+     */
+    long getCacheCounter();
+
+    /**
      * Caches the body aas a {@link StreamCache}.
      *
      * @param exchange the exchange

http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/main/java/org/apache/camel/util/FilePathResolver.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FilePathResolver.java b/camel-core/src/main/java/org/apache/camel/util/FilePathResolver.java
new file mode 100644
index 0000000..eae06eb
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/util/FilePathResolver.java
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.util;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A resolver for file paths that supports resolving with system and environment properties.
+ */
+public final class FilePathResolver {
+
+    // must be non greedy patterns
+    private static final Pattern ENV_PATTERN = Pattern.compile("\\$\\{env:(.*?)\\}", Pattern.DOTALL);
+    private static final Pattern SYS_PATTERN = Pattern.compile("\\$\\{(.*?)\\}", Pattern.DOTALL);
+
+    private FilePathResolver() {
+    }
+
+    /**
+     * Resolves the path.
+     * <p/>
+     * The pattern is:
+     * <ul>
+     *   <li><tt>${env.key}</tt> for environment variables.</li>
+     *   <li><tt>${key}</tt> for JVM system properties.</li>
+     * </ul>
+     * For example: <tt>${env.KARAF_HOME}/data/logs</tt>
+     *
+     * @param path  the path
+     * @return the resolved path
+     * @throws IllegalArgumentException is thrown if system property / environment not found
+     */
+    public static String resolvePath(String path) throws IllegalArgumentException {
+        Matcher matcher = ENV_PATTERN.matcher(path);
+        while (matcher.find()) {
+            String key = matcher.group(1);
+            String value = System.getenv(key);
+            if (ObjectHelper.isEmpty(value)) {
+                throw new IllegalArgumentException("Cannot find system environment with key:
" + key);
+            }
+            // must quote the replacement to have it work as literal replacement
+            value = Matcher.quoteReplacement(value);
+            path = matcher.replaceFirst(value);
+            // must match again as location is changed
+            matcher = ENV_PATTERN.matcher(path);
+        }
+
+        matcher = SYS_PATTERN.matcher(path);
+        while (matcher.find()) {
+            String key = matcher.group(1);
+            String value = System.getProperty(key);
+            if (ObjectHelper.isEmpty(value)) {
+                throw new IllegalArgumentException("Cannot find JVM system property with
key: " + key);
+            }
+            // must quote the replacement to have it work as literal replacement
+            value = Matcher.quoteReplacement(value);
+            path = matcher.replaceFirst(value);
+            // must match again as location is changed
+            matcher = SYS_PATTERN.matcher(path);
+        }
+
+        return path;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
index 22b691d..3eabe85 100644
--- a/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
+++ b/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
@@ -76,11 +76,13 @@ public final class FileUtil {
         return osName.indexOf("windows") > -1;
     }
 
+    @Deprecated
     public static File createTempFile(String prefix, String suffix) throws IOException {
         return createTempFile(prefix, suffix, null);
     }
 
     public static File createTempFile(String prefix, String suffix, File parentDir) throws
IOException {
+        // TODO: parentDir should be mandatory
         File parent = (parentDir == null) ? getDefaultTempDir() : parentDir;
             
         if (suffix == null) {
@@ -280,6 +282,7 @@ public final class FileUtil {
         return sb.toString();
     }
 
+    @Deprecated
     private static synchronized File getDefaultTempDir() {
         if (defaultTempDir != null && defaultTempDir.exists()) {
             return defaultTempDir;
@@ -302,7 +305,8 @@ public final class FileUtil {
     /**
      * Creates a new temporary directory in the <tt>java.io.tmpdir</tt> directory.
      */
-    public static File createNewTempDir() {
+    @Deprecated
+    private static File createNewTempDir() {
         String s = System.getProperty("java.io.tmpdir");
         File checkExists = new File(s);
         if (!checkExists.exists()) {
@@ -328,6 +332,7 @@ public final class FileUtil {
     /**
      * Shutdown and cleanup the temporary directory and removes any shutdown hooks in use.
      */
+    @Deprecated
     public static synchronized void shutdown() {
         if (defaultTempDir != null && defaultTempDir.exists()) {
             removeDir(defaultTempDir);

http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/test/java/org/apache/camel/management/ManagedStreamCachingStrategyTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedStreamCachingStrategyTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedStreamCachingStrategyTest.java
index b80b0b1..e91d7dc 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedStreamCachingStrategyTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedStreamCachingStrategyTest.java
@@ -22,6 +22,7 @@ import javax.management.ObjectName;
 
 import org.apache.camel.StreamCache;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.util.IOHelper;
 
 /**
@@ -32,7 +33,7 @@ public class ManagedStreamCachingStrategyTest extends ManagementTestSupport
{
     public void testStreamCachingStrategy() throws Exception {
         MBeanServer mbeanServer = getMBeanServer();
 
-        ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=services,*");
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/myCamel,type=services,*");
 
         // number of services
         Set<ObjectName> names = mbeanServer.queryNames(on, null);
@@ -49,7 +50,7 @@ public class ManagedStreamCachingStrategyTest extends ManagementTestSupport
{
         assertEquals(Boolean.TRUE, enabled);
 
         String dir = (String) mbeanServer.getAttribute(name, "SpoolDirectory");
-        assertEquals("target/cachedir", dir);
+        assertEquals("target/cachedir/myCamel", dir);
 
         Long threshold = (Long) mbeanServer.getAttribute(name, "SpoolThreshold");
         assertEquals(StreamCache.DEFAULT_SPOOL_THRESHOLD, threshold.longValue());
@@ -57,6 +58,9 @@ public class ManagedStreamCachingStrategyTest extends ManagementTestSupport
{
         Integer size = (Integer) mbeanServer.getAttribute(name, "BufferSize");
         assertEquals(IOHelper.DEFAULT_BUFFER_SIZE, size.intValue());
 
+        Long counter = (Long) mbeanServer.getAttribute(name, "CacheCounter");
+        assertEquals(0, counter.longValue());
+
         String chiper = (String) mbeanServer.getAttribute(name, "SpoolChiper");
         assertNull(chiper);
 
@@ -69,8 +73,11 @@ public class ManagedStreamCachingStrategyTest extends ManagementTestSupport
{
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
+                DefaultCamelContext dcc = (DefaultCamelContext) context;
+                dcc.setName("myCamel");
+
                 context.setStreamCaching(true);
-                context.getStreamCachingStrategy().setSpoolDirectory("target/cachedir");
+                context.getStreamCachingStrategy().setSpoolDirectory("target/cachedir/#name#/");
 
                 from("direct:start").routeId("foo")
                     .convertBodyTo(int.class)

http://git-wip-us.apache.org/repos/asf/camel/blob/df4210b3/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java b/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java
new file mode 100644
index 0000000..cc05b0c
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.camel.util;
+
+import junit.framework.TestCase;
+
+public class FilePathResolverTest extends TestCase {
+
+    public void testFilePathResolver() throws Exception {
+        assertEquals("/foo/bar", FilePathResolver.resolvePath("/foo/bar"));
+
+        String tmp = System.getProperty("java.io.tmpdir");
+        assertEquals(tmp + "foo", FilePathResolver.resolvePath("${java.io.tmpdir}foo"));
+
+        System.setProperty("beer", "Carlsberg");
+        assertEquals(tmp + "foo/Carlsberg", FilePathResolver.resolvePath("${java.io.tmpdir}foo/${beer}"));
+    }
+}


Mime
View raw message