Search in sources :

Example 6 with SQLResponse

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)));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 7 with SQLResponse

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));
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 8 with SQLResponse

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"));
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Map(java.util.Map) HashMap(java.util.HashMap) UseJdbc(io.crate.testing.UseJdbc) Test(org.junit.Test)

Example 9 with SQLResponse

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));
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 10 with SQLResponse

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));
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) 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