Search in sources :

Example 11 with WriteResult

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

the class LogManager method appendStatement.

@SuppressWarnings("BlockingMethodInNonBlockingContext")
private <R extends Result> Mono<R> appendStatement(R result, String logFileName, boolean appendNewLine) {
    try {
        Path logFile = operationDirectory.resolve(logFileName);
        PrintWriter writer = openFiles.get(logFile);
        assert writer != null;
        writer.print("Statement: ");
        String format = statementFormatter.format(result.getStatement(), statementFormatVerbosity, protocolVersion, codecRegistry);
        LogManagerUtils.printAndMaybeAddNewLine(format, writer);
        if (result instanceof WriteResult) {
            WriteResult writeResult = (WriteResult) result;
            // If a conditional update could not be applied, print the failed mutations
            if (writeResult.isSuccess() && !writeResult.wasApplied()) {
                writer.println("Failed conditional updates: ");
                writeResult.getFailedWrites().forEach(row -> {
                    String failed = rowFormatter.format(row, protocolVersion, codecRegistry);
                    LogManagerUtils.printAndMaybeAddNewLine(failed, writer);
                });
            }
        }
        if (result.getError().isPresent()) {
            stackTracePrinter.printStackTrace(result.getError().get(), writer);
        }
        if (appendNewLine) {
            writer.println();
        }
        writer.flush();
        return Mono.just(result);
    } catch (Exception e) {
        return Mono.error(e);
    }
}
Also used : Path(java.nio.file.Path) WriteResult(com.datastax.oss.dsbulk.executor.api.result.WriteResult) 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 12 with WriteResult

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

the class BulkExecutorTestBase method writeSyncStringTest.

// Tests for synchronous write methods
@Test
void writeSyncStringTest() {
    BulkExecutor executor = newBulkExecutor(false);
    WriteResult r = executor.writeSync("write should succeed 1");
    verifySuccessfulWriteResult(r);
    verifySession(1, 0);
}
Also used : WriteResult(com.datastax.oss.dsbulk.executor.api.result.WriteResult) Test(org.junit.jupiter.api.Test)

Example 13 with WriteResult

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

the class BulkExecutorTestBase method writeAsyncStatementFailSafeTest.

@Test
void writeAsyncStatementFailSafeTest() throws Exception {
    BulkExecutor executor = newBulkExecutor(true);
    WriteResult r = executor.writeAsync(failed).get();
    verifyFailedWriteResult(r);
    verifySession(0, 1);
    verifyListener(0, 1);
}
Also used : WriteResult(com.datastax.oss.dsbulk.executor.api.result.WriteResult) Test(org.junit.jupiter.api.Test)

Example 14 with WriteResult

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

the class BulkExecutorTestBase method writeSyncStatementFailSafeTest.

@Test
void writeSyncStatementFailSafeTest() {
    BulkExecutor executor = newBulkExecutor(true);
    WriteResult r = executor.writeSync(failed);
    verifyFailedWriteResult(r);
    verifySession(0, 1);
    verifyListener(0, 1);
}
Also used : WriteResult(com.datastax.oss.dsbulk.executor.api.result.WriteResult) Test(org.junit.jupiter.api.Test)

Example 15 with WriteResult

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

the class BulkExecutorTestBase method writeSyncStringFailSafeTest.

@Test
void writeSyncStringFailSafeTest() {
    BulkExecutor executor = newBulkExecutor(true);
    WriteResult r = executor.writeSync("should fail");
    verifyFailedWriteResult(r);
    verifySession(0, 1);
    verifyListener(0, 1);
}
Also used : WriteResult(com.datastax.oss.dsbulk.executor.api.result.WriteResult) Test(org.junit.jupiter.api.Test)

Aggregations

WriteResult (com.datastax.oss.dsbulk.executor.api.result.WriteResult)23 Test (org.junit.jupiter.api.Test)22 Path (java.nio.file.Path)6 DefaultWriteResult (com.datastax.oss.dsbulk.executor.api.result.DefaultWriteResult)5 TooManyErrorsException (com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException)4 AllNodesFailedException (com.datastax.oss.driver.api.core.AllNodesFailedException)1 DriverExecutionException (com.datastax.oss.driver.api.core.DriverExecutionException)1 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)1 RequestThrottlingException (com.datastax.oss.driver.api.core.RequestThrottlingException)1 BusyConnectionException (com.datastax.oss.driver.api.core.connection.BusyConnectionException)1 FrameTooLongException (com.datastax.oss.driver.api.core.connection.FrameTooLongException)1 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)1 BatchStatement (com.datastax.oss.driver.api.core.cql.BatchStatement)1 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)1 Row (com.datastax.oss.driver.api.core.cql.Row)1 InvalidQueryException (com.datastax.oss.driver.api.core.servererrors.InvalidQueryException)1 QueryExecutionException (com.datastax.oss.driver.api.core.servererrors.QueryExecutionException)1 SyntaxError (com.datastax.oss.driver.api.core.servererrors.SyntaxError)1 BulkExecutionException (com.datastax.oss.dsbulk.executor.api.exception.BulkExecutionException)1 DriverUtils.mockRow (com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockRow)1