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/11/14 17:29:17 UTC

svn commit: r1409246 - in /camel/trunk/camel-core/src/test/java/org/apache/camel: component/file/strategy/MarkerFileExclusiveReadLockStrategyReadLockFailedTest.java management/EventNotifierExchangeSentParallelTest.java

Author: davsclaus
Date: Wed Nov 14 16:29:16 2012
New Revision: 1409246

URL: http://svn.apache.org/viewvc?rev=1409246&view=rev
Log:
Fixed tests

Modified:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategyReadLockFailedTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/EventNotifierExchangeSentParallelTest.java

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategyReadLockFailedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategyReadLockFailedTest.java?rev=1409246&r1=1409245&r2=1409246&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategyReadLockFailedTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategyReadLockFailedTest.java Wed Nov 14 16:29:16 2012
@@ -17,9 +17,9 @@
 package org.apache.camel.component.file.strategy;
 
 import java.io.File;
-import java.io.FileOutputStream;
 
 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.slf4j.Logger;
@@ -30,8 +30,6 @@ import org.slf4j.LoggerFactory;
  */
 public class MarkerFileExclusiveReadLockStrategyReadLockFailedTest extends ContextTestSupport {
 
-    private static final transient Logger LOG = LoggerFactory.getLogger(MarkerFileExclusiveReadLockStrategyReadLockFailedTest.class);
-    
     @Override
     protected void setUp() throws Exception {
         deleteDirectory("target/readlock/");
@@ -40,56 +38,33 @@ public class MarkerFileExclusiveReadLock
     }
 
     public void testReadLockFailed() throws Exception {
+        // should only pickup the 2nd file, as we have a marker file for the first file
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        mock.expectedFileExists("target/readlock/out/file1.dat");
+        mock.expectedBodiesReceived("Bye World");
 
         writeFiles();
 
+        // wait for files to be fully done using oneExchangeDone
         assertMockEndpointsSatisfied();
+        assertTrue(oneExchangeDone.matchesMockWaitTime());
 
-        String content = context.getTypeConverter().convertTo(String.class, new File("target/readlock/out/file1.dat").getAbsoluteFile());
-        String[] lines = content.split(LS);
-        for (int i = 0; i < 20; i++) {
-            assertEquals("Line " + i, lines[i]);
-        }
-        
-        // wait for a while for camel to clean up the file
-        Thread.sleep(500);
-
-        assertFileDoesNotExists("target/readlock/in/file1.dat.camelLock");
-        assertFileExists("target/readlock/in/file2.dat.camelLock");
-
-        assertFileDoesNotExists("target/readlock/in/file1.dat");
-        assertFileExists("target/readlock/in/file2.dat");
-        
-        File lock = new File("target/readlock/in/file2.dat.camelLock");
-        lock.delete();
-        // wait for a while for camel to clean up the file
-        Thread.sleep(500);
+        // we should generate an output for the 2nd file
         assertFileExists("target/readlock/out/file2.dat");
-        
-      
+
+        // and the marker file from the 1st file is still there, and the 1st file as well
+        assertFileExists("target/readlock/in/file1.dat.camelLock");
+        assertFileExists("target/readlock/in/file1.dat");
     }
 
     private void writeFiles() throws Exception {
-        LOG.debug("Writing files...");
-        // create a camelLock file first
-        File lock = new File("target/readlock/in/file2.dat.camelLock");
+        log.debug("Writing files...");
+
+        // create a camelLock file first, so file1 will not be picked up
+        File lock = new File("target/readlock/in/file1.dat.camelLock");
         lock.createNewFile();
-        
-        FileOutputStream fos = new FileOutputStream("target/readlock/in/file1.dat");
-        FileOutputStream fos2 = new FileOutputStream("target/readlock/in/file2.dat");
-        for (int i = 0; i < 20; i++) {
-            fos.write(("Line " + i + LS).getBytes());
-            fos2.write(("Line " + i + LS).getBytes());
-            LOG.debug("Writing line " + i);
-        }
-
-        fos.flush();
-        fos.close();
-        fos2.flush();
-        fos2.close();
+
+        template.sendBodyAndHeader("file:target/readlock/in", "Hello World", Exchange.FILE_NAME, "file1.dat");
+        template.sendBodyAndHeader("file:target/readlock/in", "Bye World", Exchange.FILE_NAME, "file2.dat");
     }
 
     @Override
@@ -98,15 +73,11 @@ public class MarkerFileExclusiveReadLock
             @Override
             public void configure() throws Exception {
                 from("file:target/readlock/in?readLock=markerFile")
-                        .to("file:target/readlock/out", "mock:result");
+                        .to("file:target/readlock/out")
+                        .convertBodyTo(String.class)
+                        .to("mock:result");
             }
         };
     }
 
-   
-    private static void assertFileDoesNotExists(String filename) {
-        File file = new File(filename).getAbsoluteFile();
-        assertFalse("File " + filename + " should not exist, it should have been deleted after being processed", file.exists());
-    }
-
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/EventNotifierExchangeSentParallelTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/EventNotifierExchangeSentParallelTest.java?rev=1409246&r1=1409245&r2=1409246&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/EventNotifierExchangeSentParallelTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/EventNotifierExchangeSentParallelTest.java Wed Nov 14 16:29:16 2012
@@ -31,10 +31,9 @@ public class EventNotifierExchangeSentPa
 
         template.sendBodyAndHeader("direct:foo", "Hello World", "foo", "direct:cool,direct:start");
 
+        // wait for the message to be fully done using oneExchangeDone
         assertMockEndpointsSatisfied();
-
-        // give it time to complete
-        Thread.sleep(200);
+        assertTrue(oneExchangeDone.matchesMockWaitTime());
 
         assertEquals(12, events.size());