You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/03/08 17:41:29 UTC
camel git commit: CAMEL-9681 - Add an option to enable/disable cache
creation
Repository: camel
Updated Branches:
refs/heads/master 72141c6d6 -> ef4cc80b8
CAMEL-9681 - Add an option to enable/disable cache creation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ef4cc80b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ef4cc80b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ef4cc80b
Branch: refs/heads/master
Commit: ef4cc80b8b0afa2618a026ff1cffabd27769a826
Parents: 72141c6
Author: lburgazzoli <lb...@gmail.com>
Authored: Tue Mar 8 15:39:31 2016 +0100
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Mar 8 15:39:31 2016 +0100
----------------------------------------------------------------------
.../component/jcache/JCacheConfiguration.java | 14 +++++++
.../camel/component/jcache/JCacheManager.java | 5 +++
.../component/jcache/JCacheManagerTest.java | 42 ++++++++++++++++++++
.../src/test/resources/log4j.properties | 2 -
4 files changed, 61 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ef4cc80b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheConfiguration.java b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheConfiguration.java
index af83153..0002845 100644
--- a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheConfiguration.java
+++ b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheConfiguration.java
@@ -88,6 +88,8 @@ public class JCacheConfiguration {
@UriParam(label = "producer")
private String action;
+ @UriParam(label = "advanced", defaultValue = "true")
+ private boolean createCacheIfNotExists = true;
private final CamelContext camelContext;
@@ -299,4 +301,16 @@ public class JCacheConfiguration {
public void setAction(String action) {
this.action = action;
}
+
+ public boolean isCreateCacheIfNotExists() {
+ return createCacheIfNotExists;
+ }
+
+ /**
+ * Configure if a cache need to be created if it does exist or can't be
+ * pre-configured.
+ */
+ public void setCreateCacheIfNotExists(boolean createCacheIfNotExists) {
+ this.createCacheIfNotExists = createCacheIfNotExists;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/ef4cc80b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheManager.java
----------------------------------------------------------------------
diff --git a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheManager.java b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheManager.java
index 5ec98b2..bb86e08 100644
--- a/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheManager.java
+++ b/components/camel-jcache/src/main/java/org/apache/camel/component/jcache/JCacheManager.java
@@ -96,6 +96,11 @@ public class JCacheManager<K, V> implements Closeable {
cache = manager.getCache(cacheName);
if (cache == null) {
+ if (!configuration.isCreateCacheIfNotExists()) {
+ throw new IllegalStateException(
+ "Cache " + cacheName + " does not exist and should not be created (createCacheIfNotExists=false)");
+ }
+
cache = manager.createCache(
cacheName,
getOrCreateCacheConfiguration());
http://git-wip-us.apache.org/repos/asf/camel/blob/ef4cc80b/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheManagerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheManagerTest.java b/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheManagerTest.java
new file mode 100644
index 0000000..3eb98b1
--- /dev/null
+++ b/components/camel-jcache/src/test/java/org/apache/camel/component/jcache/JCacheManagerTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.component.jcache;
+
+import org.junit.Test;
+
+public class JCacheManagerTest extends JCacheComponentTestSupport {
+
+ @Test
+ public void testCacheCreation() throws Exception {
+ JCacheConfiguration conf = new JCacheConfiguration();
+
+ JCacheManager<Object, Object> manager = new JCacheManager<>(conf, randomString());
+ assertNotNull(manager.getCache());
+
+ manager.close();
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testCacheCreationFailure() throws Exception {
+ JCacheConfiguration conf = new JCacheConfiguration();
+ conf.setCreateCacheIfNotExists(false);
+
+ new JCacheManager<>(conf, randomString()).getCache();
+
+ fail("Should have raised IllegalStateException");
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/ef4cc80b/components/camel-jcache/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-jcache/src/test/resources/log4j.properties b/components/camel-jcache/src/test/resources/log4j.properties
index 6290fb2..b2324eb 100644
--- a/components/camel-jcache/src/test/resources/log4j.properties
+++ b/components/camel-jcache/src/test/resources/log4j.properties
@@ -18,8 +18,6 @@
#
# The logging properties used during tests..
#
-#log4j.rootLogger=INFO, file
-
log4j.rootLogger=INFO, file
#log4j.logger.org.apache.camel.component.jcache=DEBUG