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 2023/07/24 07:40:48 UTC

[camel] 01/01: Fix flaky test

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch ant
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 434297ebc967f65e0f7a08fd68887bf1fdaa4423
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Jul 24 09:40:34 2023 +0200

    Fix flaky test
---
 .../file/AntPathMatcherGenericFileFilterTest.java  | 153 ++++++++++++++++-----
 1 file changed, 115 insertions(+), 38 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java
index 98eee7f8275..8044f9863f5 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java
@@ -30,6 +30,11 @@ import org.junit.jupiter.api.Test;
  */
 public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
 
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
     @Override
     protected Registry createRegistry() throws Exception {
         AntPathMatcherGenericFileFilter<File> filterNotCaseSensitive = new AntPathMatcherGenericFileFilter<>("**/c*");
@@ -43,6 +48,18 @@ public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
 
     @Test
     public void testInclude() throws Exception {
+        context.setAutoStartup(false);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(fileUri(
+                        "files/ant-path-1?initialDelay=0&delay=10&recursive=true&antInclude=**/*.txt&antFilterCaseSensitive=true"))
+                        .convertBodyTo(String.class)
+                        .to("mock:result1");
+            }
+        });
+        context.start();
+
         MockEndpoint mock = getMockEndpoint("mock:result1");
         mock.expectedBodiesReceivedInAnyOrder("Hello World");
 
@@ -50,11 +67,23 @@ public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
         template.sendBodyAndHeader(endpointUri, "Hello World", Exchange.FILE_NAME, "report.txt");
         template.sendBodyAndHeader(endpointUri, "Hello World 2", Exchange.FILE_NAME, "b.TXT");
 
+        context.getRouteController().startAllRoutes();
+
         assertMockEndpointsSatisfied();
     }
 
     @Test
     public void testExclude() throws Exception {
+        context.setAutoStartup(false);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(fileUri("files/ant-path-2?initialDelay=0&delay=10&recursive=true&antExclude=**/*.bak"))
+                        .convertBodyTo(String.class).to("mock:result2");
+            }
+        });
+        context.start();
+
         MockEndpoint mock = getMockEndpoint("mock:result2");
         mock.expectedBodiesReceivedInAnyOrder("Hello World 2", "Hello World 3", "Hello World 4");
 
@@ -64,11 +93,25 @@ public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
         template.sendBodyAndHeader(endpointUri, "Hello World 3", Exchange.FILE_NAME, "b.BAK");
         template.sendBodyAndHeader(endpointUri, "Hello World 4", Exchange.FILE_NAME, "b.TXT");
 
+        context.getRouteController().startAllRoutes();
+
         assertMockEndpointsSatisfied();
     }
 
     @Test
     public void testIncludesAndExcludes() throws Exception {
+        context.setAutoStartup(false);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(fileUri(
+                        "files/ant-path-3?initialDelay=0&delay=10&recursive=true&antInclude=**/*.pdf,**/*.txt&antExclude=**/a*,**/b*"))
+                        .convertBodyTo(String.class)
+                        .to("mock:result3");
+            }
+        });
+        context.start();
+
         MockEndpoint mock = getMockEndpoint("mock:result3");
         mock.expectedBodiesReceivedInAnyOrder("Hello World 2", "Hello World 4");
 
@@ -86,11 +129,25 @@ public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
         template.sendBodyAndHeader(endpointUri, "Hello World 11", Exchange.FILE_NAME, "by.BAK");
         template.sendBodyAndHeader(endpointUri, "Hello World 12", Exchange.FILE_NAME, "my.BaK");
 
+        context.getRouteController().startAllRoutes();
+
         assertMockEndpointsSatisfied();
     }
 
     @Test
     public void testIncludesAndExcludesAndFilter() throws Exception {
+        context.setAutoStartup(false);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(fileUri(
+                        "files/ant-path-4?initialDelay=0&delay=10&recursive=true&antInclude=**/*.txt&antExclude=**/a*&filter=#filter"))
+                        .convertBodyTo(String.class)
+                        .to("mock:result4");
+            }
+        });
+        context.start();
+
         MockEndpoint mock = getMockEndpoint("mock:result4");
         mock.expectedBodiesReceivedInAnyOrder("Hello World 3");
 
@@ -100,11 +157,25 @@ public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
         template.sendBodyAndHeader(endpointUri, "Hello World 3", Exchange.FILE_NAME, "c.txt");
         template.sendBodyAndHeader(endpointUri, "Hello World 4", Exchange.FILE_NAME, "Cy.txt");
 
+        context.getRouteController().startAllRoutes();
+
         assertMockEndpointsSatisfied();
     }
 
     @Test
     public void testIncludeAndAntFilterNotCaseSensitive() throws Exception {
+        context.setAutoStartup(false);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(fileUri(
+                        "files/ant-path-5?initialDelay=0&delay=10&recursive=true&antInclude=**/*.txt&antFilterCaseSensitive=false"))
+                        .convertBodyTo(String.class)
+                        .to("mock:result5");
+            }
+        });
+        context.start();
+
         MockEndpoint mock = getMockEndpoint("mock:result5");
         mock.expectedBodiesReceivedInAnyOrder("Hello World");
 
@@ -112,11 +183,26 @@ public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
         template.sendBodyAndHeader(endpointUri, "Hello World", Exchange.FILE_NAME,
                 "report.TXT");
 
