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 2012/05/20 10:07:26 UTC
svn commit: r1340635 -
/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaFileIdempotentIssueTest.java
Author: davsclaus
Date: Sun May 20 08:07:26 2012
New Revision: 1340635
URL: http://svn.apache.org/viewvc?rev=1340635&view=rev
Log:
CAMEL-5282: Added unit test
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaFileIdempotentIssueTest.java
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaFileIdempotentIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaFileIdempotentIssueTest.java?rev=1340635&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaFileIdempotentIssueTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/SedaFileIdempotentIssueTest.java Sun May 20 08:07:26 2012
@@ -0,0 +1,113 @@
+/**
+ * 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.issues;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.concurrent.CountDownLatch;
+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.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.processor.idempotent.FileIdempotentRepository;
+
+/**
+ *
+ */
+public class SedaFileIdempotentIssueTest extends ContextTestSupport {
+
+ private final CountDownLatch latch = new CountDownLatch(1);
+ private FileIdempotentRepository repository = new FileIdempotentRepository();
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/inbox");
+ createDirectory("target/inbox");
+
+ // create file without using Camel
+ File file = new File("target/inbox/hello.txt");
+ FileOutputStream fos = new FileOutputStream(file, true);
+ fos.write("Hello World".getBytes());
+ fos.flush();
+ fos.close();
+
+ super.setUp();
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+
+ repository.setFileStore(new File("target/repo.txt"));
+ jndi.bind("repo", repository);
+ return jndi;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ onException(RuntimeException.class).process(new ShutDown());
+
+ from("file:target/inbox?idempotent=true&noop=true&idempotentRepository=#repo&delay=1000")
+ .to("log:begin")
+ .inOut("seda:process");
+
+ from("seda:process")
+ .delay(1000)
+ .throwException(new RuntimeException("Testing with exception"));
+ }
+ };
+ }
+
+ public void testRepo() throws Exception {
+ boolean done = latch.await(10, TimeUnit.SECONDS);
+ assertTrue("Should stop Camel", done);
+
+ assertEquals("No file should be reported consumed", 0, repository.getCache().keySet().size());
+ }
+
+ private class ShutDown implements Processor {
+
+ @Override
+ public void process(final Exchange exchange) throws Exception {
+ // shutdown route
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ // shutdown camel
+ try {
+ log.info("Stopping Camel");
+ exchange.getContext().stop();
+ log.info("Stopped Camel complete");
+ latch.countDown();
+ } catch (Exception e) {
+ // ignore
+ e.printStackTrace();
+ }
+ }
+ };
+ // start shutdown in a separate thread
+ thread.start();
+ }
+ }
+
+}