use of com.datastax.oss.dsbulk.runner.ExitStatus.STATUS_COMPLETED_WITH_ERRORS in project dsbulk by datastax.
the class CSVConnectorEndToEndCCMIT method cas_load_with_errors.
/**
* Test for CAS failures (DAT-384).
*/
@Test
void cas_load_with_errors() {
session.execute("DROP TABLE IF EXISTS test_cas");
session.execute("CREATE TABLE test_cas (pk int, cc int, v int, PRIMARY KEY (pk, cc))");
session.execute("INSERT INTO test_cas (pk, cc, v) VALUES (1, 1, 1)");
session.execute("INSERT INTO test_cas (pk, cc, v) VALUES (1, 2, 2)");
session.execute("INSERT INTO test_cas (pk, cc, v) VALUES (1, 3, 3)");
// two failed CAS records will cause the entire batch to fail
// will fail
Record record1Failed = RecordUtils.mappedCSV("pk", "1", "cc", "1", "v", "1");
// will fail
Record record2Failed = RecordUtils.mappedCSV("pk", "1", "cc", "2", "v", "2");
Record record3NotApplied = // will not be applied
RecordUtils.mappedCSV("pk", "1", "cc", "4", "v", "4");
MockConnector.mockReads(record1Failed, record2Failed, record3NotApplied);
List<String> args = new ArrayList<>();
args.add("load");
args.add("--connector.name");
args.add("mock");
args.add("--schema.keyspace");
args.add(session.getKeyspace().get().asInternal());
args.add("--schema.query");
args.add("INSERT INTO test_cas (pk, cc, v) VALUES (:pk, :cc, :v) IF NOT EXISTS");
ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(status, STATUS_COMPLETED_WITH_ERRORS);
Path bad = OperationDirectory.getCurrentOperationDirectory().map(dir -> dir.resolve("paxos.bad")).orElse(null);
assertThat(bad).exists();
assertThat(FileUtils.readAllLines(bad)).containsExactly(record1Failed.getSource().toString(), record2Failed.getSource().toString(), record3NotApplied.getSource().toString());
Path errors = OperationDirectory.getCurrentOperationDirectory().map(dir -> dir.resolve("paxos-errors.log")).orElse(null);
assertThat(errors).exists();
assertThat(FileUtils.readAllLines(errors).collect(Collectors.joining("\n"))).contains(String.format("Resource: %s\n" + " Position: %d\n" + " Source: %s\n" + " INSERT INTO test_cas (pk, cc, v) VALUES (:pk, :cc, :v) IF NOT EXISTS\n" + " pk: 1\n" + " cc: 1\n" + " v: 1", record1Failed.getResource(), record1Failed.getPosition(), record1Failed.getSource()), String.format("Resource: %s\n" + " Position: %d\n" + " Source: %s\n" + " INSERT INTO test_cas (pk, cc, v) VALUES (:pk, :cc, :v) IF NOT EXISTS\n" + " pk: 1\n" + " cc: 2\n" + " v: 2", record2Failed.getResource(), record2Failed.getPosition(), record2Failed.getSource()), String.format("Resource: %s\n" + " Position: %d\n" + " Source: %s\n" + " INSERT INTO test_cas (pk, cc, v) VALUES (:pk, :cc, :v) IF NOT EXISTS\n" + " pk: 1\n" + " cc: 4\n" + " v: 4", record3NotApplied.getResource(), record3NotApplied.getPosition(), record3NotApplied.getSource()), "Failed conditional updates:", "\"[applied]\": false\npk: 1\ncc: 1\nv: 1", "\"[applied]\": false\npk: 1\ncc: 2\nv: 2");
List<Row> rows = session.execute("SELECT v FROM test_cas WHERE pk = 1").all();
assertThat(rows).hasSize(3);
assertThat(rows.get(0).getInt(0)).isEqualTo(1);
assertThat(rows.get(1).getInt(0)).isEqualTo(2);
assertThat(rows.get(2).getInt(0)).isEqualTo(3);
}
Aggregations