gnodet-bot commented on code in PR #29155:
URL: https://github.com/apache/camel/pull/29155#discussion_r4466440293


##########
components/camel-azure/camel-azure-storage-datalake/src/test/java/org/apache/camel/component/azure/storage/datalake/operations/DataLakeFileOperationTest.java:
##########
@@ -94,6 +97,49 @@ void testGetFile() throws IOException {
         assertNotNull(secondResponse.getHeaders());
     }
 
+    @Test
+    void testFlushUsesAbsoluteHeaderPosition() {
+        when(client.flushWithResponse(anyLong(), any(), any(), any(), any(), 
any()))
+                .thenReturn(new ResponseBase<>(
+                        null, 200, new HttpHeaders(),
+                        new PathInfo("testTag", OffsetDateTime.now()), null));
+        final Exchange exchange = new DefaultExchange(context);
+        configuration.setPosition(110L);
+        exchange.getIn().setHeader(DataLakeConstants.POSITION, 120L);
+
+        new DataLakeFileOperations(configuration, 
client).flushToFile(exchange);
+
+        verify(client).flushWithResponse(eq(120L), any(), any(), any(), any(), 
any());
+        verify(client, never()).getFileSize();
+    }
+
+    @Test
+    void testFlushUsesAbsoluteConfiguredPosition() {
+        configuration.setPosition(120L);
+        when(client.flushWithResponse(anyLong(), any(), any(), any(), any(), 
any()))
+                .thenReturn(new ResponseBase<>(
+                        null, 200, new HttpHeaders(),
+                        new PathInfo("testTag", OffsetDateTime.now()), null));
+
+        new DataLakeFileOperations(configuration, client).flushToFile(new 
DefaultExchange(context));
+
+        verify(client).flushWithResponse(eq(120L), any(), any(), any(), any(), 
any());
+        verify(client, never()).getFileSize();
+    }
+
+    @Test
+    void testFlushUsesCurrentLengthWhenPositionIsAbsent() {
+        when(client.getFileSize()).thenReturn(100L);
+        when(client.flushWithResponse(anyLong(), any(), any(), any(), any(), 
any()))
+                .thenReturn(new ResponseBase<>(
+                        null, 200, new HttpHeaders(),
+                        new PathInfo("testTag", OffsetDateTime.now()), null));
+
+        new DataLakeFileOperations(configuration, client).flushToFile(new 
DefaultExchange(context));
+
+        verify(client).flushWithResponse(eq(100L), any(), any(), any(), any(), 
any());

Review Comment:
   ⚠️ **Weak test — passes before and after the fix.**
   
   The old code computed `flushPosition = (position != null ? position : 0L) + 
fileClientWrapper.getFileSize()`. With no position set and `getFileSize()` 
returning `100`, the old code gives `0 + 100 = 100`. The new code gives 
`getFileSize() = 100`. The result is identical, so this test passes without the 
fix.
   
   Add `verify(client).getFileSize()` to at least confirm the fallback path 
actually invokes `getFileSize()`. Better yet, mock `getFileSize()` to return a 
value distinct from any residual position (e.g. `75L`) and assert flush is 
called with `75L` — that removes any ambiguity.
   
   ```suggestion
           verify(client).flushWithResponse(eq(100L), any(), any(), any(), 
any(), any());
           verify(client).getFileSize();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to