Skip to content

Commit baa94ce

Browse files
committed
Conditional check added for log raw records
1 parent 58c5051 commit baa94ce

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

data-loader/core/src/main/java/com/scalar/db/dataloader/core/dataimport/log/AbstractImportLogger.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public void onTransactionBatchCompleted(ImportTransactionBatchResult batchResult
7575
if (shouldSkipLoggingSuccess(batchResult)) {
7676
return;
7777
}
78+
// Skip logging records if log raw records is not enabled and execution is not success
79+
if (!batchResult.isSuccess() && !config.isLogRawSourceRecordsEnabled()) {
80+
return;
81+
}
7882

7983
logTransactionBatch(batchResult);
8084
notifyTransactionBatchCompleted(batchResult);

data-loader/core/src/test/java/com/scalar/db/dataloader/core/dataimport/log/SingleFileImportLoggerTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.junit.jupiter.api.BeforeEach;
2626
import org.junit.jupiter.api.Test;
2727
import org.junit.jupiter.api.io.TempDir;
28+
import org.mockito.Mockito;
2829
import org.slf4j.Logger;
2930
import org.slf4j.LoggerFactory;
3031

@@ -262,4 +263,28 @@ private void assertDataChunkStatusEquals(
262263
assertEquals(
263264
expected.getTotalDurationInMilliSeconds(), actual.getTotalDurationInMilliSeconds());
264265
}
266+
267+
@Test
268+
void onTransactionBatchCompleted_ShouldNotLogOrNotify_WhenRawLoggingIsSkipped()
269+
throws IOException {
270+
// Arrange
271+
ImportLoggerConfig config =
272+
ImportLoggerConfig.builder()
273+
.logDirectoryPath(tempDir.toString() + "/")
274+
.isLogRawSourceRecordsEnabled(false)
275+
.isLogSuccessRecordsEnabled(true) // success logging OFF
276+
.build();
277+
278+
// Spy on logger to verify internal calls
279+
SingleFileImportLogger loggerSpy =
280+
Mockito.spy(new SingleFileImportLogger(config, logWriterFactory));
281+
282+
ImportTransactionBatchResult batch = createBatchResults(1, false).get(0); // success batch
283+
284+
// Act
285+
loggerSpy.onTransactionBatchCompleted(batch);
286+
287+
// Assert
288+
Mockito.verify(loggerSpy, Mockito.never()).logTransactionBatch(Mockito.any());
289+
}
265290
}

0 commit comments

Comments
 (0)