Search in sources :

Example 1 with ReadResult

use of com.datastax.oss.dsbulk.executor.api.result.ReadResult in project dsbulk by datastax.

the class BulkExecutorITBase method verifyReads.

protected void verifyReads(int expectedSuccessful, int expectedFailed, Iterable<ReadResult> actual) {
    AtomicInteger i = new AtomicInteger();
    long actualSuccessful = Flux.fromIterable(actual).filter(Result::isSuccess).map(result -> result.getRow().orElseThrow(AssertionError::new)).map(row -> row.getInt("pk")).sort().doOnNext(pk -> {
        assertThat(pk).isEqualTo(i.get());
        i.getAndIncrement();
    }).count().blockOptional().orElse(0L);
    assertThat(actualSuccessful).isEqualTo(expectedSuccessful);
    long actualFailed = Flux.fromIterable(actual).filter(r -> !r.isSuccess()).doOnNext(r -> {
        assertThat(r.getRow().isPresent()).isFalse();
        assertThat(r.getError().isPresent()).isTrue();
        BulkExecutionException error = r.getError().get();
        verifyException(error);
    }).count().blockOptional().orElse(0L);
    assertThat(actualFailed).isEqualTo(expectedFailed);
}
Also used : SyntaxError(com.datastax.oss.driver.api.core.servererrors.SyntaxError) Strictness(org.mockito.quality.Strictness) ReadResult(com.datastax.oss.dsbulk.executor.api.result.ReadResult) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Result(com.datastax.oss.dsbulk.executor.api.result.Result) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ArgumentCaptor(org.mockito.ArgumentCaptor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Flux(reactor.core.publisher.Flux) WriteResult(com.datastax.oss.dsbulk.executor.api.result.WriteResult) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Assertions.fail(org.assertj.core.api.Assertions.fail) BulkExecutionException(com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException) Stream(java.util.stream.Stream) StreamSupport.stream(java.util.stream.StreamSupport.stream) MockitoSession(org.mockito.MockitoSession) Queue(java.util.Queue) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) BulkExecutionException(com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with ReadResult

use of com.datastax.oss.dsbulk.executor.api.result.ReadResult 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 3 with ReadResult

use of com.datastax.oss.dsbulk.executor.api.result.ReadResult 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 4 with ReadResult

use of com.datastax.oss.dsbulk.executor.api.result.ReadResult in project dsbulk by datastax.

the class LogManager method appendUnmappableReadResultToDebugFile.

// row -> record failed (unload workflow)
@SuppressWarnings("BlockingMethodInNonBlockingContext")
private Mono<ErrorRecord> appendUnmappableReadResultToDebugFile(ErrorRecord record) {
    try {
        Path logFile = operationDirectory.resolve(MAPPING_ERRORS_FILE);
        PrintWriter writer = openFiles.get(logFile);
        assert writer != null;
        // Don't print the resource since it will be just cql://keyspace/table
        if (record.getSource() instanceof ReadResult) {
            ReadResult source = (ReadResult) record.getSource();
            appendStatement(source, MAPPING_ERRORS_FILE, false);
            source.getRow().ifPresent(row -> {
                writer.print("Row: ");
                String format = rowFormatter.format(row, protocolVersion, codecRegistry);
                LogManagerUtils.printAndMaybeAddNewLine(format, writer);
            });
        }
        stackTracePrinter.printStackTrace(record.getError(), writer);
        writer.println();
        writer.flush();
        return Mono.just(record);
    } catch (Exception e) {
        return Mono.error(e);
    }
}
Also used : Path(java.nio.file.Path) ReadResult(com.datastax.oss.dsbulk.executor.api.result.ReadResult) InvalidMappingException(com.datastax.oss.dsbulk.workflow.commons.schema.InvalidMappingException) BusyConnectionException(com.datastax.oss.driver.api.core.connection.BusyConnectionException) QueryExecutionException(com.datastax.oss.driver.api.core.servererrors.QueryExecutionException) TooManyErrorsException(com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException) AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) RequestThrottlingException(com.datastax.oss.driver.api.core.RequestThrottlingException) InvalidQueryException(com.datastax.oss.driver.api.core.servererrors.InvalidQueryException) FrameTooLongException(com.datastax.oss.driver.api.core.connection.FrameTooLongException) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 5 with ReadResult

use of com.datastax.oss.dsbulk.executor.api.result.ReadResult 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);
}
Also used : ReadResult(com.datastax.oss.dsbulk.executor.api.result.ReadResult) DefaultReadResult(com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult) Row(com.datastax.oss.driver.api.core.cql.Row) AbstractIterator(com.datastax.oss.driver.shaded.guava.common.collect.AbstractIterator) DefaultReadResult(com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult)

Aggregations

ReadResult (com.datastax.oss.dsbulk.executor.api.result.ReadResult)9 DefaultReadResult (com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult)7 Path (java.nio.file.Path)5 Test (org.junit.jupiter.api.Test)5 Row (com.datastax.oss.driver.api.core.cql.Row)4 BulkExecutionException (com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException)4 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)3 TooManyErrorsException (com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 DriverExecutionException (com.datastax.oss.driver.api.core.DriverExecutionException)2 BatchStatement (com.datastax.oss.driver.api.core.cql.BatchStatement)2 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)2 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)2 AbstractIterator (com.datastax.oss.driver.shaded.guava.common.collect.AbstractIterator)2 DefaultErrorRecord (com.datastax.oss.dsbulk.connectors.api.DefaultErrorRecord)2 DefaultWriteResult (com.datastax.oss.dsbulk.executor.api.result.DefaultWriteResult)2 WriteResult (com.datastax.oss.dsbulk.executor.api.result.WriteResult)2 List (java.util.List)2 Flux (reactor.core.publisher.Flux)2 AllNodesFailedException (com.datastax.oss.driver.api.core.AllNodesFailedException)1