camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: Improvements to PollEnricher Tests
Date Fri, 04 Mar 2016 15:13:39 GMT
Repository: camel
Updated Branches:
  refs/heads/master 97cd326de -> 2d5000ea0


Improvements to PollEnricher Tests


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

Branch: refs/heads/master
Commit: 2d5000ea0bc16be3c7cddd6d7cec2c71772fae6b
Parents: 97cd326
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Fri Mar 4 16:08:33 2016 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Fri Mar 4 16:08:33 2016 +0100

----------------------------------------------------------------------
 ...EnrichFileCustomAggregationStrategyTest.java | 53 +++++++++++---------
 ...nrichFileDefaultAggregationStrategyTest.java | 52 ++++++++++---------
 2 files changed, 59 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2d5000ea/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnrichFileCustomAggregationStrategyTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnrichFileCustomAggregationStrategyTest.java
b/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnrichFileCustomAggregationStrategyTest.java
index 4e46667..3a8bfd4 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnrichFileCustomAggregationStrategyTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnrichFileCustomAggregationStrategyTest.java
@@ -17,40 +17,44 @@
 package org.apache.camel.processor.enricher;
 
 import java.io.File;
-import java.io.FileWriter;
-import java.util.List;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.processor.aggregate.AggregationStrategy;
 import org.junit.Test;
 
 public class PollEnrichFileCustomAggregationStrategyTest extends ContextTestSupport {
 
+    @Override
+    protected void setUp() throws Exception {
+        deleteDirectory("target/enrich");
+        deleteDirectory("target/enrichdata");
+        super.setUp();
+    }
+    
     @Test
     public void testPollEnrichDefaultAggregationStrategyBody() throws Exception {
 
-        Thread.sleep(2000);
-        String enrichFilename = "target/pollEnrich/enrich.txt";
-        String msgText = "Hello Camel";
-        FileWriter enrichFile = new FileWriter(enrichFilename);
-        enrichFile.write(msgText);
-        enrichFile.close();
+        getMockEndpoint("mock:start").expectedBodiesReceived("Start");
 
-        getMockEndpoint("mock:result").expectedMinimumMessageCount(1);
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Big file");
+        mock.expectedFileExists("target/enrich/.done/AAA.fin");
+        mock.expectedFileExists("target/enrichdata/.done/AAA.dat");
 
-        assertMockEndpointsSatisfied();
+        template.sendBodyAndHeader("file://target/enrich", "Start", Exchange.FILE_NAME, "AAA.fin");
 
-        List<Exchange> exchanges = getMockEndpoint("mock:result").getExchanges();
-        assertEquals(1, exchanges.size());
-        Exchange ex = (Exchange) exchanges.get(0);
-        assertEquals(msgText, ex.getIn().getBody().toString());
+        log.info("Sleeping for 1 sec before writing enrichdata file");
+        Thread.sleep(1000);
+        template.sendBodyAndHeader("file://target/enrichdata", "Big file", Exchange.FILE_NAME,
"AAA.dat");
+        log.info("... write done");
 
-        //This file should be deleted but it's there when the test end, so we have to use
AssertTrue for the moment
-        Thread.sleep(300);
-        File markerFile = new File(enrichFilename + ".camelLock");
-        assertTrue("Camel markerFile " + enrichFilename + ".camelLock did not get deleted
after file consumption.", markerFile.exists());
+        assertMockEndpointsSatisfied();
+        
+        // With Custom Aggregation Strategy The readLock continues to exist even if it should
be deleted
+        // assertFileDoesNotExists("target/enrichdata/AAA.dat.camelLock");
     }
 
     @Override
@@ -58,16 +62,19 @@ public class PollEnrichFileCustomAggregationStrategyTest extends ContextTestSupp
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("timer:foo?period=1000&repeatCount=1")
-                    .setBody().constant("Hello from Camel.")
-                    .pollEnrich("file:target/pollEnrich?fileName=enrich.txt&readLock=markerFile",
new ReplaceAggregationStrategy())
-                    .convertBodyTo(String.class)
-                    .log("The body is ${body}")
+                from("file://target/enrich?move=.done")
+                    .to("mock:start")
+                    .pollEnrich("file://target/enrichdata?readLock=markerFile&move=.done",
10000, new ReplaceAggregationStrategy())
                     .to("mock:result");
             }
         };
     }
     
