You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by he...@apache.org on 2013/10/31 21:33:49 UTC
git commit: [CAMEL-6919] Now FileIdempotentRepository creates parent
directory of repo file if necessary.
Updated Branches:
refs/heads/master d662d94f4 -> 8d263fd38
[CAMEL-6919] Now FileIdempotentRepository creates parent directory of repo file if necessary.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8d263fd3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8d263fd3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8d263fd3
Branch: refs/heads/master
Commit: 8d263fd38b419c11a0a8465db4b2514aae35bd53
Parents: d662d94
Author: Henryk Konsek <he...@gmail.com>
Authored: Thu Oct 31 21:33:36 2013 +0100
Committer: Henryk Konsek <he...@gmail.com>
Committed: Thu Oct 31 21:33:36 2013 +0100
----------------------------------------------------------------------
.../idempotent/FileIdempotentRepository.java | 10 +++++
.../FileIdempotentConsumerCreateRepoTest.java | 45 ++++++++++++++++++++
2 files changed, 55 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8d263fd3/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java b/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
index c1d0704..921b4a4 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
@@ -230,6 +230,16 @@ public class FileIdempotentRepository extends ServiceSupport implements Idempote
LOG.debug("Appending {} to idempotent filestore: {}", messageId, fileStore);
FileOutputStream fos = null;
try {
+ // create store parent directory if missing
+ File storeParentDirectory = fileStore.getParentFile();
+ if (storeParentDirectory != null && !storeParentDirectory.exists()) {
+ LOG.info("Parent directory of file store {} doesn't exist. Creating.", fileStore);
+ if (fileStore.getParentFile().mkdirs()) {
+ LOG.info("Parent directory of file store {} successfully created.", fileStore);
+ } else {
+ LOG.warn("Parent directory of file store {} cannot be created.", fileStore);
+ }
+ }
// create store if missing
if (!fileStore.exists()) {
FileUtil.createNewFile(fileStore);
http://git-wip-us.apache.org/repos/asf/camel/blob/8d263fd3/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerCreateRepoTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerCreateRepoTest.java b/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerCreateRepoTest.java
new file mode 100644
index 0000000..bdfd923
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerCreateRepoTest.java
@@ -0,0 +1,45 @@
+/**
+ * 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.processor;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.camel.spi.IdempotentRepository;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.apache.camel.processor.idempotent.FileIdempotentRepository.fileIdempotentRepository;
+
+public class FileIdempotentConsumerCreateRepoTest extends Assert {
+
+ @Test
+ public void shouldCreateParentOfRepositoryFileStore() throws IOException {
+ // Given
+ File tmpDir = new File(System.getProperty("java.io.tmpdir"));
+ File storeParent = new File(tmpDir, "repositoryParent");
+ File store = new File(storeParent, "repository");
+ IdempotentRepository<String> repo = fileIdempotentRepository(store);
+
+ // When
+ repo.add("anyKey");
+
+ // Then
+ assertTrue(store.exists());
+ }
+
+}
\ No newline at end of file