Search in sources :

Example 26 with RequestPrime

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

the class JsonEndToEndSimulacronIT method full_load_multiple_urls.

@ParameterizedTest
@MethodSource("multipleUrlsProvider")
void full_load_multiple_urls(Path urlfile) {
    primeIpByCountryTable(simulacron);
    RequestPrime insert = createSimpleParameterizedQuery(INSERT_INTO_IP_BY_COUNTRY);
    simulacron.prime(new Prime(insert));
    String[] args = { "load", "-c", "json", "--connector.json.urlfile", StringUtils.quoteJson(urlfile.toAbsolutePath()), "--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);
    assertThat(logs.getAllMessagesAsString()).contains("Records: total: 24, successful: 24, failed: 0").contains("Batches: total: 24, size: 1.00 mean, 1 min, 1 max").contains("Writes: total: 24, successful: 24, failed: 0");
    validateQueryCount(simulacron, 24, "INSERT INTO ip_by_country", LOCAL_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) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 27 with RequestPrime

use of com.datastax.oss.simulacron.common.cluster.RequestPrime 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);
}
Also used : Query(com.datastax.oss.simulacron.common.request.Query) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) SuccessResult(com.datastax.oss.simulacron.common.result.SuccessResult) LinkedHashMap(java.util.LinkedHashMap)

Example 28 with RequestPrime

use of com.datastax.oss.simulacron.common.cluster.RequestPrime 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);
}
Also used : Query(com.datastax.oss.simulacron.common.request.Query) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) ArrayList(java.util.ArrayList) SuccessResult(com.datastax.oss.simulacron.common.result.SuccessResult) LinkedHashMap(java.util.LinkedHashMap)

Example 29 with RequestPrime

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

the class JsonEndToEndSimulacronIT method validate_stdout.

@Test
void validate_stdout() {
    primeIpByCountryTable(simulacron);
    RequestPrime prime = createQueryWithResultSet(SELECT_FROM_IP_BY_COUNTRY, 24);
    simulacron.prime(new Prime(prime));
    String[] args = { "unload", "-c", "json", "--connector.json.url", "-", "--schema.keyspace", "ks1", "--schema.query", SELECT_FROM_IP_BY_COUNTRY, "--schema.mapping", IP_BY_COUNTRY_MAPPING_NAMED };
    ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
    assertStatus(status, STATUS_OK);
    validateQueryCount(simulacron, 1, SELECT_FROM_IP_BY_COUNTRY, LOCAL_ONE);
    assertThat(stdOut.getStreamLines().size()).isEqualTo(24);
}
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 30 with RequestPrime

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

the class JsonEndToEndSimulacronIT method skip_test_load.

@Test
void skip_test_load() throws Exception {
    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_SKIP), "--connector.json.skipRecords", "3", "--connector.json.maxRecords", "24", "--schema.keyspace", "ks1", "--schema.query", INSERT_INTO_IP_BY_COUNTRY, "--schema.mapping", IP_BY_COUNTRY_MAPPING_NAMED, "--schema.allowMissingFields", "true" };
    ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
    assertStatus(status, STATUS_COMPLETED_WITH_ERRORS);
    validateQueryCount(simulacron, 21, "INSERT INTO ip_by_country", LOCAL_ONE);
    validateNumberOfBadRecords(3);
    validateExceptionsLog(3, "Source:", "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)

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