use of com.datastax.oss.driver.api.core.DriverExecutionException 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.driver.api.core.DriverExecutionException in project dsbulk by datastax.
the class LogManagerTest method should_stop_when_unrecoverable_error_writing.
@Test
void should_stop_when_unrecoverable_error_writing() throws Exception {
Path outputDir = Files.createTempDirectory("test4");
LogManager logManager = new LogManager(session, outputDir, ErrorThreshold.forAbsoluteValue(1000), ErrorThreshold.forAbsoluteValue(0), true, statementFormatter, EXTENDED, rowFormatter);
logManager.init();
DefaultWriteResult result = new DefaultWriteResult(new BulkExecutionException(new DriverExecutionException(new IllegalArgumentException("error 1")), new MappedBoundStatement(csvRecord1, mockBoundStatement("INSERT 1"))));
Flux<WriteResult> stmts = Flux.just(result);
try {
stmts.transform(logManager.newFailedWritesHandler()).blockLast();
fail("Expecting DriverExecutionException to be thrown");
} catch (DriverExecutionException e) {
assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class).hasMessage("error 1");
}
logManager.close();
Path bad = logManager.getOperationDirectory().resolve("load.bad");
Path errors = logManager.getOperationDirectory().resolve("load-errors.log");
Path positions = logManager.getOperationDirectory().resolve("positions.txt");
assertThat(bad.toFile()).exists();
assertThat(errors.toFile()).exists();
assertThat(positions.toFile()).exists();
List<String> badLines = Files.readAllLines(bad, UTF_8);
assertThat(badLines).hasSize(1);
assertThat(badLines.get(0)).isEqualTo(source1.trim());
assertThat(FileUtils.listAllFilesInDirectory(logManager.getOperationDirectory())).containsOnly(bad, errors, positions);
List<String> lines = Files.readAllLines(errors, UTF_8);
String content = String.join("\n", lines);
assertThat(content).containsOnlyOnce("Resource: " + resource1).containsOnlyOnce("Source: " + LogManagerUtils.formatSingleLine(source1)).contains("Position: 1").contains("INSERT 1").contains("error 1").containsOnlyOnce("com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException: Statement execution failed: INSERT 1");
List<String> positionLines = Files.readAllLines(positions, UTF_8);
assertThat(positionLines).contains("file:///file1.csv:1");
}
Aggregations