+        context.getRouteController().startAllRoutes();
+
         assertMockEndpointsSatisfied();
     }
 
     @Test
     public void testExcludeAndAntFilterNotCaseSensitive() throws Exception {
+        context.setAutoStartup(false);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(fileUri(
+                        "files/ant-path-6?initialDelay=0&delay=10&recursive=true&antExclude=**/*.bak&antFilterCaseSensitive=false"))
+                        .convertBodyTo(String.class)
+                        .to("mock:result6");
+
+            }
+        });
+        context.start();
+
         MockEndpoint mock = getMockEndpoint("mock:result6");
         mock.expectedBodiesReceivedInAnyOrder("Hello World 2", "Hello World 4");
 
@@ -126,11 +212,25 @@ public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
         template.sendBodyAndHeader(endpointUri, "Hello World 3", Exchange.FILE_NAME, "b.BAK");
         template.sendBodyAndHeader(endpointUri, "Hello World 4", Exchange.FILE_NAME, "b.TXT");
 
+        context.getRouteController().startAllRoutes();
+
         assertMockEndpointsSatisfied();
     }
 
     @Test
     public void testIncludesAndExcludesAndAntFilterNotCaseSensitive() throws Exception {
+        context.setAutoStartup(false);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(fileUri(
+                        "files/ant-path-7?initialDelay=0&delay=10&recursive=true&antInclude=**/*.Pdf,**/*.txt&antExclude=**/a*,**/b*&antFilterCaseSensitive=false"))
+                        .convertBodyTo(String.class).to("mock:result7");
+
+            }
+        });
+        context.start();
+
         MockEndpoint mock = getMockEndpoint("mock:result7");
         mock.expectedBodiesReceivedInAnyOrder("Hello World 2", "Hello World 4", "Hello World 8", "Hello World 10");
 
@@ -148,11 +248,24 @@ public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
         template.sendBodyAndHeader(endpointUri, "Hello World 11", Exchange.FILE_NAME, "By.BAK");
         template.sendBodyAndHeader(endpointUri, "Hello World 12", Exchange.FILE_NAME, "My.BaK");
 
+        context.getRouteController().startAllRoutes();
+
         assertMockEndpointsSatisfied();
     }
 
     @Test
     public void testIncludesAndExcludesAndFilterAndAntFilterNotCaseSensitive() throws Exception {
+        context.setAutoStartup(false);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(fileUri(
+                        "files/ant-path-8?initialDelay=0&delay=10&recursive=true&antInclude=**/*.txt&antExclude=**/a*&filter=#caseInsensitiveFilter"))
+                        .convertBodyTo(String.class).to("mock:result8");
+            }
+        });
+        context.start();
+
         MockEndpoint mock = getMockEndpoint("mock:result8");
         mock.expectedBodiesReceivedInAnyOrder("Hello World 3", "Hello World 4");
 
@@ -162,45 +275,9 @@ public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
         template.sendBodyAndHeader(endpointUri, "Hello World 3", Exchange.FILE_NAME, "c.txt");
         template.sendBodyAndHeader(endpointUri, "Hello World 4", Exchange.FILE_NAME, "Cy.txt");
 
+        context.getRouteController().startAllRoutes();
+
         assertMockEndpointsSatisfied();
     }
 
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            public void configure() throws Exception {
-                from(fileUri(
-                        "files/ant-path-1?initialDelay=0&delay=10&recursive=true&antInclude=**/*.txt&antFilterCaseSensitive=true"))
-                        .convertBodyTo(String.class)
-                        .to("mock:result1");
-                from(fileUri(
-                        "files/ant-path-5?initialDelay=0&delay=10&recursive=true&antInclude=**/*.txt&antFilterCaseSensitive=false"))
-                        .convertBodyTo(String.class)
-                        .to("mock:result5");
-
-                from(fileUri("files/ant-path-2?initialDelay=0&delay=10&recursive=true&antExclude=**/*.bak"))
-                        .convertBodyTo(String.class).to("mock:result2");
-                from(fileUri(
-                        "files/ant-path-6?initialDelay=0&delay=10&recursive=true&antExclude=**/*.bak&antFilterCaseSensitive=false"))
-                        .convertBodyTo(String.class)
-                        .to("mock:result6");
-
-                from(fileUri(
-                        "files/ant-path-3?initialDelay=0&delay=10&recursive=true&antInclude=**/*.pdf,**/*.txt&antExclude=**/a*,**/b*"))
-                        .convertBodyTo(String.class)
-                        .to("mock:result3");
-                from(fileUri(
-                        "files/ant-path-7?initialDelay=0&delay=10&recursive=true&antInclude=**/*.Pdf,**/*.txt&antExclude=**/a*,**/b*&antFilterCaseSensitive=false"))
-                        .convertBodyTo(String.class).to("mock:result7");
-
-                from(fileUri(
-                        "files/ant-path-4?initialDelay=0&delay=10&recursive=true&antInclude=**/*.txt&antExclude=**/a*&filter=#filter"))
-                        .convertBodyTo(String.class)
-                        .to("mock:result4");
-                from(fileUri(
-                        "files/ant-path-8?initialDelay=0&delay=10&recursive=true&antInclude=**/*.txt&antExclude=**/a*&filter=#caseInsensitiveFilter"))
-                        .convertBodyTo(String.class).to("mock:result8");
-            }
-        };
-    }
 }