Search in sources :

Example 6 with TooManyErrorsException

use of com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException in project dsbulk by datastax.

the class LogManagerTest method should_stop_at_first_error_when_max_errors_is_zero.

@Test
void should_stop_at_first_error_when_max_errors_is_zero() throws Exception {
    Path outputDir = Files.createTempDirectory("test");
    LogManager logManager = new LogManager(session, outputDir, ErrorThreshold.forAbsoluteValue(0), ErrorThreshold.forAbsoluteValue(0), true, statementFormatter, EXTENDED, rowFormatter);
    logManager.init();
    Flux<BatchableStatement<?>> stmts = Flux.just(unmappableStmt1);
    try {
        stmts.transform(logManager.newUnmappableStatementsHandler()).blockLast();
        fail("Expecting TooManyErrorsException to be thrown");
    } catch (TooManyErrorsException e) {
        assertThat(e).hasMessage("Too many errors, the maximum allowed is 0.");
        assertThat(((AbsoluteErrorThreshold) e.getThreshold()).getMaxErrors()).isEqualTo(0);
    }
    logManager.close();
    Path bad = logManager.getOperationDirectory().resolve("mapping.bad");
    Path errors = logManager.getOperationDirectory().resolve("mapping-errors.log");
    Path positions = logManager.getOperationDirectory().resolve("positions.txt");
    assertThat(bad.toFile()).exists();
    assertThat(errors.toFile()).exists();
    assertThat(positions.toFile()).exists();
    assertThat(FileUtils.listAllFilesInDirectory(logManager.getOperationDirectory())).containsOnly(bad, errors, positions);
    List<String> badLines = Files.readAllLines(bad, UTF_8);
    assertThat(badLines).hasSize(1);
    assertThat(badLines.get(0)).isEqualTo(source1.trim());
    List<String> lines = Files.readAllLines(errors, UTF_8);
    String content = String.join("\n", lines);
    assertThat(content).containsOnlyOnce("Resource: " + resource1).containsOnlyOnce("Position: 1").containsOnlyOnce("Source: " + LogManagerUtils.formatSingleLine(source1)).containsOnlyOnce("java.lang.RuntimeException: error 1");
}
Also used : Path(java.nio.file.Path) BatchableStatement(com.datastax.oss.driver.api.core.cql.BatchableStatement) TooManyErrorsException(com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException) Test(org.junit.jupiter.api.Test)

Example 7 with TooManyErrorsException

use of com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException in project dsbulk by datastax.

the class LogManagerTest method should_stop_when_sample_size_is_met_and_percentage_exceeded.

@Test
void should_stop_when_sample_size_is_met_and_percentage_exceeded() throws Exception {
    Path outputDir = Files.createTempDirectory("test");
    LogManager logManager = new LogManager(session, outputDir, ErrorThreshold.forRatio(0.01f, 100), ErrorThreshold.forAbsoluteValue(0), true, statementFormatter, EXTENDED, rowFormatter);
    logManager.init();
    Flux<ReadResult> stmts = Flux.just(failedReadResult1);
    try {
        stmts.repeat(101).transform(logManager.newTotalItemsCounter()).transform(logManager.newFailedReadsHandler()).blockLast();
        fail("Expecting TooManyErrorsException to be thrown");
    } catch (TooManyErrorsException e) {
        assertThat(e).hasMessage("Too many errors, the maximum allowed is 1%.");
        Assertions.assertThat(((RatioErrorThreshold) e.getThreshold()).getMaxErrorRatio()).isEqualTo(0.01f);
    }
    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);
    assertThat(lines.stream().filter(l -> l.contains("BulkExecutionException")).count()).isEqualTo(100);
}
Also used : Path(java.nio.file.Path) ReadResult(com.datastax.oss.dsbulk.executor.api.result.ReadResult) BeforeEach(org.junit.jupiter.api.BeforeEach) MappedBoundStatementPrinter(com.datastax.oss.dsbulk.workflow.commons.format.statement.MappedBoundStatementPrinter) DefaultWriteResult(com.datastax.oss.dsbulk.executor.api.result.DefaultWriteResult) EXTENDED(com.datastax.oss.dsbulk.format.statement.StatementFormatVerbosity.EXTENDED) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) DefaultErrorRecord(com.datastax.oss.dsbulk.connectors.api.DefaultErrorRecord) ByteBuffer(java.nio.ByteBuffer) UnmappableStatement(com.datastax.oss.dsbulk.workflow.commons.statement.UnmappableStatement) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions(org.assertj.core.api.Assertions) MappedBoundStatement(com.datastax.oss.dsbulk.workflow.commons.statement.MappedBoundStatement) URI(java.net.URI) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord) Path(java.nio.file.Path) Record(com.datastax.oss.dsbulk.connectors.api.Record) LogInterceptor(com.datastax.oss.dsbulk.tests.logging.LogInterceptor) DriverUtils.mockSession(com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockSession) StatementFormatter(com.datastax.oss.dsbulk.format.statement.StatementFormatter) RowFormatter(com.datastax.oss.dsbulk.format.row.RowFormatter) TestAssertions.assertThat(com.datastax.oss.dsbulk.tests.assertions.TestAssertions.assertThat) TooManyErrorsException(com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) Test(org.junit.jupiter.api.Test) List(java.util.List) BatchableStatement(com.datastax.oss.driver.api.core.cql.BatchableStatement) Lists(org.assertj.core.util.Lists) WARN(org.slf4j.event.Level.WARN) Mockito.mock(org.mockito.Mockito.mock) Fail.fail(org.assertj.core.api.Fail.fail) RatioErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.RatioErrorThreshold) DefaultReadResult(com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult) ErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.ErrorThreshold) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Row(com.datastax.oss.driver.api.core.cql.Row) DefaultBatchType(com.datastax.oss.driver.api.core.cql.DefaultBatchType) AbsoluteErrorThreshold(com.datastax.oss.dsbulk.workflow.api.error.AbsoluteErrorThreshold) FileUtils(com.datastax.oss.dsbulk.tests.utils.FileUtils) Files(java.nio.file.Files) DriverUtils.mockBoundStatement(com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockBoundStatement) UTF_8(java.nio.charset.StandardCharsets.UTF_8) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) DriverUtils.mockRow(com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockRow) Mockito.when(org.mockito.Mockito.when) BatchStatement(com.datastax.oss.driver.api.core.cql.BatchStatement) LogCapture(com.datastax.oss.dsbulk.tests.logging.LogCapture) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Flux(reactor.core.publisher.Flux) WriteResult(com.datastax.oss.dsbulk.executor.api.result.WriteResult) BulkExecutionException(com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException) DriverExecutionException(com.datastax.oss.driver.api.core.DriverExecutionException) LogInterceptingExtension(com.datastax.oss.dsbulk.tests.logging.LogInterceptingExtension) Statement(com.datastax.oss.driver.api.core.cql.Statement) TooManyErrorsException(com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException) ReadResult(com.datastax.oss.dsbulk.executor.api.result.ReadResult) DefaultReadResult(com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult) Test(org.junit.jupiter.api.Test)

