You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/10/21 10:39:23 UTC

[camel] branch main updated: CAMEL-18608: Fix the test FromFtpThirdPoolOkIT.testPollFileAndShouldBeDeletedAtThirdPoll

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

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


The following commit(s) were added to refs/heads/main by this push:
     new f4246b3280e CAMEL-18608: Fix the test FromFtpThirdPoolOkIT.testPollFileAndShouldBeDeletedAtThirdPoll
f4246b3280e is described below

commit f4246b3280e1647667099da4bc5368fb0bb8a58b
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Fri Oct 21 12:38:59 2022 +0200

    CAMEL-18608: Fix the test FromFtpThirdPoolOkIT.testPollFileAndShouldBeDeletedAtThirdPoll
---
 .../remote/integration/FromFtpThirdPoolOkIT.java   | 30 ++++++++++------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpThirdPoolOkIT.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpThirdPoolOkIT.java
index 72deb07da9e..f9c42d54307 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpThirdPoolOkIT.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/integration/FromFtpThirdPoolOkIT.java
@@ -18,9 +18,9 @@ package org.apache.camel.component.file.remote.integration;
 
 import java.io.File;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
@@ -30,17 +30,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-public class FromFtpThirdPoolOkIT extends FtpServerTestSupport {
+class FromFtpThirdPoolOkIT extends FtpServerTestSupport {
 
-    private static int counter;
-    private final String body = "Hello World this file will be deleted";
+    private final AtomicInteger counter = new AtomicInteger();
 
     private String getFtpUrl() {
         return "ftp://admin@localhost:{{ftp.server.port}}/thirdpool?password=admin&delete=true";
     }
 
     @Test
-    public void testPollFileAndShouldBeDeletedAtThirdPoll() throws Exception {
+    void testPollFileAndShouldBeDeletedAtThirdPoll() throws Exception {
+        String body = "Hello World this file will be deleted";
         template.sendBodyAndHeader(getFtpUrl(), body, Exchange.FILE_NAME, "hello.txt");
 
         getMockEndpoint("mock:result").expectedBodiesReceived(body);
@@ -51,11 +51,12 @@ public class FromFtpThirdPoolOkIT extends FtpServerTestSupport {
 
         // give time to delete file
         await().atMost(200, TimeUnit.MILLISECONDS)
-                .untilAsserted(() -> assertEquals(3, counter));
+                .untilAsserted(() -> assertEquals(3, counter.get()));
 
         // assert the file is deleted
         File file = service.ftpFile("thirdpool/hello.txt").toFile();
-        assertFalse(file.exists(), "The file should have been deleted");
+        await().atMost(1, TimeUnit.MINUTES)
+                .untilAsserted(() -> assertFalse(file.exists(), "The file should have been deleted"));
     }
 
     @Override
@@ -66,15 +67,12 @@ public class FromFtpThirdPoolOkIT extends FtpServerTestSupport {
                 // use no delay for fast unit testing
                 onException(IllegalArgumentException.class).logStackTrace(false).to("mock:error");
 
-                from(getFtpUrl()).process(new Processor() {
-                    public void process(Exchange exchange) {
-                        counter++;
-                        if (counter < 3) {
-                            // file should exists
-                            File file = service.ftpFile("thirdpool/hello.txt").toFile();
-                            assertTrue(file.exists(), "The file should NOT have been deleted");
-                            throw new IllegalArgumentException("Forced by unittest");
-                        }
+                from(getFtpUrl()).process(exchange -> {
+                    if (counter.incrementAndGet() < 3) {
+                        // file should exist
+                        File file = service.ftpFile("thirdpool/hello.txt").toFile();
+                        assertTrue(file.exists(), "The file should NOT have been deleted");
+                        throw new IllegalArgumentException("Forced by unit test");
                     }
                 }).to("mock:result");
             }