camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [12/13] camel git commit: CAMEL-8727: File consumer - Add read lock that is based on idempotent repository
Date Sun, 03 May 2015 09:04:06 GMT
CAMEL-8727: File consumer - Add read lock that is based on idempotent repository


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

Branch: refs/heads/master
Commit: 51f8742d0952d95f9bff8e899f9fd2e19401ce8c
Parents: 411c944
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun May 3 11:05:02 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun May 3 11:05:02 2015 +0200

----------------------------------------------------------------------
 ...empotentReadLockRemoveOnCommitFalseTest.java | 61 ++++++++++++++
 .../strategy/FileIdempotentReadLockTest.java    | 87 ++++++++++++++++++++
 2 files changed, 148 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/51f8742d/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileIdempotentReadLockRemoveOnCommitFalseTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileIdempotentReadLockRemoveOnCommitFalseTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileIdempotentReadLockRemoveOnCommitFalseTest.java
new file mode 100644
index 0000000..854f106
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileIdempotentReadLockRemoveOnCommitFalseTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.file.strategy;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version
+ */
+public class FileIdempotentReadLockRemoveOnCommitFalseTest extends FileIdempotentReadLockTest
{
+
+    @Override
+    public void testIdempotentReadLock() throws Exception {
+        assertEquals(0, myRepo.getCacheSize());
+
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(2);
+
+        template.sendBodyAndHeader("file:target/changed/in", "Hello World", Exchange.FILE_NAME,
"hello.txt");
+        template.sendBodyAndHeader("file:target/changed/in", "Bye World", Exchange.FILE_NAME,
"bye.txt");
+
+        assertMockEndpointsSatisfied();
+
+        assertTrue(notify.matches(5, TimeUnit.SECONDS));
+
+        // they are not removed with commit
+        assertEquals(2, myRepo.getCacheSize());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file:target/changed/in?readLock=idempotent&idempotentRepository=#myRepo&readLockRemoveOnCommit=false")
+                    .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/51f8742d/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileIdempotentReadLockTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileIdempotentReadLockTest.java
b/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileIdempotentReadLockTest.java
new file mode 100644
index 0000000..0ce9a6f
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileIdempotentReadLockTest.java
@@ -0,0 +1,87 @@
+/**
+ * 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.file.strategy;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.processor.idempotent.MemoryIdempotentRepository;
+
+/**
+ * @version
+ */
+public class FileIdempotentReadLockTest extends ContextTestSupport {
+
+    MemoryIdempotentRepository myRepo = new MemoryIdempotentRepository();
+
+    @Override
+    protected void setUp() throws Exception {
+        deleteDirectory("target/changed/");
+        createDirectory("target/changed/in");
+        super.setUp();
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("myRepo", myRepo);
+        return jndi;
+    }
+
+    public void testIdempotentReadLock() throws Exception {
+        assertEquals(0, myRepo.getCacheSize());
+
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(2);
+
+        template.sendBodyAndHeader("file:target/changed/in", "Hello World", Exchange.FILE_NAME,
"hello.txt");
+        template.sendBodyAndHeader("file:target/changed/in", "Bye World", Exchange.FILE_NAME,
"bye.txt");
+
+        assertMockEndpointsSatisfied();
+
+        assertTrue(notify.matches(5, TimeUnit.SECONDS));
+
+        // they are removed with commit
+        assertEquals(0, myRepo.getCacheSize());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file:target/changed/in?readLock=idempotent&idempotentRepository=#myRepo")
+                    .process(new Processor() {
+                        @Override
+                        public void process(Exchange exchange) throws Exception {
+                            // we are in progress
+                            assertEquals(1, myRepo.getCacheSize());
+                        }
+                    })
+                    .to("mock:result");
+            }
+        };
+    }
+}


Mime
View raw message