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:33:08 UTC

[camel] branch camel-3.18.x updated (e2bf8581131 -> bfe34c69ba7)

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

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


    from e2bf8581131 [Minor] Apply formatter
     new 5d4ae79be0a File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)
     new 5e3540a5096 File Changed ReadLock Strategy with minAge only looks for lastModified (#10131)
     new bfe34c69ba7 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 | 22 +++++++++++-----------
 2 files changed, 17 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.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5d4ae79be0a5eb1a968bd6c5d1218f7318af9055
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.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit bfe34c69ba70ed0ea33d989cb2b8b21a4db5e672
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 | 22 +++++++++++-----------
 1 file changed, 11 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..356f0b41830 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
@@ -59,8 +60,7 @@ public class FileChangedReadLockMinAgeShortCircuitTest extends ContextTestSuppor
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from(fileUri(
-                        "in?initialDelay=500&delay=10&readLock=changed&readLockMinAge=10&readLockCheckInterval=30000&readLockTimeout=90000"))
+                from(fileUri("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.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5e3540a509675cd95cc2ddedd0bce479fcac2236
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 {