This is an automated email from the ASF dual-hosted git repository.
Croway 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 93d78a5f579b CAMEL-25772: camel-file - leave the kept done files as
they are when the listing was cut (#28255)
93d78a5f579b is described below
commit 93d78a5f579bd3f15a6c12a6f409ba4dd0c3f9ce
Author: allthingssecurity <[email protected]>
AuthorDate: Thu Oct 22 22:14:16 2026 +0530
CAMEL-25772: camel-file - leave the kept done files as they are when the
listing was cut (#28255)
* CAMEL-25772: camel-file - leave the kept done files as they are when the
listing was cut
Follow-up to the review of CAMEL-25728 (#28035). When the listing of a poll
was cut at maxMessagesPerPoll, GenericFileKeptDoneFiles.startBatch removed
the
listed done files from the kept set, and GenericFileConsumer.poll then kept
every listed done file again right after. The removeAll was undone at once,
so
the code did not say what happens (review comment by Claus Ibsen).
startBatch now leaves the kept done files as they are when the listing was
cut, and its javadoc says that the caller keeps the done file of every
listed
file in that case. The kept set after the poll is the same as before (the
done
files kept before plus the listed ones), so the behaviour is unchanged. The
only difference is that a listed done file is no longer out of the kept set
for the short time between startBatch and the keeps, when a file of the
previous poll that completes asynchronously could have checked it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* CAMEL-25772: camel-file - unit test of GenericFileKeptDoneFiles for the
cut and the complete listing
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../component/file/GenericFileKeptDoneFiles.java | 12 ++---
.../file/GenericFileKeptDoneFilesTest.java | 58 ++++++++++++++++++++++
2 files changed, 64 insertions(+), 6 deletions(-)
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileKeptDoneFiles.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileKeptDoneFiles.java
index f7a9eaa8cf0b..e9998adddedb 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileKeptDoneFiles.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileKeptDoneFiles.java
@@ -38,12 +38,14 @@ final class GenericFileKeptDoneFiles {
private final Set<String> kept = new HashSet<>();
/**
- * Called once the directory is listed, before the files are consumed:
forgets the done files kept by the last poll,
- * as the files of this poll decide again whether they are kept.
+ * Called once the directory is listed, before the files are consumed.
When the listing was complete, forgets the
+ * done files kept by the last poll, as the files of this poll decide
again whether they are kept. When the listing
+ * was cut (it stopped at the limit), the kept done files are left as they
are: a done file not listed is still
+ * kept, as its files may be among those not listed, and the caller then
keeps the done file of every listed file,
+ * as the poll leaves files for the next one.
*
* @param listedDoneFiles the done files of the files this poll found
- * @param listingComplete whether every file was listed; if not (the
listing stopped at the limit), a done file not
- * listed is kept, as its files may be among those
not listed
+ * @param listingComplete whether every file was listed
* @return the done files kept for files that are gone
(the listing was complete and found none of
* their files), to delete
*/
@@ -59,8 +61,6 @@ final class GenericFileKeptDoneFiles {
}
}
kept.clear();
- } else {
- kept.removeAll(listedDoneFiles);
}
return answer;
}
diff --git
a/components/camel-file/src/test/java/org/apache/camel/component/file/GenericFileKeptDoneFilesTest.java
b/components/camel-file/src/test/java/org/apache/camel/component/file/GenericFileKeptDoneFilesTest.java
new file mode 100644
index 000000000000..37960c00481c
--- /dev/null
+++
b/components/camel-file/src/test/java/org/apache/camel/component/file/GenericFileKeptDoneFilesTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file;
+
+import java.util.List;
+import java.util.Set;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class GenericFileKeptDoneFilesTest {
+
+ private final GenericFileKeptDoneFiles keptDoneFiles = new
GenericFileKeptDoneFiles();
+
+ @Test
+ void cutListingKeepsTheKeptDoneFilesAtAllTimes() {
+ keptDoneFiles.keep("dir/ready");
+ keptDoneFiles.keep("other/ready");
+
+ // a cut listing does not forget a kept done file, not even for a
moment: a file of the last poll that completes
+ // on another thread meanwhile must still find it kept, listed in this
poll or not
+ assertNull(keptDoneFiles.startBatch(Set.of("dir/ready"), false));
+ assertTrue(keptDoneFiles.isKept("dir/ready"));
+ assertTrue(keptDoneFiles.isKept("other/ready"));
+ }
+
+ @Test
+ void completeListingForgetsTheKeptDoneFilesAndReturnsThoseOfGoneFiles() {
+ keptDoneFiles.keep("dir/ready");
+ keptDoneFiles.keep("gone/ready");
+
+ assertEquals(List.of("gone/ready"),
keptDoneFiles.startBatch(Set.of("dir/ready"), true));
+ assertFalse(keptDoneFiles.isKept("dir/ready"));
+ assertFalse(keptDoneFiles.isKept("gone/ready"));
+
+ keptDoneFiles.keep("dir/ready");
+ assertEquals(List.of("dir/ready"), keptDoneFiles.startBatch(Set.of(),
true));
+ assertFalse(keptDoneFiles.isKept("dir/ready"));
+ }
+}