Search in sources :

Example 1 with DriverExecutionException

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");
}
Also used : Path(java.nio.file.Path) DriverExecutionException(com.datastax.oss.driver.api.core.DriverExecutionException) BulkExecutionException(com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException) ReadResult(com.datastax.oss.dsbulk.executor.api.result.ReadResult) DefaultReadResult(com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult) DefaultReadResult(com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult) Test(org.junit.jupiter.api.Test)

Example 2 with DriverExecutionException

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");
}
Also used : Path(java.nio.file.Path) DriverExecutionException(com.datastax.oss.driver.api.core.DriverExecutionException) BulkExecutionException(com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException) DefaultWriteResult(com.datastax.oss.dsbulk.executor.api.result.DefaultWriteResult) DefaultWriteResult(com.datastax.oss.dsbulk.executor.api.result.DefaultWriteResult) WriteResult(com.datastax.oss.dsbulk.executor.api.result.WriteResult) MappedBoundStatement(com.datastax.oss.dsbulk.workflow.commons.statement.MappedBoundStatement) Test(org.junit.jupiter.api.Test)

Aggregations

DriverExecutionException (com.datastax.oss.driver.api.core.DriverExecutionException)2 BulkExecutionException (com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException)2 Path (java.nio.file.Path)2 Test (org.junit.jupiter.api.Test)2 DefaultReadResult (com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult)1 DefaultWriteResult (com.datastax.oss.dsbulk.executor.api.result.DefaultWriteResult)1 ReadResult (com.datastax.oss.dsbulk.executor.api.result.ReadResult)1 WriteResult (com.datastax.oss.dsbulk.executor.api.result.WriteResult)1 MappedBoundStatement (com.datastax.oss.dsbulk.workflow.commons.statement.MappedBoundStatement)1