Search in sources :

Example 1 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class SQLTypeMappingTest method testParseInsertObject.

@Test
public void testParseInsertObject() throws Exception {
    setUpObjectTable();
    execute("insert into test12 (object_field, strict_field, " + "no_dynamic_field) values (?,?,?)", new Object[] { new HashMap<String, Object>() {

        {
            put("size", 127);
            put("created", "2013-11-19");
        }
    }, new HashMap<String, Object>() {

        {
            put("path", "/dev/null");
            put("created", "1970-01-01T00:00:00");
        }
    }, new HashMap<String, Object>() {

        {
            put("path", "/etc/shadow");
            put("dynamic_again", new HashMap<String, Object>() {

                {
                    put("field", 1384790145.289);
                }
            });
        }
    } });
    refresh();
    SQLResponse response = execute("select object_field, strict_field, no_dynamic_field from test12");
    assertEquals(1, response.rowCount());
    assertThat(response.rows()[0][0], instanceOf(Map.class));
    @SuppressWarnings("unchecked") Map<String, Object> objectMap = (Map<String, Object>) response.rows()[0][0];
    assertEquals(1384819200000L, objectMap.get("created"));
    assertEquals(127, objectMap.get("size"));
    assertThat(response.rows()[0][1], instanceOf(Map.class));
    @SuppressWarnings("unchecked") Map<String, Object> strictMap = (Map<String, Object>) response.rows()[0][1];
    assertEquals("/dev/null", strictMap.get("path"));
    assertEquals(0, strictMap.get("created"));
    assertThat(response.rows()[0][2], instanceOf(Map.class));
    @SuppressWarnings("unchecked") Map<String, Object> noDynamicMap = (Map<String, Object>) response.rows()[0][2];
    assertEquals("/etc/shadow", noDynamicMap.get("path"));
    assertEquals(new HashMap<String, Object>() {

        {
            put("field", 1384790145289L);
        }
    }, noDynamicMap.get("dynamic_again"));
    response = execute("select object_field['created'], object_field['size'], " + "no_dynamic_field['dynamic_again']['field'] from test12");
    assertEquals(1384819200000L, response.rows()[0][0]);
    assertEquals((byte) 127, response.rows()[0][1]);
    assertEquals(1384790145289L, response.rows()[0][2]);
}
Also used : HashMap(java.util.HashMap) SQLResponse(io.crate.testing.SQLResponse) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class SQLTypeMappingTest method testInsertTimestamp.

@Test
public void testInsertTimestamp() throws Exception {
    // This is a regression test that we allow timestamps that have more than 13 digits.
    execute("create table ts_table (ts timestamp) clustered into 2 shards with (number_of_replicas=0)");
    ensureYellow();
    // biggest Long that can be converted to Double without losing precision
    // equivalent to 33658-09-27T01:46:39.999Z
    long maxDateMillis = 999999999999999L;
    // smallest Long that can be converted to Double without losing precision
    // equivalent to -29719-04-05T22:13:20.001Z
    long minDateMillis = -999999999999999L;
    execute("insert into ts_table (ts) values (?)", new Object[] { minDateMillis });
    execute("insert into ts_table (ts) values (?)", new Object[] { 0L });
    execute("insert into ts_table (ts) values (?)", new Object[] { maxDateMillis });
    // TODO: select timestamps with correct sorting
    refresh();
    SQLResponse response = execute("select * from ts_table order by ts desc");
    assertEquals(response.rowCount(), 3L);
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 3 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class ReadOnlyNodeIntegrationTest method testAllowedCopyTo.

@Test
public void testAllowedCopyTo() throws Exception {
    String uri = folder.getRoot().toURI().toString();
    SQLResponse response = execute("copy write_test to directory ?", new Object[] { uri });
    assertThat(response.rowCount(), greaterThanOrEqualTo(0L));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 4 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class NodeStatsTest method testSysNodsOsInfo.

@Test
public void testSysNodsOsInfo() throws Exception {
    SQLResponse response = execute("select os_info from sys.nodes limit 1");
    Map results = (Map) response.rows()[0][0];
    assertThat(response.rowCount(), is(1L));
    assertThat((Integer) results.get("available_processors"), greaterThan(0));
    assertEquals(Constants.OS_NAME, results.get("name"));
    assertEquals(Constants.OS_ARCH, results.get("arch"));
    assertEquals(Constants.OS_VERSION, results.get("version"));
    Map<String, Object> jvmObj = new HashMap<>(4);
    jvmObj.put("version", Constants.JAVA_VERSION);
    jvmObj.put("vm_name", Constants.JVM_NAME);
    jvmObj.put("vm_vendor", Constants.JVM_VENDOR);
    jvmObj.put("vm_version", Constants.JVM_VERSION);
    assertEquals(jvmObj, results.get("jvm"));
}
Also used : HashMap(java.util.HashMap) SQLResponse(io.crate.testing.SQLResponse) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class NodeStatsTest method testNetwork.

@Test
public void testNetwork() throws Exception {
    SQLResponse response = execute("select network from sys.nodes limit 1");
    assertThat(response.rowCount(), is(1L));
    Map<String, Object> network = (Map<String, Object>) response.rows()[0][0];
    assertThat(network, hasKey("tcp"));
    Map<String, Object> tcp = (Map<String, Object>) network.get("tcp");
    assertNetworkTCP(tcp);
    response = execute("select network['tcp'] from sys.nodes limit 1");
    assertThat(response.rowCount(), is(1L));
    tcp = (Map<String, Object>) response.rows()[0][0];
    assertNetworkTCP(tcp);
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

SQLResponse (io.crate.testing.SQLResponse)109 Test (org.junit.Test)78 Map (java.util.Map)13 UseJdbc (io.crate.testing.UseJdbc)10 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)8 PartitionName (io.crate.metadata.PartitionName)4 TestingHelpers.resolveCanonicalString (io.crate.testing.TestingHelpers.resolveCanonicalString)4 Path (java.nio.file.Path)4 BytesRef (org.apache.lucene.util.BytesRef)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 TreeMap (java.util.TreeMap)2 List (java.util.List)1 UUID (java.util.UUID)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ClusterRerouteRequestBuilder (org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder)1 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1 SearchRequest (org.elasticsearch.action.search.SearchRequest)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1