use of io.crate.testing.SQLResponse in project crate by crate.
the class NodeStatsTest method testSysNodesMem.
@Test
public void testSysNodesMem() throws Exception {
SQLResponse response = execute("select mem['free'], mem['used'], mem['free_percent'], mem['used_percent'] from sys.nodes limit 1");
long free = (long) response.rows()[0][0];
long used = (long) response.rows()[0][1];
double free_percent = ((Number) response.rows()[0][2]).intValue() * 0.01;
double used_percent = ((Number) response.rows()[0][3]).intValue() * 0.01;
double calculated_free_percent = free / (double) (free + used);
double calculated_used_percent = used / (double) (free + used);
// result should not differ from calculated result more than 2%
double max_delta = 0.02;
double free_delta = Math.abs(calculated_free_percent - free_percent);
double used_delta = Math.abs(calculated_used_percent - used_percent);
assertThat(free_delta, is(lessThan(max_delta)));
assertThat(used_delta, is(lessThan(max_delta)));
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class NodeStatsTest method testNetworkTcpPacketsFields.
@Test
public void testNetworkTcpPacketsFields() throws Exception {
SQLResponse response = execute("select " + "network['tcp']['packets']['sent'], " + "network['tcp']['packets']['received'], " + "network['tcp']['packets']['retransmitted'], " + "network['tcp']['packets']['errors_received'], " + "network['tcp']['packets']['rst_sent'] " + "from sys.nodes limit 1");
assertThat(response.rowCount(), is(1L));
for (int i = 0; i < response.cols().length; i++) {
assertThat((Long) response.rows()[0][i], greaterThanOrEqualTo(-1L));
}
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class NodeStatsTest method testFs.
@Test
// because of json some values are transfered as integer instead of long
@UseJdbc(0)
public void testFs() throws Exception {
SQLResponse response = execute("select fs from sys.nodes limit 1");
assertThat(response.rowCount(), is(1L));
assertThat(response.rows()[0][0], instanceOf(Map.class));
Map<String, Object> fs = (Map<String, Object>) response.rows()[0][0];
assertThat(fs.keySet().size(), is(3));
assertThat(fs.keySet(), hasItems("total", "disks", "data"));
Map<String, Object> total = (Map<String, Object>) fs.get("total");
assertThat(total.keySet(), hasItems("size", "used", "available", "reads", "writes", "bytes_written", "bytes_read"));
for (Object val : total.values()) {
assertThat((Long) val, greaterThanOrEqualTo(-1L));
}
Object[] disks = (Object[]) fs.get("disks");
if (disks.length > 0) {
// on travis there are no accessible disks
assertThat(disks.length, greaterThanOrEqualTo(1));
Map<String, Object> someDisk = (Map<String, Object>) disks[0];
assertThat(someDisk.keySet().size(), is(8));
assertThat(someDisk.keySet(), hasItems("dev", "size", "used", "available", "reads", "writes", "bytes_read", "bytes_written"));
for (Map.Entry<String, Object> entry : someDisk.entrySet()) {
if (!entry.getKey().equals("dev")) {
assertThat((Long) entry.getValue(), greaterThanOrEqualTo(-1L));
}
}
}
Object[] data = (Object[]) fs.get("data");
if (data.length > 0) {
// without sigar, no data definition returned
int numDataPaths = internalCluster().getInstance(NodeEnvironment.class).nodeDataPaths().length;
assertThat(data.length, is(numDataPaths));
Map<String, Object> someData = (Map<String, Object>) data[0];
assertThat(someData.keySet().size(), is(2));
assertThat(someData.keySet(), hasItems("dev", "path"));
}
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class NodeStatsTest method testSysNodesObjectArrayStringChildColumn.
@Test
public void testSysNodesObjectArrayStringChildColumn() throws Exception {
SQLResponse response = execute("select fs['data']['path'] from sys.nodes");
assertThat(response.rowCount(), Matchers.is(2L));
for (Object path : (Object[]) response.rows()[0][0]) {
assertThat(path, instanceOf(String.class));
}
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class NodeStatsTest method testNetworkTcpConnectionFields.
@Test
public void testNetworkTcpConnectionFields() throws Exception {
SQLResponse response = execute("select " + "network['tcp']['connections']['initiated'], " + "network['tcp']['connections']['accepted'], " + "network['tcp']['connections']['curr_established']," + "network['tcp']['connections']['dropped']," + "network['tcp']['connections']['embryonic_dropped']" + " from sys.nodes limit 1");
assertThat(response.rowCount(), is(1L));
for (int i = 0; i < response.cols().length; i++) {
assertThat((Long) response.rows()[0][i], greaterThanOrEqualTo(-1L));
}
}
Aggregations