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/05/22 17:30:34 UTC

[camel] branch camel-3.x updated (d4bc6fe7baa -> df63ca4c355)

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

davsclaus pushed a change to branch camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git


    from d4bc6fe7baa Regen for commit 763c3bc15b960ef6249c40f4d4a6a89e1a3a3738
     new 850d3eaefb5 File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)
     new 430af4a0bd3 File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)
     new df63ca4c355 File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../FileChangedExclusiveReadLockStrategy.java      | 14 ++++++-------
 .../FileChangedReadLockMinAgeShortCircuitTest.java | 23 +++++++++++-----------
 2 files changed, 18 insertions(+), 19 deletions(-)


[camel] 01/03: File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 850d3eaefb503892572192e82d48f381a550eb23
Author: David Voit <da...@gmail.com>
AuthorDate: Mon May 22 17:20:57 2023 +0200

    File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)
    
    If a file is copied with the original lastModified date, files are processes instantly.
    Also the file change detection is disabled if a copy takes more than minAge time.
    Instead of comparing startTime with lastModified on each iteration we are comparing it with now().
    If files are created anew this should be the same behaviour, and files copied with preserved lastModifed are still correctly checked.
---
 .../strategy/FileChangedExclusiveReadLockStrategy.java     | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java
index c3d01f0880f..b1e04b4273e 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java
@@ -17,7 +17,6 @@
 package org.apache.camel.component.file.strategy;
 
 import java.io.File;
-import java.util.Date;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.LoggingLevel;
@@ -58,7 +57,7 @@ public class FileChangedExclusiveReadLockStrategy extends MarkerFileExclusiveRea
         long lastModified = Long.MIN_VALUE;
         long length = Long.MIN_VALUE;
         StopWatch watch = new StopWatch();
-        long startTime = (new Date()).getTime();
+        long startTime = System.currentTimeMillis();
 
         while (!exclusive) {
             // timeout check
@@ -81,16 +80,15 @@ public class FileChangedExclusiveReadLockStrategy extends MarkerFileExclusiveRea
 
             long newLastModified = target.lastModified();
             long newLength = target.length();
-            long newOlderThan = startTime + watch.taken() - minAge;
+            long minTriggerTime = startTime + minAge;
+            long currentTime = System.currentTimeMillis();
 
             LOG.trace("Previous last modified: {}, new last modified: {}", lastModified, newLastModified);
             LOG.trace("Previous length: {}, new length: {}", length, newLength);
-            LOG.trace("New older than threshold: {}", newOlderThan);
+            LOG.trace("Min File Trigger Time: {}", minTriggerTime);
 
-            // CHECKSTYLE:OFF
-            if (newLength >= minLength && ((minAge == 0 && newLastModified == lastModified && newLength == length)
-                    || (minAge != 0 && newLastModified < newOlderThan))) {
-            // CHECKSTYLE:ON
+            if (newLength >= minLength && currentTime >= minTriggerTime
+                && newLastModified == lastModified && newLength == length) {
                 LOG.trace("Read lock acquired.");
                 exclusive = true;
             } else {


[camel] 03/03: File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit df63ca4c35564ded90d1e099018a2209bd478fe7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon May 22 19:28:50 2023 +0200

    File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)
---
 .../FileChangedReadLockMinAgeShortCircuitTest.java | 23 +++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockMinAgeShortCircuitTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockMinAgeShortCircuitTest.java
index 60bdfc610dc..cd4588b0a43 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockMinAgeShortCircuitTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/FileChangedReadLockMinAgeShortCircuitTest.java
@@ -17,10 +17,8 @@
 package org.apache.camel.component.file.strategy;
 
 import java.nio.file.Files;
-import java.util.Date;
 
 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.jupiter.api.BeforeEach;
@@ -43,15 +41,18 @@ public class FileChangedReadLockMinAgeShortCircuitTest extends ContextTestSuppor
     }
 
     @Test
-    public void testChangedReadLockMinAge() throws Exception {
+    public void testChangedReadLockMinAgeNotAcquired() throws Exception {
+        // terminate test quicker
+        context.getShutdownStrategy().setTimeout(1);
+
+        // we do not acquire read-lock because the check interval is 10s, so "changed" requires at least a poll of 10s
+        // before we can determine that the file has same size as before
+
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        mock.expectedFileExists(testFile("out/file.dat"));
-        // We should get the file on the first poll
-        mock.expectedMessagesMatches(
-                exchangeProperty(Exchange.RECEIVED_TIMESTAMP).convertTo(long.class).isLessThan(new Date().getTime() + 15000));
+        mock.expectedMessageCount(0);
 
-        assertMockEndpointsSatisfied();
+        // but the unit test only waits 2 seconds
+        mock.assertIsSatisfied(2000);
     }
 
     @Override
@@ -60,8 +61,8 @@ public class FileChangedReadLockMinAgeShortCircuitTest extends ContextTestSuppor
             @Override
             public void configure() throws Exception {
                 from(fileUri(
-                        "in?initialDelay=500&delay=10&readLock=changed&readLockMinAge=10&readLockCheckInterval=30000&readLockTimeout=90000"))
-                                .to(fileUri("out"), "mock:result");
+                        "in?initialDelay=500&delay=10&readLock=changed&readLockMinAge=1000&readLockCheckInterval=10000&readLockTimeout=20000"))
+                        .to(fileUri("out"), "mock:result");
             }
         };
     }


[camel] 02/03: File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 430af4a0bd32e0eb619e43e19c386f5a7382489e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon May 22 17:21:37 2023 +0200

    File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)
---
 .../component/file/strategy/FileChangedExclusiveReadLockStrategy.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java
index b1e04b4273e..1bf34e8b0c5 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/strategy/FileChangedExclusiveReadLockStrategy.java
@@ -88,7 +88,7 @@ public class FileChangedExclusiveReadLockStrategy extends MarkerFileExclusiveRea
             LOG.trace("Min File Trigger Time: {}", minTriggerTime);
 
             if (newLength >= minLength && currentTime >= minTriggerTime
-                && newLastModified == lastModified && newLength == length) {
+                    && newLastModified == lastModified && newLength == length) {
                 LOG.trace("Read lock acquired.");
                 exclusive = true;
             } else {