Search in sources :

Example 51 with Reference

use of io.crate.metadata.Reference in project crate by crate.

the class SysNodesExpressionsWithDefaultExtendedStatsTest method testCpu.

@Test
public void testCpu() throws Exception {
    prepare(true);
    Reference refInfo = refInfo("sys.nodes.os", DataTypes.OBJECT, RowGranularity.NODE);
    io.crate.operation.reference.NestedObjectExpression os = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    Map<String, Object> v = os.value();
    Map<String, Short> cpuObj = new HashMap<>(5);
    cpuObj.put("system", (short) -1);
    cpuObj.put("user", (short) -1);
    cpuObj.put("idle", (short) -1);
    cpuObj.put("used", (short) -1);
    cpuObj.put("stolen", (short) -1);
    assertEquals(cpuObj, v.get("cpu"));
}
Also used : HashMap(java.util.HashMap) Reference(io.crate.metadata.Reference) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 52 with Reference

use of io.crate.metadata.Reference in project crate by crate.

the class SysNodesExpressionsOnHandlerTest method testFs.

@Test
public void testFs() throws Exception {
    Reference refInfo = refInfo("sys.nodes.fs", DataTypes.STRING, RowGranularity.NODE);
    collectExpression = resolver.getImplementation(refInfo);
    collectExpression.setNextRow(CONTEXT);
    Map<String, Object> v = (Map<String, Object>) collectExpression.value();
    String total = mapToSortedString((Map<String, Object>) v.get("total"));
    assertThat(total, is("available=86016, bytes_read=84, bytes_written=84, reads=84, size=86016, used=86016, writes=84"));
    Object[] disks = (Object[]) v.get("disks");
    assertThat(disks.length, is(2));
    Map<String, Object> disk0 = (Map<String, Object>) disks[0];
    assertThat(disk0.get("dev"), is(BytesRefs.toBytesRef("/dev/sda1")));
    assertThat(disk0.get("size"), is(42L));
    Map<String, Object> disk1 = (Map<String, Object>) disks[1];
    assertThat(disk1.get("dev"), is(BytesRefs.toBytesRef("/dev/sda2")));
    assertThat(disk0.get("used"), is(42L));
    Object[] data = (Object[]) v.get("data");
    assertThat(data.length, is(2));
    assertThat(((Map<String, Object>) data[0]).get("dev"), is(BytesRefs.toBytesRef("/dev/sda1")));
    assertThat(((Map<String, Object>) data[0]).get("path"), is(BytesRefs.toBytesRef("/foo")));
    assertThat(((Map<String, Object>) data[1]).get("dev"), is(BytesRefs.toBytesRef("/dev/sda2")));
    assertThat(((Map<String, Object>) data[1]).get("path"), is(BytesRefs.toBytesRef("/bar")));
    refInfo = refInfo("sys.nodes.fs", DataTypes.STRING, RowGranularity.NODE, "data", "dev");
    collectExpression = resolver.getImplementation(refInfo);
    collectExpression.setNextRow(CONTEXT);
    for (Object arrayElement : (Object[]) collectExpression.value()) {
        assertThat(arrayElement, instanceOf(BytesRef.class));
    }
}
Also used : Reference(io.crate.metadata.Reference) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) HashMap(java.util.HashMap) Map(java.util.Map) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 53 with Reference

use of io.crate.metadata.Reference in project crate by crate.

the class SysNodesExpressionsTest method testNetwork.

@Test
public void testNetwork() throws Exception {
    Reference refInfo = refInfo("sys.nodes.network", DataTypes.OBJECT, RowGranularity.NODE);
    io.crate.operation.reference.NestedObjectExpression networkRef = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    Map<String, Object> networkStats = networkRef.value();
    assertThat(mapToSortedString(networkStats), is("probe_timestamp=0, tcp={" + "connections={accepted=42, curr_established=42, dropped=42, embryonic_dropped=42, initiated=42}, " + "packets={errors_received=42, received=42, retransmitted=42, rst_sent=42, sent=42}" + "}"));
}
Also used : Reference(io.crate.metadata.Reference) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 54 with Reference

use of io.crate.metadata.Reference in project crate by crate.

the class SysNodesExpressionsTest method testMemory.

@Test
public void testMemory() throws Exception {
    Reference refInfo = refInfo("sys.nodes.mem", DataTypes.OBJECT, RowGranularity.NODE);
    io.crate.operation.reference.NestedObjectExpression mem = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    Map<String, Object> v = mem.value();
    assertEquals(12345342234L, v.get("free"));
    assertEquals(Short.valueOf("78"), v.get("free_percent"));
    assertEquals(12345342234L, v.get("used"));
    assertEquals(Short.valueOf("22"), v.get("used_percent"));
}
Also used : Reference(io.crate.metadata.Reference) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 55 with Reference

use of io.crate.metadata.Reference in project crate by crate.

the class SysNodesExpressionsTest method testPorts.

@Test
public void testPorts() throws Exception {
    Reference refInfo = refInfo("sys.nodes.port", DataTypes.OBJECT, RowGranularity.NODE);
    io.crate.operation.reference.NestedObjectExpression port = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    Map<String, Object> v = port.value();
    assertEquals(44200, v.get("http"));
    assertEquals(44300, v.get("transport"));
}
Also used : Reference(io.crate.metadata.Reference) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Reference (io.crate.metadata.Reference)84 Test (org.junit.Test)57 CrateUnitTest (io.crate.test.integration.CrateUnitTest)55 TestingHelpers.mapToSortedString (io.crate.testing.TestingHelpers.mapToSortedString)27 HashMap (java.util.HashMap)20 Map (java.util.Map)20 NestedObjectExpression (io.crate.operation.reference.NestedObjectExpression)17 ColumnIdent (io.crate.metadata.ColumnIdent)15 Symbol (io.crate.analyze.symbol.Symbol)14 BytesRef (org.apache.lucene.util.BytesRef)11 TableIdent (io.crate.metadata.TableIdent)9 ReferenceIdent (io.crate.metadata.ReferenceIdent)8 InputColumn (io.crate.analyze.symbol.InputColumn)6 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)6 ShardId (org.elasticsearch.index.shard.ShardId)5 Routing (io.crate.metadata.Routing)4 UUID (java.util.UUID)4 OrderBy (io.crate.analyze.OrderBy)3 ShardResponse (io.crate.executor.transport.ShardResponse)3 ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)3