+    private static void assertFileDoesNotExists(String filename) {
+        File file = new File(filename);
+        assertFalse("File " + filename + " should not exist, it should have been deleted
after being processed", file.exists());
+    }
+    
     class ReplaceAggregationStrategy implements AggregationStrategy {
 
         public Exchange aggregate(Exchange original, Exchange resource) {

http://git-wip-us.apache.org/repos/asf/camel/blob/2d5000ea/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnrichFileDefaultAggregationStrategyTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnrichFileDefaultAggregationStrategyTest.java
b/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnrichFileDefaultAggregationStrategyTest.java
index 73f6dcd..65163c7 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnrichFileDefaultAggregationStrategyTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/enricher/PollEnrichFileDefaultAggregationStrategyTest.java
@@ -17,39 +17,42 @@
 package org.apache.camel.processor.enricher;
 
 import java.io.File;
-import java.io.FileWriter;
-import java.util.List;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.Test;
 
 public class PollEnrichFileDefaultAggregationStrategyTest extends ContextTestSupport {
 
+    @Override
+    protected void setUp() throws Exception {
+        deleteDirectory("target/enrich");
+        deleteDirectory("target/enrichdata");
+        super.setUp();
+    }
+    
     @Test
     public void testPollEnrichDefaultAggregationStrategyBody() throws Exception {
 
-        Thread.sleep(2000);
-        String enrichFilename = "target/pollEnrich/enrich.txt";
-        String msgText = "Hello Camel";
-        FileWriter enrichFile = new FileWriter(enrichFilename);
-        enrichFile.write(msgText);
-        enrichFile.close();
+        getMockEndpoint("mock:start").expectedBodiesReceived("Start");
 
-        getMockEndpoint("mock:result").expectedMinimumMessageCount(1);
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Big file");
+        mock.expectedFileExists("target/enrich/.done/AAA.fin");
+        mock.expectedFileExists("target/enrichdata/.done/AAA.dat");
 
-        assertMockEndpointsSatisfied();
+        template.sendBodyAndHeader("file://target/enrich", "Start", Exchange.FILE_NAME, "AAA.fin");
 
-        List<Exchange> exchanges = getMockEndpoint("mock:result").getExchanges();
-        assertEquals(1, exchanges.size());
-        Exchange ex = (Exchange) exchanges.get(0);
-        assertEquals(msgText, ex.getIn().getBody().toString());
+        log.info("Sleeping for 1 sec before writing enrichdata file");
+        Thread.sleep(1000);
+        template.sendBodyAndHeader("file://target/enrichdata", "Big file", Exchange.FILE_NAME,
"AAA.dat");
+        log.info("... write done");
 
-        // assert Camel markerFile got deleted
-        Thread.sleep(300);
-        File markerFile = new File(enrichFilename + ".camelLock");
-        assertFalse("Camel markerFile " + enrichFilename + ".camelLock did not get deleted
after file consumption.", markerFile.exists());
+        assertMockEndpointsSatisfied();
+        
+        assertFileDoesNotExists("target/enrichdata/AAA.dat.camelLock");
     }
 
     @Override
@@ -57,13 +60,16 @@ public class PollEnrichFileDefaultAggregationStrategyTest extends ContextTestSup
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("timer:foo?period=1000&repeatCount=1")
-                    .setBody().constant("Hello from Camel.")
-                    .pollEnrich("file:target/pollEnrich?fileName=enrich.txt&readLock=markerFile")
-                    .convertBodyTo(String.class)
-                    .log("The body is ${body}")
+                from("file://target/enrich?move=.done")
+                    .to("mock:start")
+                    .pollEnrich("file://target/enrichdata?readLock=markerFile&move=.done",
10000)
                     .to("mock:result");
             }
         };
     }
+    
+    private static void assertFileDoesNotExists(String filename) {
+        File file = new File(filename);
+        assertFalse("File " + filename + " should not exist, it should have been deleted
after being processed", file.exists());
+    }
 }


Mime
View raw message