Example 8 with TooManyErrorsException

use of com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException in project dsbulk by datastax.

the class LogManagerTest method should_stop_when_max_result_mapping_errors_reached.

@Test
void should_stop_when_max_result_mapping_errors_reached() 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();
    Flux<Record> stmts = Flux.just(rowRecord1, rowRecord2, rowRecord3);
    try {
        stmts.transform(logManager.newUnmappableRecordsHandler()).blockLast();
        fail("Expecting TooManyErrorsException to be thrown");
    } catch (TooManyErrorsException e) {
        assertThat(e).hasMessage("Too many errors, the maximum allowed is 2.");
        assertThat(((AbsoluteErrorThreshold) e.getThreshold()).getMaxErrors()).isEqualTo(2);
    }
    logManager.close();
    Path errors = logManager.getOperationDirectory().resolve("mapping-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("Source: ").doesNotContain("Resource: ").doesNotContain("Position: ").contains("SELECT 1").containsOnlyOnce("c1: 1").containsOnlyOnce("java.lang.RuntimeException: error 1").contains("SELECT 2").containsOnlyOnce("c1: 2").containsOnlyOnce("java.lang.RuntimeException: error 2").doesNotContain("c3: 3");
}
Also used : Path(java.nio.file.Path) TooManyErrorsException(com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException) DefaultErrorRecord(com.datastax.oss.dsbulk.connectors.api.DefaultErrorRecord) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord) Record(com.datastax.oss.dsbulk.connectors.api.Record) Test(org.junit.jupiter.api.Test)

Example 9 with TooManyErrorsException

use of com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException in project dsbulk by datastax.

the class LogManagerTest method should_stop_when_max_read_errors_reached.

@Test
void should_stop_when_max_read_errors_reached() 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();
    Flux<ReadResult> stmts = Flux.just(failedReadResult1, failedReadResult2, failedReadResult3);
    try {
        stmts.transform(logManager.newFailedReadsHandler()).blockLast();
        fail("Expecting TooManyErrorsException to be thrown");
    } catch (TooManyErrorsException e) {
        assertThat(e).hasMessage("Too many errors, the maximum allowed is 2.");
        assertThat(((AbsoluteErrorThreshold) e.getThreshold()).getMaxErrors()).isEqualTo(2);
    }
    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("Position: ").doesNotContain("Source: ").contains("SELECT 1").containsOnlyOnce("com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException: Statement execution failed: SELECT 1 (error 1)").contains("SELECT 2").containsOnlyOnce("com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException: Statement execution failed: SELECT 2 (error 2)");
}
Also used : Path(java.nio.file.Path) TooManyErrorsException(com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException) ReadResult(com.datastax.oss.dsbulk.executor.api.result.ReadResult) DefaultReadResult(com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult) Test(org.junit.jupiter.api.Test)

Aggregations

TooManyErrorsException (com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException)9 Path (java.nio.file.Path)9 Test (org.junit.jupiter.api.Test)9 DefaultWriteResult (com.datastax.oss.dsbulk.executor.api.result.DefaultWriteResult)4 WriteResult (com.datastax.oss.dsbulk.executor.api.result.WriteResult)4 BatchableStatement (com.datastax.oss.driver.api.core.cql.BatchableStatement)3 DefaultErrorRecord (com.datastax.oss.dsbulk.connectors.api.DefaultErrorRecord)3 DefaultRecord (com.datastax.oss.dsbulk.connectors.api.DefaultRecord)3 Record (com.datastax.oss.dsbulk.connectors.api.Record)3 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)2 BatchStatement (com.datastax.oss.driver.api.core.cql.BatchStatement)2 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)2 Row (com.datastax.oss.driver.api.core.cql.Row)2 DefaultReadResult (com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult)2 ReadResult (com.datastax.oss.dsbulk.executor.api.result.ReadResult)2 DriverUtils.mockRow (com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockRow)2 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 DriverExecutionException (com.datastax.oss.driver.api.core.DriverExecutionException)1 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)1 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)1