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 2009/03/13 08:52:19 UTC

svn commit: r753153 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/test/java/org/apache/camel/component/file/ camel-core/src/test/java/org/apache/camel/processor/aggregator/ components/camel-ftp/src/test/java/org/apache/ca...

Author: davsclaus
Date: Fri Mar 13 07:52:18 2009
New Revision: 753153

URL: http://svn.apache.org/viewvc?rev=753153&view=rev
Log:
added unit test for Camel VFS consumer doing rollback and try again at next pool. Polished javadoc. Fixed failing test on hudson. 

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFilePollThirdTimeOkTest.java
      - copied, changed from r753137, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorBatchOptionsTest.java
    camel/trunk/components/camel-ftp/src/test/resources/log4j.properties

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=753153&r1=753152&r2=753153&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Fri Mar 13 07:52:18 2009
@@ -81,7 +81,7 @@
     /**
      * Gets a readonly list of names of the components currently registered
      *
-     * @return a readonly list with the names of the the componens.
+     * @return a readonly list with the names of the the components
      */
     List<String> getComponentNames();
 
@@ -289,7 +289,7 @@
     /**
      * Gets a readonly list with the names of the languages currently registered.
      *
-     * @return a readonly list with the names of the the languages. 
+     * @return a readonly list with the names of the the languages
      */
     List<String> getLanguageNames();
 

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFilePollThirdTimeOkTest.java (from r753137, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFilePollThirdTimeOkTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFilePollThirdTimeOkTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java&r1=753137&r2=753153&rev=753153&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFileDoNotDeleteFileIfProcessFailsTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FromFilePollThirdTimeOkTest.java Fri Mar 13 07:52:18 2009
@@ -22,14 +22,14 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision$
  */
-public class FromFileDoNotDeleteFileIfProcessFailsTest extends ContextTestSupport {
+public class FromFilePollThirdTimeOkTest extends ContextTestSupport {
 
-    private String body = "Hello World this file will NOT be deleted";
+    private String body = "Hello World this file will be deleted";
+    private static int counter;
 
     @Override
     protected void setUp() throws Exception {
@@ -37,36 +37,46 @@
         super.setUp();
     }
 
-    public void testPollFileAndShouldNotBeDeleted() throws Exception {
+    public void testPollFileAndShouldBeDeletedAtThirdPoll() throws Exception {
         template.sendBodyAndHeader("file://target/deletefile", body, Exchange.FILE_NAME, "hello.txt");
 
-        MockEndpoint mock = getMockEndpoint("mock:error");
-        mock.expectedBodiesReceived(body);
+        getMockEndpoint("mock:result").expectedBodiesReceived(body);
+        // 2 first attempt should fail
+        getMockEndpoint("mock:error").expectedMessageCount(2);
 
-        mock.assertIsSatisfied();
+        assertMockEndpointsSatisfied();
 
-        // give time to NOT delete file
+        // give time to delete file
         Thread.sleep(200);
 
+        assertEquals(3, counter);
+
         // assert the file is deleted
         File file = new File("./target/deletefile/hello.txt");
         file = file.getAbsoluteFile();
-        assertTrue("The file should NOT have been deleted", file.exists());
+        assertFalse("The file should have been deleted", file.exists());
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(2).delay(100).logStackTrace(false));
+                // no redeliveries as we want the file consumer to try again
+                errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(0).logStackTrace(false));
 
                 from("file://target/deletefile?delete=true").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
-                        throw new IllegalArgumentException("Forced by unittest");
+                        counter++;
+                        if (counter < 3) {
+                            // file should exists
+                            File file = new File("./target/deletefile/hello.txt");
+                            file = file.getAbsoluteFile();
+                            assertTrue("The file should NOT have been deleted", file.exists());
+                            throw new IllegalArgumentException("Forced by unittest");
+                        }
                     }
-                });
+                }).to("mock:result");
             }
         };
     }
 
-
-}
+}
\ No newline at end of file

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorBatchOptionsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorBatchOptionsTest.java?rev=753153&r1=753152&r2=753153&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorBatchOptionsTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregatorBatchOptionsTest.java Fri Mar 13 07:52:18 2009
@@ -119,7 +119,7 @@
         template.sendBodyAndHeader("direct:start", "Message 1c", "id", "1");
 
         // need a little sleep between batches
-        Thread.sleep(10);
+        Thread.sleep(100);
         // when we sent the next message we have reached the in batch size limit and the current
         // aggregated exchanges will be sent
         template.sendBodyAndHeader("direct:start", "Message 3a", "id", "3");

Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java?rev=753153&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java Fri Mar 13 07:52:18 2009
@@ -0,0 +1,86 @@
+/**
+ * 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.remote;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class FromFtpThirdPoolOkTest extends FtpServerTestSupport {
+
+    private String body = "Hello World this file will be deleted";
+    private static int counter;
+
+    private String getFtpUrl() {
+        return "ftp://admin@localhost:" + getPort() + "/thirdpool?password=admin&delete=true";
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        deleteDirectory("res/home/thirdpool");
+        deleteDirectory("target/thridpool");
+        super.setUp();
+    }
+
+    public void testPollFileAndShouldBeDeletedAtThirdPoll() throws Exception {
+        template.sendBodyAndHeader(getFtpUrl(), body, Exchange.FILE_NAME, "hello.txt");
+
+        getMockEndpoint("mock:result").expectedBodiesReceived(body);
+        // 2 first attempt should fail
+        getMockEndpoint("mock:error").expectedMessageCount(2);
+
+        assertMockEndpointsSatisfied();
+
+        // give time to delete file
+        Thread.sleep(200);
+
+        assertEquals(3, counter);
+
+        // assert the file is deleted
+        File file = new File("./res/home/thirdpool/hello.txt");
+        file = file.getAbsoluteFile();
+        assertFalse("The file should have been deleted", file.exists());
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                // no redeliveries as we want the ftp consumer to try again
+                errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(0).logStackTrace(false));
+
+                from(getFtpUrl()).process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        counter++;
+                        if (counter < 3) {
+                            // file should exists
+                            File file = new File("./res/home/thirdpool/hello.txt");
+                            file = file.getAbsoluteFile();
+                            assertTrue("The file should NOT have been deleted", file.exists());
+                            throw new IllegalArgumentException("Forced by unittest");
+                        }
+                    }
+                }).to("mock:result");
+            }
+        };
+    }
+
+}

Propchange: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpThirdPoolOkTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-ftp/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/resources/log4j.properties?rev=753153&r1=753152&r2=753153&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/resources/log4j.properties (original)
+++ camel/trunk/components/camel-ftp/src/test/resources/log4j.properties Fri Mar 13 07:52:18 2009
@@ -21,7 +21,7 @@
 log4j.rootLogger=INFO, file
 
 # uncomment the following to enable camel debugging
-log4j.logger.org.apache.camel.component.file=TRACE
+#log4j.logger.org.apache.camel.component.file=TRACE
 #log4j.logger.org.apache.camel=DEBUG
 log4j.logger.org.apache.mina=WARN
 log4j.logger.org.apache.ftpserver=WARN