Search in sources :

Example 1 with BulkExecutionException

use of com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException in project dsbulk by datastax.

the class MetricsCollectingExecutionListenerTest method should_collect_metrics.

@Test
void should_collect_metrics() {
    MetricsCollectingExecutionListener listener = new MetricsCollectingExecutionListener();
    ExecutionContext global = new TestExecutionContext();
    ExecutionContext local1 = new TestExecutionContext();
    ExecutionContext local2 = new TestExecutionContext();
    ExecutionContext local3 = new TestExecutionContext();
    ExecutionContext local4 = new TestExecutionContext();
    listener.onExecutionStarted(successfulRead, global);
    listener.onExecutionStarted(failedRead, global);
    listener.onExecutionStarted(successfulWrite, global);
    listener.onExecutionStarted(failedWrite, global);
    assertThat(listener.getInFlightRequestsCounter().getCount()).isEqualTo(0);
    assertThat(listener.getBytesSentMeter().get().getCount()).isEqualTo(0);
    assertThat(listener.getBytesReceivedMeter().get().getCount()).isEqualTo(0);
    listener.onReadRequestStarted(successfulRead, local1);
    assertThat(listener.getInFlightRequestsCounter().getCount()).isEqualTo(1);
    listener.onReadRequestStarted(failedRead, local2);
    assertThat(listener.getInFlightRequestsCounter().getCount()).isEqualTo(2);
    listener.onWriteRequestStarted(successfulWrite, local3);
    assertThat(listener.getInFlightRequestsCounter().getCount()).isEqualTo(3);
    assertThat(listener.getBytesSentMeter().get().getCount()).isEqualTo(8);
    listener.onWriteRequestStarted(failedWrite, local4);
    assertThat(listener.getBytesSentMeter().get().getCount()).isEqualTo(16);
    assertThat(listener.getInFlightRequestsCounter().getCount()).isEqualTo(4);
    listener.onReadRequestSuccessful(successfulRead, local1);
    // simulate 3 rows received
    listener.onRowReceived(row, local1);
    assertThat(listener.getBytesReceivedMeter().get().getCount()).isEqualTo(4);
    listener.onRowReceived(row, local1);
    assertThat(listener.getBytesReceivedMeter().get().getCount()).isEqualTo(8);
    listener.onRowReceived(row, local1);
    assertThat(listener.getBytesReceivedMeter().get().getCount()).isEqualTo(12);
    assertThat(listener.getInFlightRequestsCounter().getCount()).isEqualTo(3);
    listener.onReadRequestFailed(failedRead, new RuntimeException(), local2);
    assertThat(listener.getInFlightRequestsCounter().getCount()).isEqualTo(2);
    listener.onWriteRequestSuccessful(successfulWrite, local3);
    assertThat(listener.getInFlightRequestsCounter().getCount()).isEqualTo(1);
    listener.onWriteRequestFailed(failedWrite, new RuntimeException(), local4);
    assertThat(listener.getInFlightRequestsCounter().getCount()).isEqualTo(0);
    listener.onExecutionSuccessful(successfulRead, global);
    listener.onExecutionFailed(new BulkExecutionException(new RuntimeException(), failedRead), global);
    listener.onExecutionSuccessful(successfulWrite, global);
    listener.onExecutionFailed(new BulkExecutionException(new RuntimeException(), failedWrite), global);
    // 3 successful reads
    // 1 failed read
    // 2 successful writes
    // 2 failed writes
    assertThat(listener.getTotalStatementsTimer().getCount()).isEqualTo(4);
    assertThat(listener.getFailedStatementsCounter().getCount()).isEqualTo(2);
    assertThat(listener.getSuccessfulStatementsCounter().getCount()).isEqualTo(2);
    assertThat(listener.getTotalReadsWritesTimer().getCount()).isEqualTo(8);
    assertThat(listener.getFailedReadsWritesCounter().getCount()).isEqualTo(3);
    assertThat(listener.getSuccessfulReadsWritesCounter().getCount()).isEqualTo(5);
    assertThat(listener.getTotalWritesTimer().getCount()).isEqualTo(4);
    assertThat(listener.getFailedWritesCounter().getCount()).isEqualTo(2);
    assertThat(listener.getSuccessfulWritesCounter().getCount()).isEqualTo(2);
    assertThat(listener.getTotalReadsTimer().getCount()).isEqualTo(4);
    assertThat(listener.getFailedReadsCounter().getCount()).isEqualTo(1);
    assertThat(listener.getSuccessfulReadsCounter().getCount()).isEqualTo(3);
}
Also used : BulkExecutionException(com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException) Test(org.junit.jupiter.api.Test)

