Search in sources :

Example 11 with RequestPrime

use of com.datastax.oss.simulacron.common.cluster.RequestPrime in project dsbulk by datastax.

the class CSVEndToEndSimulacronIT method error_load_primary_key_cannot_be_null.

@Test
void error_load_primary_key_cannot_be_null() throws Exception {
    primeIpByCountryTable(simulacron);
    RequestPrime insert = createSimpleParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY);
    simulacron.prime(new Prime(insert));
    String[] args = { "load", "--log.maxErrors", "9", "--log.verbosity", "2", "-header", "false", "--connector.csv.url", StringUtils.quoteJson(getClass().getResource("/ip-by-country-pk-null.csv")), "--codec.nullStrings", "[NULL]", "--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_ABORTED_TOO_MANY_ERRORS);
    assertThat(logs.getAllMessagesAsString()).contains("aborted: Too many errors, the maximum allowed is 9").contains("Records: total: 24, successful: 14, failed: 10");
    // the number of writes may vary due to the abortion
    validateNumberOfBadRecords(10);
    validateExceptionsLog(10, "Primary key column country_code cannot be set to null", "mapping-errors.log");
}
Also used : ExitStatus(com.datastax.oss.dsbulk.runner.ExitStatus) Prime(com.datastax.oss.simulacron.common.stubbing.Prime) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) DataStaxBulkLoader(com.datastax.oss.dsbulk.runner.DataStaxBulkLoader) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with RequestPrime

use of com.datastax.oss.simulacron.common.cluster.RequestPrime in project dsbulk by datastax.

the class CSVEndToEndSimulacronIT method full_unload_large_result_set.

@Test
void full_unload_large_result_set() throws Exception {
    primeIpByCountryTable(simulacron);
    RequestPrime prime = createQueryWithResultSet(SELECT_FROM_IP_BY_COUNTRY, 10_000);
    simulacron.prime(new Prime(prime));
    String[] args = { "unload", "-header", "false", "--connector.csv.url", quoteJson(unloadDir), "--connector.csv.maxConcurrentFiles", "1C", "--schema.keyspace", "ks1", "--schema.query", SELECT_FROM_IP_BY_COUNTRY, "--schema.mapping", IP_BY_COUNTRY_MAPPING_INDEXED };
    ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
    assertStatus(status, STATUS_OK);
    validateQueryCount(simulacron, 1, SELECT_FROM_IP_BY_COUNTRY, ConsistencyLevel.LOCAL_ONE);
    validateOutputFiles(10_000, unloadDir);
}
Also used : ExitStatus(com.datastax.oss.dsbulk.runner.ExitStatus) Prime(com.datastax.oss.simulacron.common.stubbing.Prime) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) DataStaxBulkLoader(com.datastax.oss.dsbulk.runner.DataStaxBulkLoader) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with RequestPrime

use of com.datastax.oss.simulacron.common.cluster.RequestPrime in project dsbulk by datastax.

the class JsonEndToEndSimulacronIT method full_load_dry_run.

@Test
void full_load_dry_run() {
    primeIpByCountryTable(simulacron);
    RequestPrime insert = createSimpleParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY);
    simulacron.prime(new Prime(insert));
    String[] args = { "load", "-c", "json", "--connector.json.url", StringUtils.quoteJson(JsonUtils.JSON_RECORDS_UNIQUE), "-dryRun", "true", "--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_OK);
    validateQueryCount(simulacron, 0, "INSERT INTO ip_by_country", ONE);
}
Also used : ExitStatus(com.datastax.oss.dsbulk.runner.ExitStatus) Prime(com.datastax.oss.simulacron.common.stubbing.Prime) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) DataStaxBulkLoader(com.datastax.oss.dsbulk.runner.DataStaxBulkLoader) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with RequestPrime

use of com.datastax.oss.simulacron.common.cluster.RequestPrime in project dsbulk by datastax.

the class SimulacronUtils method primeSystemPeersV2.

