Search in sources :

Example 11 with Query

use of com.datastax.oss.simulacron.common.request.Query 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 12 with Query

use of com.datastax.oss.simulacron.common.request.Query 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 13 with Query

use of com.datastax.oss.simulacron.common.request.Query in project dsbulk by datastax.

the class EndToEndUtils method createQueryWithResultSet.

public static RequestPrime createQueryWithResultSet(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.1");
        row.put("ending_ip_address", "127.2.0.1");
        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 14 with Query

use of com.datastax.oss.simulacron.common.request.Query in project dsbulk by datastax.

the class EndToEndUtils method createParameterizedQuery.

public static RequestPrime createParameterizedQuery(String query, Map<String, Object> params, Result then) {
    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");
    LinkedHashMap<String, Object> defaultParams = new LinkedHashMap<>();
    defaultParams.put("country_code", "*");
    defaultParams.put("country_name", "*");
    defaultParams.put("beginning_ip_address", "*");
    defaultParams.put("ending_ip_address", "*");
    defaultParams.put("beginning_ip_number", "*");
    defaultParams.put("ending_ip_number", "*");
    for (String key : params.keySet()) {
        defaultParams.put(key, params.get(key));
    }
    Query when = new Query(query, Collections.emptyList(), defaultParams, paramTypes);
    return new RequestPrime(when, then);
}
Also used : Query(com.datastax.oss.simulacron.common.request.Query) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Query (com.datastax.oss.simulacron.common.request.Query)14 RequestPrime (com.datastax.oss.simulacron.common.cluster.RequestPrime)7 Test (org.junit.jupiter.api.Test)7 LinkedHashMap (java.util.LinkedHashMap)6 SuccessResult (com.datastax.oss.simulacron.common.result.SuccessResult)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 GenericRecord (org.apache.pulsar.client.api.schema.GenericRecord)4 InstanceState (com.datastax.oss.common.sink.state.InstanceState)3 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)3 ErrorResult (com.datastax.oss.simulacron.common.result.ErrorResult)3 BoundCluster (com.datastax.oss.simulacron.server.BoundCluster)3 GenericRecordImpl (com.datastax.oss.sink.pulsar.GenericRecordImpl)3 PulsarRecordImpl (com.datastax.oss.sink.pulsar.PulsarRecordImpl)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 TEXT (com.datastax.oss.driver.api.core.type.DataTypes.TEXT)2 ServerErrorResult (com.datastax.oss.simulacron.common.result.ServerErrorResult)2