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]);
}
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);
}
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));
}
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"));
}
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);
}
Aggregations