This is an automated email from the ASF dual-hosted git repository.
gnodet 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 43b1fb05f169 CAMEL-24905: Fix flaky GridFsConsumerIT tests
43b1fb05f169 is described below
commit 43b1fb05f1697e75281c65f6d5eb45d9382a298a
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Sep 23 21:04:20 2026 +0200
CAMEL-24905: Fix flaky GridFsConsumerIT tests
Two root causes:
1. tearDownMongo() in AbstractMongoDbITSupport only cleaned the base GridFS
bucket (GridFsConsumerIT) but not the -a, -pts, and customFileFilterTest
buckets used by sibling consumer routes. Leftover files from a previous
test run caused the assertFalse pre-condition check (line 117) to fail.
Fix: drop all four buckets in teardown via a shared dropBucket() helper.
2. All four consumer routes in GridFsConsumerIT.createRouteBuilder() sent
to the same mock:test endpoint, so messages delivered by an unrelated
route (e.g. the -a consumer picking up a file left from testTimestamp)
polluted the expected message count, causing 'Expected <1> but was <2>'.
Fix: each consumer route now uses its own dedicated mock endpoint
(mock:test-ts, mock:test-a, mock:test-pts, mock:test-custom) and each
test method targets only its own mock.
Also aligns test class/method visibility to package-private per JUnit 5 /
Camel test conventions (drop public modifiers).
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../integration/AbstractMongoDbITSupport.java | 13 ++++++++-
.../gridfs/integration/GridFsConsumerIT.java | 31 +++++++++++-----------
2 files changed, 28 insertions(+), 16 deletions(-)
diff --git
a/components/camel-mongodb-gridfs/src/test/java/org/apache/camel/component/mongodb/gridfs/integration/AbstractMongoDbITSupport.java
b/components/camel-mongodb-gridfs/src/test/java/org/apache/camel/component/mongodb/gridfs/integration/AbstractMongoDbITSupport.java
index dd7e4ef67997..4342f09a5546 100644
---
a/components/camel-mongodb-gridfs/src/test/java/org/apache/camel/component/mongodb/gridfs/integration/AbstractMongoDbITSupport.java
+++
b/components/camel-mongodb-gridfs/src/test/java/org/apache/camel/component/mongodb/gridfs/integration/AbstractMongoDbITSupport.java
@@ -40,12 +40,23 @@ public abstract class AbstractMongoDbITSupport extends
CamelTestSupport {
return this.getClass().getSimpleName();
}
+ /**
+ * Drops all files from all GridFS buckets used by the test class, so
subsequent tests start with a clean slate.
+ * Subclasses that add extra buckets should override and call super.
+ */
@AfterEach
public void tearDownMongo() {
- gridFSBucket.find().forEach(gridFSFile ->
gridFSBucket.delete(gridFSFile.getId()));
+ dropBucket(gridFSBucket);
+ dropBucket(GridFSBuckets.create(mongo.getDatabase("test"), getBucket()
+ "-a"));
+ dropBucket(GridFSBuckets.create(mongo.getDatabase("test"), getBucket()
+ "-pts"));
+ dropBucket(GridFSBuckets.create(mongo.getDatabase("test"),
"customFileFilterTest"));
mongo.close();
}
+ private static void dropBucket(GridFSBucket bucket) {
+ bucket.find().forEach(f -> bucket.delete(f.getId()));
+ }
+
@Override
protected CamelContext createCamelContext() throws Exception {
mongo = MongoClients.create(service.getReplicaSetUrl());
diff --git
a/components/camel-mongodb-gridfs/src/test/java/org/apache/camel/component/mongodb/gridfs/integration/GridFsConsumerIT.java
b/components/camel-mongodb-gridfs/src/test/java/org/apache/camel/component/mongodb/gridfs/integration/GridFsConsumerIT.java
index aa8c420b2357..dc9d3bb9f4b9 100644
---
a/components/camel-mongodb-gridfs/src/test/java/org/apache/camel/component/mongodb/gridfs/integration/GridFsConsumerIT.java
+++
b/components/camel-mongodb-gridfs/src/test/java/org/apache/camel/component/mongodb/gridfs/integration/GridFsConsumerIT.java
@@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-public class GridFsConsumerIT extends AbstractMongoDbITSupport {
+class GridFsConsumerIT extends AbstractMongoDbITSupport {
@Override
protected RouteBuilder createRouteBuilder() {
@@ -49,36 +49,37 @@ public class GridFsConsumerIT extends
AbstractMongoDbITSupport {
.to("mongodb-gridfs:myDb?database={{mongodb.testDb}}&operation=create&bucket="
+ getBucket() + "-pts");
from("mongodb-gridfs:myDb?database={{mongodb.testDb}}&bucket="
+ getBucket()).convertBodyTo(String.class)
- .to("mock:test");
+ .to("mock:test-ts");
from("mongodb-gridfs:myDb?database={{mongodb.testDb}}&bucket="
+ getBucket() + "-a&queryStrategy=FileAttribute")
- .convertBodyTo(String.class).to("mock:test");
+ .convertBodyTo(String.class).to("mock:test-a");
from("mongodb-gridfs:myDb?database={{mongodb.testDb}}&bucket="
+ getBucket()
+ "-pts&queryStrategy=PersistentTimestamp")
- .convertBodyTo(String.class).to("mock:test");
+ .convertBodyTo(String.class).to("mock:test-pts");
from("mongodb-gridfs:myDb?database={{mongodb.testDb}}&bucket=customFileFilterTest&queryStrategy=TimeStampAndFileAttribute&query="
+ String.format("{'%s': '%s'}", GRIDFS_FILE_KEY_FILENAME,
FILE_NAME))
- .convertBodyTo(String.class).to("mock:test");
+ .convertBodyTo(String.class).to("mock:test-custom");
}
};
}
@Test
- public void testTimestamp() throws Exception {
- runTest("direct:create", gridFSBucket);
+ void testTimestamp() throws Exception {
+ runTest("direct:create", gridFSBucket, "mock:test-ts");
}
@Test
- public void testAttribute() throws Exception {
- runTest("direct:create-a",
GridFSBuckets.create(mongo.getDatabase("test"), getBucket() + "-a"));
+ void testAttribute() throws Exception {
+ runTest("direct:create-a",
GridFSBuckets.create(mongo.getDatabase("test"), getBucket() + "-a"),
"mock:test-a");
}
@Test
- public void testPersistentTS() throws Exception {
- runTest("direct:create-pts",
GridFSBuckets.create(mongo.getDatabase("test"), getBucket() + "-pts"));
+ void testPersistentTS() throws Exception {
+ runTest("direct:create-pts",
GridFSBuckets.create(mongo.getDatabase("test"), getBucket() + "-pts"),
+ "mock:test-pts");
}
@Test
- public void testCustomFileQuery() throws Exception {
+ void testCustomFileQuery() throws Exception {
Map<String, Object> headers = new HashMap<>();
headers.put(Exchange.FILE_NAME, FILE_NAME);
@@ -94,7 +95,7 @@ public class GridFsConsumerIT extends
AbstractMongoDbITSupport {
ObjectId objectId =
result.getMessage().getHeader(GridFsConstants.GRIDFS_OBJECT_ID, ObjectId.class);
assertNotNull(objectId);
- MockEndpoint mock = getMockEndpoint("mock:test");
+ MockEndpoint mock = getMockEndpoint("mock:test-custom");
mock.expectedBodiesReceived(FILE_DATA);
mock.assertIsSatisfied();
@@ -108,8 +109,8 @@ public class GridFsConsumerIT extends
AbstractMongoDbITSupport {
assertEquals(0, count);
}
- public void runTest(String target, GridFSBucket gridfs) throws Exception {
- MockEndpoint mock = getMockEndpoint("mock:test");
+ void runTest(String target, GridFSBucket gridfs, String mockUri) throws
Exception {
+ MockEndpoint mock = getMockEndpoint(mockUri);
mock.expectedBodiesReceived(FILE_DATA);
mock.expectedHeaderReceived(GridFsConstants.GRIDFS_METADATA,
"{\"contentType\": \"text/plain\"}");