This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-27182-datalake-not-found in repository https://gitbox.apache.org/repos/asf/camel.git
commit 93f4c1fb189cc289d368320ee480e0af788cb012 Author: Claus Ibsen <[email protected]> AuthorDate: Tue Nov 24 16:41:40 2026 +0100 CAMEL-27182: camel-azure-storage-datalake - treat a 404 BlobStorageException as file not found in the consumer DataLakeFileClient.openInputStream reads through the blob endpoint and throws BlobStorageException, so a fileName that does not exist failed every poll with a WARN, and a listed file deleted before it was read was reported as a failure. A 404 of either exception type now means the file does not exist. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../azure/storage/datalake/DataLakeConsumer.java | 21 +++++++++-- .../DataLakeConsumerFileThatCannotBeGotTest.java | 43 +++++++++++++++++++++- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/components/camel-azure/camel-azure-storage-datalake/src/main/java/org/apache/camel/component/azure/storage/datalake/DataLakeConsumer.java b/components/camel-azure/camel-azure-storage-datalake/src/main/java/org/apache/camel/component/azure/storage/datalake/DataLakeConsumer.java index 0a82efe58e59..3022995cb2a7 100644 --- a/components/camel-azure/camel-azure-storage-datalake/src/main/java/org/apache/camel/component/azure/storage/datalake/DataLakeConsumer.java +++ b/components/camel-azure/camel-azure-storage-datalake/src/main/java/org/apache/camel/component/azure/storage/datalake/DataLakeConsumer.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import java.util.Queue; +import com.azure.storage.blob.models.BlobStorageException; import com.azure.storage.file.datalake.DataLakeFileSystemClient; import com.azure.storage.file.datalake.models.DataLakeStorageException; import com.azure.storage.file.datalake.models.PathItem; @@ -70,8 +71,9 @@ public class DataLakeConsumer extends ScheduledBatchPollingConsumer { exchanges = createBatchExchangesFromPath(dataLakeFileSystemClient); } result = processBatch(CastUtils.cast(exchanges)); - } catch (DataLakeStorageException e) { - if (NOT_FOUND == e.getStatusCode()) { + } catch (DataLakeStorageException | BlobStorageException e) { + if (isNotFound(e)) { + // the file of the fileName option does not exist (yet) result = 0; } else { throw e; @@ -103,8 +105,8 @@ public class DataLakeConsumer extends ScheduledBatchPollingConsumer { // files are consumed, and a later poll tries it again try { exchanges.add(createExchangeFromFile(pathItem.getName(), dataLakeFileSystemClient)); - } catch (DataLakeStorageException e) { - if (NOT_FOUND == e.getStatusCode()) { + } catch (DataLakeStorageException | BlobStorageException e) { + if (isNotFound(e)) { // deleted (for example by another consumer) after it was listed LOG.debug("Skipping file {} as it no longer exists", pathItem.getName()); } else { @@ -136,6 +138,17 @@ public class DataLakeConsumer extends ScheduledBatchPollingConsumer { return exchanges; } + /** + * Whether the exception is the answer of the service to a file that does not exist. Reading a file goes through the + * blob endpoint ({@code DataLakeFileClient.openInputStream} reads with a {@code BlockBlobClient} and does not + * translate its exception), so a missing file is a {@link BlobStorageException}, not a + * {@link DataLakeStorageException}. + */ + private static boolean isNotFound(final Exception e) { + return e instanceof DataLakeStorageException d && NOT_FOUND == d.getStatusCode() + || e instanceof BlobStorageException b && NOT_FOUND == b.getStatusCode(); + } + private static void rethrow(final Exception e) throws IOException { if (e instanceof IOException ioe) { throw ioe; diff --git a/components/camel-azure/camel-azure-storage-datalake/src/test/java/org/apache/camel/component/azure/storage/datalake/DataLakeConsumerFileThatCannotBeGotTest.java b/components/camel-azure/camel-azure-storage-datalake/src/test/java/org/apache/camel/component/azure/storage/datalake/DataLakeConsumerFileThatCannotBeGotTest.java index 2456087ca2f3..9a435c2b0491 100644 --- a/components/camel-azure/camel-azure-storage-datalake/src/test/java/org/apache/camel/component/azure/storage/datalake/DataLakeConsumerFileThatCannotBeGotTest.java +++ b/components/camel-azure/camel-azure-storage-datalake/src/test/java/org/apache/camel/component/azure/storage/datalake/DataLakeConsumerFileThatCannotBeGotTest.java @@ -25,9 +25,11 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import com.azure.core.http.HttpResponse; import com.azure.core.http.rest.PagedIterable; +import com.azure.storage.blob.models.BlobStorageException; import com.azure.storage.file.datalake.DataLakeFileClient; import com.azure.storage.file.datalake.DataLakeFileSystemClient; import com.azure.storage.file.datalake.DataLakeServiceClient; @@ -45,6 +47,7 @@ import org.apache.camel.spi.PollingConsumerPollStrategy; import org.apache.camel.test.junit6.CamelTestSupport; 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.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -64,6 +67,8 @@ class DataLakeConsumerFileThatCannotBeGotTest extends CamelTestSupport { private final Set<String> forbidden = ConcurrentHashMap.newKeySet(); private final Set<String> deleted = ConcurrentHashMap.newKeySet(); private final CountDownLatch failedPolls = new CountDownLatch(2); + private final CountDownLatch emptyPolls = new CountDownLatch(2); + private final AtomicInteger rolledBackPolls = new AtomicInteger(); private final CountDownLatch skippedReported = new CountDownLatch(1); private final List<String> handled = new CopyOnWriteArrayList<>(); @@ -88,6 +93,25 @@ class DataLakeConsumerFileThatCannotBeGotTest extends CamelTestSupport { return false; } }); + context.getRegistry().bind("countEmptyPolls", new PollingConsumerPollStrategy() { + @Override + public boolean begin(Consumer consumer, Endpoint endpoint) { + return true; + } + + @Override + public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) { + if (polledMessages == 0) { + emptyPolls.countDown(); + } + } + + @Override + public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception e) { + rolledBackPolls.incrementAndGet(); + return false; + } + }); context.getRegistry().bind("recordErrors", new ExceptionHandler() { @Override public void handleException(Throwable exception) { @@ -151,6 +175,20 @@ class DataLakeConsumerFileThatCannotBeGotTest extends CamelTestSupport { assertTrue(handled.isEmpty(), "a file that no longer exists is not reported: " + handled); } + @Test + void fileNameThatDoesNotExistGivesAnEmptyPoll() throws Exception { + deleted.add("missing.txt"); + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(0); + + addConsumerRoute("&fileName=missing.txt&pollStrategy=#countEmptyPolls"); + + // before, the BlobStorageException (404) of the read failed every poll, with a WARN each time + assertTrue(emptyPolls.await(20, TimeUnit.SECONDS), "the polls are empty"); + assertEquals(0, rolledBackPolls.get(), "no poll fails"); + mock.assertIsSatisfied(); + } + @Test void pollFailsWhenNoListedFileCanBeGot() throws Exception { files.add("a.txt"); @@ -207,10 +245,11 @@ class DataLakeConsumerFileThatCannotBeGotTest extends CamelTestSupport { null); } if (deleted.contains(name)) { - // what the service answers to a read of a file deleted after the listing + // what the SDK throws when reading a file that does not exist: openInputStream reads through the blob + // endpoint and does not translate the exception into a DataLakeStorageException HttpResponse response = mock(HttpResponse.class); when(response.getStatusCode()).thenReturn(404); - throw new DataLakeStorageException("The specified path does not exist.", response, null); + throw new BlobStorageException("The specified blob does not exist.", response, null); } DataLakeFileOpenInputStreamResult result = mock(DataLakeFileOpenInputStreamResult.class); when(result.getInputStream()).thenReturn(new ByteArrayInputStream(name.getBytes(StandardCharsets.UTF_8)));