public static void primeSystemPeersV2(BoundCluster simulacron) {
    Query whenSelectSystemPeersV2 = new Query(SELECT_SYSTEM_PEERS_V2);
    ErrorResult thenThrowServerError = new ServerErrorResult("Unknown keyspace/cf pair (system.peers_v2)");
    RequestPrime primeSystemPeersV2 = new RequestPrime(whenSelectSystemPeersV2, thenThrowServerError);
    simulacron.prime(new Prime(primeSystemPeersV2));
}
Also used : Prime(com.datastax.oss.simulacron.common.stubbing.Prime) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) Query(com.datastax.oss.simulacron.common.request.Query) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) ErrorResult(com.datastax.oss.simulacron.common.result.ErrorResult) ServerErrorResult(com.datastax.oss.simulacron.common.result.ServerErrorResult) ServerErrorResult(com.datastax.oss.simulacron.common.result.ServerErrorResult)

Example 15 with RequestPrime

use of com.datastax.oss.simulacron.common.cluster.RequestPrime 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));
}
Also used : Prime(com.datastax.oss.simulacron.common.stubbing.Prime) BoundCluster(com.datastax.oss.simulacron.server.BoundCluster) Arrays(java.util.Arrays) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) ImmutableSet(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet) HashMap(java.util.HashMap) Sets(org.assertj.core.util.Sets) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap) ArrayList(java.util.ArrayList) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) LinkedHashMap(java.util.LinkedHashMap) ErrorResult(com.datastax.oss.simulacron.common.result.ErrorResult) Map(java.util.Map) ServerErrorResult(com.datastax.oss.simulacron.common.result.ServerErrorResult) Collector(java.util.stream.Collector) SimpleEntry(java.util.AbstractMap.SimpleEntry) Query(com.datastax.oss.simulacron.common.request.Query) SuccessResult(com.datastax.oss.simulacron.common.result.SuccessResult) Collections.emptyList(java.util.Collections.emptyList) DataType(com.datastax.oss.driver.api.core.type.DataType) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) DefaultProtocolVersion(com.datastax.oss.driver.api.core.DefaultProtocolVersion) List(java.util.List) BoundNode(com.datastax.oss.simulacron.server.BoundNode) Collections(java.util.Collections) TEXT(com.datastax.oss.driver.api.core.type.DataTypes.TEXT) Prime(com.datastax.oss.simulacron.common.stubbing.Prime) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) Query(com.datastax.oss.simulacron.common.request.Query) ArrayList(java.util.ArrayList) SuccessResult(com.datastax.oss.simulacron.common.result.SuccessResult) LinkedHashMap(java.util.LinkedHashMap) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime)

Aggregations

RequestPrime (com.datastax.oss.simulacron.common.cluster.RequestPrime)36 Prime (com.datastax.oss.simulacron.common.stubbing.Prime)32 DataStaxBulkLoader (com.datastax.oss.dsbulk.runner.DataStaxBulkLoader)30 ExitStatus (com.datastax.oss.dsbulk.runner.ExitStatus)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 Test (org.junit.jupiter.api.Test)28 LinkedHashMap (java.util.LinkedHashMap)7 Query (com.datastax.oss.simulacron.common.request.Query)6 SuccessResult (com.datastax.oss.simulacron.common.result.SuccessResult)6 SyntaxErrorResult (com.datastax.oss.simulacron.common.result.SyntaxErrorResult)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Record (com.datastax.oss.dsbulk.connectors.api.Record)2 ErrorResult (com.datastax.oss.simulacron.common.result.ErrorResult)2 FunctionFailureResult (com.datastax.oss.simulacron.common.result.FunctionFailureResult)2 ReadTimeoutResult (com.datastax.oss.simulacron.common.result.ReadTimeoutResult)2 ServerErrorResult (com.datastax.oss.simulacron.common.result.ServerErrorResult)2 WriteFailureResult (com.datastax.oss.simulacron.common.result.WriteFailureResult)2 WriteTimeoutResult (com.datastax.oss.simulacron.common.result.WriteTimeoutResult)2 Config (com.typesafe.config.Config)2