use of com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult in project dsbulk by datastax.
the class LogManagerTest method should_stop_when_unrecoverable_error_reading.
@Test
void should_stop_when_unrecoverable_error_reading() throws Exception {
Path outputDir = Files.createTempDirectory("test");
LogManager logManager = new LogManager(session, outputDir, ErrorThreshold.forAbsoluteValue(2), ErrorThreshold.forAbsoluteValue(0), true, statementFormatter, EXTENDED, rowFormatter);
logManager.init();
DefaultReadResult result = new DefaultReadResult(new BulkExecutionException(new DriverExecutionException(new IllegalArgumentException("error 1")), mockBoundStatement("SELECT 1")));
Flux<ReadResult> stmts = Flux.just(result);
try {
stmts.transform(logManager.newFailedReadsHandler()).blockLast();
fail("Expecting DriverExecutionException to be thrown");
} catch (DriverExecutionException e) {
assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class).hasMessage("error 1");
}
logManager.close();
Path errors = logManager.getOperationDirectory().resolve("unload-errors.log");
assertThat(errors.toFile()).exists();
assertThat(FileUtils.listAllFilesInDirectory(logManager.getOperationDirectory())).containsOnly(errors);
List<String> lines = Files.readAllLines(errors, UTF_8);
String content = String.join("\n", lines);
assertThat(content).doesNotContain("Resource: ").doesNotContain("Source: ").doesNotContain("Position: ").contains("SELECT 1").contains("error 1").containsOnlyOnce("com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException: Statement execution failed: SELECT 1");
}
use of com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult in project dsbulk by datastax.
the class ContinuousReadResultSubscription method toPage.
@Override
Page toPage(ContinuousAsyncResultSet rs, ExecutionContext local) {
Iterator<Row> rows = rs.currentPage().iterator();
Iterator<ReadResult> results = new AbstractIterator<ReadResult>() {
@Override
protected ReadResult computeNext() {
if (rows.hasNext()) {
Row row = rows.next();
if (listener != null) {
listener.onRowReceived(row, local);
}
return new DefaultReadResult(statement, rs.getExecutionInfo(), row);
}
return endOfData();
}
};
return new ContinuousPage(rs, results);
}
use of com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult in project dsbulk by datastax.
the class ReadResultSubscription method toPage.
@Override
Page toPage(AsyncResultSet rs, ExecutionContext local) {
Iterator<Row> rows = rs.currentPage().iterator();
Iterator<ReadResult> results = new AbstractIterator<ReadResult>() {
@Override
protected ReadResult computeNext() {
if (rows.hasNext()) {
Row row = rows.next();
if (listener != null) {
listener.onRowReceived(row, local);
}
return new DefaultReadResult(statement, rs.getExecutionInfo(), row);
}
return endOfData();
}
};
return new Page(results, rs.hasMorePages() ? rs::fetchNextPage : null);
}
use of com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult in project dsbulk by datastax.
the class LogManagerTest method should_log_query_warnings_when_reading.
@Test
void should_log_query_warnings_when_reading(@LogCapture(value = LogManager.class, level = WARN) LogInterceptor logs) throws Exception {
Path outputDir = Files.createTempDirectory("test");
LogManager logManager = new LogManager(session, outputDir, ErrorThreshold.forAbsoluteValue(100), ErrorThreshold.forAbsoluteValue(1), true, statementFormatter, EXTENDED, rowFormatter);
logManager.init();
ExecutionInfo info1 = mock(ExecutionInfo.class);
when(info1.getWarnings()).thenReturn(ImmutableList.of("warning1", "warning2"));
ExecutionInfo info2 = mock(ExecutionInfo.class);
when(info2.getWarnings()).thenReturn(ImmutableList.of("warning3"));
Flux.just(new DefaultReadResult(SimpleStatement.newInstance("SELECT 1"), info1, mockRow(1)), new DefaultReadResult(SimpleStatement.newInstance("SELECT 2"), info2, mockRow(2))).transform(logManager.newQueryWarningsHandler()).blockLast();
logManager.close();
assertThat(logs).hasMessageContaining("Query generated server-side warning: warning1").doesNotHaveMessageContaining("warning2").doesNotHaveMessageContaining("warning3").hasMessageContaining("The maximum number of logged query warnings has been exceeded (1); " + "subsequent warnings will not be logged.");
}
use of com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult in project dsbulk by datastax.
the class LogManagerTest method setUp.
@BeforeEach
void setUp() throws Exception {
session = mockSession();
resource1 = new URI("file:///file1.csv");
resource2 = new URI("file:///file2.csv");
resource3 = new URI("file:///file3.csv");
csvRecord1 = new DefaultErrorRecord(source1, resource1, 1, new RuntimeException("error 1"));
csvRecord2 = new DefaultErrorRecord(source2, resource2, 2, new RuntimeException("error 2"));
csvRecord3 = new DefaultErrorRecord(source3, resource3, 3, new RuntimeException("error 3"));
unmappableStmt1 = new UnmappableStatement(csvRecord1, new RuntimeException("error 1"));
unmappableStmt2 = new UnmappableStatement(csvRecord2, new RuntimeException("error 2"));
unmappableStmt3 = new UnmappableStatement(csvRecord3, new RuntimeException("error 3"));
failedWriteResult1 = new DefaultWriteResult(new BulkExecutionException(new DriverTimeoutException("error 1"), new MappedBoundStatement(csvRecord1, mockBoundStatement("INSERT 1"))));
failedWriteResult2 = new DefaultWriteResult(new BulkExecutionException(new DriverTimeoutException("error 2"), new MappedBoundStatement(csvRecord2, mockBoundStatement("INSERT 2"))));
failedWriteResult3 = new DefaultWriteResult(new BulkExecutionException(new DriverTimeoutException("error 3"), new MappedBoundStatement(csvRecord3, mockBoundStatement("INSERT 3"))));
failedReadResult1 = new DefaultReadResult(new BulkExecutionException(new DriverTimeoutException("error 1"), mockBoundStatement("SELECT 1")));
failedReadResult2 = new DefaultReadResult(new BulkExecutionException(new DriverTimeoutException("error 2"), mockBoundStatement("SELECT 2")));
failedReadResult3 = new DefaultReadResult(new BulkExecutionException(new DriverTimeoutException("error 3"), mockBoundStatement("SELECT 3")));
BatchStatement batch = BatchStatement.newInstance(DefaultBatchType.UNLOGGED, new MappedBoundStatement(csvRecord1, mockBoundStatement("INSERT 1", "foo", 42)), new MappedBoundStatement(csvRecord2, mockBoundStatement("INSERT 2", "bar", 43)), new MappedBoundStatement(csvRecord3, mockBoundStatement("INSERT 3", "qix", 44)));
batchWriteResult = new DefaultWriteResult(new BulkExecutionException(new DriverTimeoutException("error batch"), batch));
ExecutionInfo info = mock(ExecutionInfo.class);
row1 = mockRow(1);
Row row2 = mockRow(2);
Row row3 = mockRow(3);
Statement<?> stmt1 = SimpleStatement.newInstance("SELECT 1");
Statement<?> stmt2 = SimpleStatement.newInstance("SELECT 2");
Statement<?> stmt3 = SimpleStatement.newInstance("SELECT 3");
successfulReadResult1 = new DefaultReadResult(stmt1, info, row1);
ReadResult successfulReadResult2 = new DefaultReadResult(stmt2, info, row2);
ReadResult successfulReadResult3 = new DefaultReadResult(stmt3, info, row3);
rowRecord1 = new DefaultErrorRecord(successfulReadResult1, tableResource, 1, new RuntimeException("error 1"));
rowRecord2 = new DefaultErrorRecord(successfulReadResult2, tableResource, 2, new RuntimeException("error 2"));
rowRecord3 = new DefaultErrorRecord(successfulReadResult3, tableResource, 3, new RuntimeException("error 3"));
}
Aggregations