Example 2 with BulkExecutionException

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

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

use of com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException 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 5 with BulkExecutionException

use of com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException in project dsbulk by datastax.

the class MetricsCollectingExecutionListenerTest method should_not_collect_throughput_metrics.

@Test
void should_not_collect_throughput_metrics() {
    MetricsCollectingExecutionListener listener = new MetricsCollectingExecutionListener(new MetricRegistry(), ProtocolVersion.DEFAULT, CodecRegistry.DEFAULT, false);
    assertThat(listener.getBytesSentMeter()).isNotPresent();
    assertThat(listener.getBytesReceivedMeter()).isNotPresent();
    // 3 successful reads
    // 1 failed read
    // 2 successful writes
    // 2 failed writes
    ExecutionContext global = new TestExecutionContext();
    ExecutionContext local1 = new TestExecutionContext();
    ExecutionContext local2 = new TestExecutionContext();
    ExecutionContext local3 = new TestExecutionContext();
    ExecutionContext local4 = new TestExecutionContext();
    listener.onExecutionStarted(successfulRead, global);
    listener.onExecutionStarted(failedRead, global);
    listener.onExecutionStarted(successfulWrite, global);
    listener.onExecutionStarted(failedWrite, global);
    listener.onReadRequestStarted(successfulRead, local1);
    listener.onReadRequestStarted(failedRead, local2);
    listener.onWriteRequestStarted(successfulWrite, local3);
    listener.onWriteRequestStarted(failedWrite, local4);
    listener.onReadRequestSuccessful(successfulRead, local1);
    listener.onRowReceived(row, local1);
    listener.onRowReceived(row, local1);
    listener.onRowReceived(row, local1);
    listener.onReadRequestFailed(failedRead, new RuntimeException(), local2);
    listener.onWriteRequestSuccessful(successfulWrite, local3);
    listener.onWriteRequestFailed(failedWrite, new RuntimeException(), local4);
    listener.onExecutionSuccessful(successfulRead, global);
    listener.onExecutionFailed(new BulkExecutionException(new RuntimeException(), failedRead), global);
    listener.onExecutionSuccessful(successfulWrite, global);
    listener.onExecutionFailed(new BulkExecutionException(new RuntimeException(), failedWrite), global);
    assertThat(listener.getBytesSentMeter()).isNotPresent();
    assertThat(listener.getBytesReceivedMeter()).isNotPresent();
}
Also used : BulkExecutionException(com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException) MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

BulkExecutionException (com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException)7 Test (org.junit.jupiter.api.Test)6 ReadResult (com.datastax.oss.dsbulk.executor.api.result.ReadResult)4 DriverExecutionException (com.datastax.oss.driver.api.core.DriverExecutionException)3 DefaultReadResult (com.datastax.oss.dsbulk.executor.api.result.DefaultReadResult)3 DefaultWriteResult (com.datastax.oss.dsbulk.executor.api.result.DefaultWriteResult)3 WriteResult (com.datastax.oss.dsbulk.executor.api.result.WriteResult)3 Path (java.nio.file.Path)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)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 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)2 DefaultErrorRecord (com.datastax.oss.dsbulk.connectors.api.DefaultErrorRecord)2 DriverUtils.mockRow (com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockRow)2 MappedBoundStatement (com.datastax.oss.dsbulk.workflow.commons.statement.MappedBoundStatement)2 List (java.util.List)2 Flux (reactor.core.publisher.Flux)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1