use of com.datastax.oss.simulacron.common.result.SuccessResult in project dsbulk by datastax.
the class JsonEndToEndSimulacronIT method load_errors.
@Test
void load_errors() throws Exception {
primeIpByCountryTable(simulacron);
Map<String, Object> params = new HashMap<>();
params.put("country_name", "Sweden");
RequestPrime prime1 = createParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY, params, new SuccessResult(emptyList(), new LinkedHashMap<>()));
simulacron.prime(new Prime(prime1));
// recoverable errors only
params.put("country_name", "France");
prime1 = createParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY, params, new ReadTimeoutResult(LOCAL_ONE, 1, 0, false));
simulacron.prime(new Prime(prime1));
params.put("country_name", "Gregistan");
prime1 = createParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY, params, new WriteTimeoutResult(LOCAL_ONE, 0, 0, WriteType.BATCH_LOG));
simulacron.prime(new Prime(prime1));
params.put("country_name", "Andybaijan");
prime1 = createParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY, params, new WriteFailureResult(ONE, 0, 0, emptyMap(), WriteType.BATCH));
simulacron.prime(new Prime(prime1));
params = new HashMap<>();
params.put("country_name", "United States");
prime1 = createParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY, params, new FunctionFailureResult("keyspace", "function", emptyList(), "bad function call"));
simulacron.prime(new Prime(prime1));
String[] args = { "load", "-c", "json", "--connector.json.url", StringUtils.quoteJson(JsonUtils.JSON_RECORDS_ERROR), "--driver.advanced.retry-policy.max-retries", "1", "--schema.keyspace", "ks1", "--schema.query", INSERT_INTO_IP_BY_COUNTRY, "--schema.mapping", IP_BY_COUNTRY_MAPPING_NAMED };
ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(status, STATUS_COMPLETED_WITH_ERRORS);
// There are 24 rows of data, but two extra queries due to the retry for the write timeout and
// the unavailable.
validateQueryCount(simulacron, 26, "INSERT INTO ip_by_country", LOCAL_ONE);
validateNumberOfBadRecords(4);
validateExceptionsLog(4, "Source:", "load-errors.log");
}
use of com.datastax.oss.simulacron.common.result.SuccessResult in project dsbulk by datastax.
the class CSVEndToEndSimulacronIT method load_errors.
@Test
void load_errors() throws Exception {
primeIpByCountryTable(simulacron);
Map<String, Object> params = new HashMap<>();
params.put("country_name", "Sweden");
RequestPrime prime1 = createParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY, params, new SuccessResult(emptyList(), new LinkedHashMap<>()));
simulacron.prime(new Prime(prime1));
// recoverable errors only
params.put("country_name", "France");
prime1 = createParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY, params, new ReadTimeoutResult(LOCAL_ONE, 1, 0, false));
simulacron.prime(new Prime(prime1));
params.put("country_name", "Gregistan");
prime1 = createParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY, params, new WriteTimeoutResult(LOCAL_ONE, 0, 0, WriteType.BATCH_LOG));
simulacron.prime(new Prime(prime1));
params.put("country_name", "Andybaijan");
prime1 = createParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY, params, new WriteFailureResult(ONE, 0, 0, emptyMap(), WriteType.BATCH));
simulacron.prime(new Prime(prime1));
params = new HashMap<>();
params.put("country_name", "United States");
prime1 = createParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY, params, new FunctionFailureResult("keyspace", "function", emptyList(), "bad function call"));
simulacron.prime(new Prime(prime1));
String[] args = { "load", "-header", "false", "--connector.csv.url", StringUtils.quoteJson(CsvUtils.CSV_RECORDS_ERROR), "--driver.advanced.retry-policy.max-retries", "1", "--schema.keyspace", "ks1", "--schema.query", INSERT_INTO_IP_BY_COUNTRY, "--schema.mapping", IP_BY_COUNTRY_MAPPING_INDEXED };
ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
assertStatus(status, STATUS_COMPLETED_WITH_ERRORS);
// There are 24 rows of data, but two extra queries due to the retry for the write timeout and
// the unavailable.
validateQueryCount(simulacron, 26, "INSERT INTO ip_by_country", LOCAL_ONE);
validateNumberOfBadRecords(4);
validateExceptionsLog(4, "Source:", "load-errors.log");
}
use of com.datastax.oss.simulacron.common.result.SuccessResult in project dsbulk by datastax.
the class SimulacronUtils method primeTables.
public static void primeTables(BoundCluster simulacron, Keyspace... keyspaces) {
List<LinkedHashMap<String, Object>> allKeyspacesRows = new ArrayList<>();
List<LinkedHashMap<String, Object>> allTablesRows = new ArrayList<>();
List<LinkedHashMap<String, Object>> allColumnsRows = new ArrayList<>();
for (Keyspace keyspace : keyspaces) {
LinkedHashMap<String, Object> keyspaceRow = new LinkedHashMap<>();
keyspaceRow.put("keyspace_name", keyspace.name);
keyspaceRow.put("durable_writes", true);
keyspaceRow.put("replication", ImmutableMap.of("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", "1"));
allKeyspacesRows.add(keyspaceRow);
Query whenSelectKeyspace = new Query(SELECT_KEYSPACES + " WHERE keyspace_name = '" + keyspace.name + '\'');
SuccessResult thenReturnKeyspace = new SuccessResult(Collections.singletonList(keyspaceRow), new LinkedHashMap<>(KEYSPACE_COLUMNS));
RequestPrime primeKeyspace = new RequestPrime(whenSelectKeyspace, thenReturnKeyspace);
simulacron.prime(new Prime(primeKeyspace));
for (Table table : keyspace.tables) {
LinkedHashMap<String, Object> tableRow = new LinkedHashMap<>();
tableRow.put("keyspace_name", keyspace.name);
tableRow.put("table_name", table.name);
tableRow.put("bloom_filter_fp_chance", 0.01d);
tableRow.put("caching", ImmutableMap.of("keys", "ALL", "rows_per_partition", "NONE"));
tableRow.put("cdc", null);
tableRow.put("comment", "");
tableRow.put("compaction", ImmutableMap.of("class", "org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy", "max_threshold", "32", "min_threshold", "4"));
tableRow.put("compression", ImmutableMap.of("chunk_length_in_kb", "64", "class", "org.apache.cassandra.io.compress.LZ4Compressor"));
tableRow.put("crc_check_chance", 1d);
tableRow.put("dclocal_read_repair_chance", 0.1d);
tableRow.put("default_time_to_live", 0);
tableRow.put("extensions", null);
tableRow.put("flags", ImmutableSet.of("compound"));
tableRow.put("gc_grace_seconds", 864000);
tableRow.put("id", UUID.randomUUID());
tableRow.put("max_index_interval", 2048);
tableRow.put("memtable_flush_period_in_ms", 0);
tableRow.put("min_index_interval", 128);
tableRow.put("read_repair_chance", 0d);
tableRow.put("speculative_retry", "99PERCENTILE");
allTablesRows.add(tableRow);
Query whenSelectTable = new Query(SELECT_TABLES + " WHERE keyspace_name = '" + keyspace.name + "' AND table_name = '" + table.name + '\'');
SuccessResult thenReturnTable = new SuccessResult(Collections.singletonList(tableRow), new LinkedHashMap<>(TABLE_COLUMNS));
RequestPrime primeTable = new RequestPrime(whenSelectTable, thenReturnTable);
simulacron.prime(new Prime(primeTable));
List<LinkedHashMap<String, Object>> tableColumnsRows = new ArrayList<>();
int position = 0;
for (Column column : table.partitionKey) {
LinkedHashMap<String, Object> columnRow = new LinkedHashMap<>();
columnRow.put("keyspace_name", keyspace.name);
columnRow.put("table_name", table.name);
columnRow.put("column_name", column.name);
columnRow.put("clustering_order", "none");
columnRow.put("column_name_bytes", column.name.getBytes(StandardCharsets.UTF_8));
columnRow.put("kind", "partition_key");
columnRow.put("position", position++);
columnRow.put("type", column.getTypeAsString());
tableColumnsRows.add(columnRow);
}
position = 0;
for (Column column : table.clusteringColumns) {
LinkedHashMap<String, Object> columnRow = new LinkedHashMap<>();
columnRow.put("keyspace_name", keyspace.name);
columnRow.put("table_name", table.name);
columnRow.put("column_name", column.name);
columnRow.put("clustering_order", "asc");
columnRow.put("column_name_bytes", column.name.getBytes(StandardCharsets.UTF_8));
columnRow.put("kind", "clustering");
columnRow.put("position", position++);
columnRow.put("type", column.getTypeAsString());
tableColumnsRows.add(columnRow);
}
for (Column column : table.otherColumns) {
LinkedHashMap<String, Object> columnRow = new LinkedHashMap<>();
columnRow.put("keyspace_name", keyspace.name);
columnRow.put("table_name", table.name);
columnRow.put("column_name", column.name);
columnRow.put("clustering_order", "none");
columnRow.put("column_name_bytes", column.name.getBytes(StandardCharsets.UTF_8));
columnRow.put("kind", "regular");
columnRow.put("position", -1);
columnRow.put("type", column.getTypeAsString());
tableColumnsRows.add(columnRow);
}
Query whenSelectTableColumns = new Query(SELECT_COLUMNS + " WHERE keyspace_name = '" + keyspace.name + "' AND table_name = '" + table.name + '\'');
SuccessResult thenReturnTableColumns = new SuccessResult(tableColumnsRows, new LinkedHashMap<>(TABLE_COLUMNS));
RequestPrime primeAllTableColumns = new RequestPrime(whenSelectTableColumns, thenReturnTableColumns);
simulacron.prime(new Prime(primeAllTableColumns));
allColumnsRows.addAll(tableColumnsRows);
// INSERT INTO table
Query whenInsertIntoTable = new Query(String.format("INSERT INTO %s.%s (%s) VALUES (%s)", asCql(keyspace.name), asCql(table.name), table.allColumns().stream().map(col -> asCql(col.name)).collect(COMMA), table.allColumns().stream().map(col -> ":" + asCql(col.name)).collect(COMMA)), emptyList(), new LinkedHashMap<String, Object>(), table.allColumnTypes());
simulacron.prime(new Prime(new RequestPrime(whenInsertIntoTable, new SuccessResult(emptyList(), new LinkedHashMap<String, String>()))));
// UPDATE table
Query whenUpdateIntoTable = new Query(String.format("UPDATE %s.%s SET %s", asCql(keyspace.name), asCql(table.name), table.allColumns().stream().map(col -> asCql(col.name) + "=:" + asCql(col.name)).collect(COMMA)), emptyList(), new LinkedHashMap<String, Object>(), table.allColumnTypes());
simulacron.prime(new Prime(new RequestPrime(whenUpdateIntoTable, new SuccessResult(emptyList(), new LinkedHashMap<String, String>()))));
// SELECT cols from table
Query whenSelectFromTable = new Query(String.format("SELECT %s FROM %s.%s", table.allColumns().stream().map(col -> asCql(col.name)).collect(COMMA), asCql(keyspace.name), asCql(table.name)));
simulacron.prime(new Prime(new RequestPrime(whenSelectFromTable, new SuccessResult(table.rows, table.allColumnTypes()))));
// SELECT from table WHERE token...
Query whenSelectFromTableWhere = new Query(String.format("SELECT %s FROM %s.%s WHERE token(%s) > ? AND token(%s) <= ?", table.allColumns().stream().map(col -> asCql(col.name)).collect(COMMA), asCql(keyspace.name), asCql(table.name), table.partitionKey.stream().map(col -> asCql(col.name)).collect(COMMA), table.partitionKey.stream().map(col -> asCql(col.name)).collect(COMMA)));
simulacron.prime(new Prime(new RequestPrime(whenSelectFromTableWhere, new SuccessResult(table.rows, table.allColumnTypes()))));
whenSelectFromTableWhere = new Query(String.format("SELECT %s FROM %s.%s WHERE token(%s) > :start AND token(%s) <= :end", table.allColumns().stream().map(col -> asCql(col.name)).collect(COMMA), asCql(keyspace.name), asCql(table.name), table.partitionKey.stream().map(col -> asCql(col.name)).collect(COMMA), table.partitionKey.stream().map(col -> asCql(col.name)).collect(COMMA)));
simulacron.prime(new Prime(new RequestPrime(whenSelectFromTableWhere, new SuccessResult(table.rows, table.allColumnTypes()))));
}
}
Query whenSelectAllKeyspaces = new Query(SELECT_KEYSPACES);
SuccessResult thenReturnAllKeyspaces = new SuccessResult(allKeyspacesRows, new LinkedHashMap<>(KEYSPACE_COLUMNS));
RequestPrime primeAllKeyspaces = new RequestPrime(whenSelectAllKeyspaces, thenReturnAllKeyspaces);
simulacron.prime(new Prime(primeAllKeyspaces));
Query whenSelectAllTables = new Query(SELECT_TABLES);
SuccessResult thenReturnAllTables = new SuccessResult(allTablesRows, new LinkedHashMap<>(TABLE_COLUMNS));
RequestPrime primeAllTables = new RequestPrime(whenSelectAllTables, thenReturnAllTables);
simulacron.prime(new Prime(primeAllTables));
Query whenSelectAllColumns = new Query(SELECT_COLUMNS);
SuccessResult thenReturnAllColumns = new SuccessResult(allColumnsRows, new LinkedHashMap<>(COLUMN_COLUMNS));
RequestPrime primeAllColumns = new RequestPrime(whenSelectAllColumns, thenReturnAllColumns);
simulacron.prime(new Prime(primeAllColumns));
}
use of com.datastax.oss.simulacron.common.result.SuccessResult in project dsbulk by datastax.
the class EndToEndUtils method createSimpleParameterizedQuery.
public static RequestPrime createSimpleParameterizedQuery(String query) {
LinkedHashMap<String, String> paramTypes = new LinkedHashMap<>();
paramTypes.put("country_code", "varchar");
paramTypes.put("country_name", "varchar");
paramTypes.put("beginning_ip_address", "inet");
paramTypes.put("ending_ip_address", "inet");
paramTypes.put("beginning_ip_number", "bigint");
paramTypes.put("ending_ip_number", "bigint");
Query when = new Query(query, Collections.emptyList(), new LinkedHashMap<>(), paramTypes);
SuccessResult then = new SuccessResult(new ArrayList<>(), new LinkedHashMap<>());
return new RequestPrime(when, then);
}
use of com.datastax.oss.simulacron.common.result.SuccessResult in project dsbulk by datastax.
the class EndToEndUtils method createQueryWithResultSetWithQuotes.
public static RequestPrime createQueryWithResultSetWithQuotes(String query, int numOfResults) {
Query when = new Query(query);
LinkedHashMap<String, String> columnTypes = new LinkedHashMap<>();
columnTypes.put("country_code", "varchar");
columnTypes.put("country_name", "varchar");
columnTypes.put("beginning_ip_address", "inet");
columnTypes.put("ending_ip_address", "inet");
columnTypes.put("beginning_ip_number", "bigint");
columnTypes.put("ending_ip_number", "bigint");
List<LinkedHashMap<String, Object>> rows = new ArrayList<>();
for (int i = 0; i < numOfResults; i++) {
LinkedHashMap<String, Object> row = new LinkedHashMap<>();
row.put("country_code", "country" + ";" + i);
row.put("country_name", "country" + ";" + i);
row.put("beginning_ip_address", "127.0.0." + i);
row.put("ending_ip_address", "127.2.0." + i);
row.put("beginning_ip_number", Integer.toString(i));
row.put("ending_ip_number", Integer.toString(i));
rows.add(row);
}
SuccessResult then = new SuccessResult(rows, columnTypes);
return new RequestPrime(when, then);
}
Aggregations