Search in sources :

Example 31 with Reference

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

the class NodeStatsIteratorTest method prepare.

@Before
public void prepare() {
    idRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.ID), RowGranularity.DOC, DataTypes.STRING);
    nameRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.ID), RowGranularity.DOC, DataTypes.STRING);
    hostnameRef = new Reference(new ReferenceIdent(SysNodesTableInfo.IDENT, SysNodesTableInfo.Columns.HOSTNAME), RowGranularity.DOC, DataTypes.STRING);
    collectPhase = mock(RoutedCollectPhase.class);
    when(collectPhase.whereClause()).thenReturn(WhereClause.NO_MATCH);
    nodes.add(newNode("nodeOne"));
    nodes.add(newNode("nodeTwo"));
}
Also used : Reference(io.crate.metadata.Reference) ReferenceIdent(io.crate.metadata.ReferenceIdent) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Before(org.junit.Before)

Example 32 with Reference

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

the class SysNodesExpressionsOnHandlerTest method testNestedBytesRefExpressionsString.

@Test
public void testNestedBytesRefExpressionsString() throws Exception {
    Reference refInfo = refInfo("sys.nodes.version", DataTypes.OBJECT, RowGranularity.NODE);
    collectExpression = resolver.getImplementation(refInfo);
    collectExpression.setNextRow(CONTEXT);
    Map<String, Object> version = (Map<String, Object>) collectExpression.value();
    String versionNumber = (String) version.get("number");
    refInfo = refInfo("sys.nodes.version", DataTypes.STRING, RowGranularity.NODE, "number");
    collectExpression = resolver.getImplementation(refInfo);
    collectExpression.setNextRow(CONTEXT);
    assertThat(collectExpression.value(), Matchers.is(new BytesRef(versionNumber)));
}
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 33 with Reference

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

the class SysNodesExpressionsOnHandlerTest method testProcess.

@Test
public void testProcess() throws Exception {
    Reference refInfo = refInfo("sys.nodes.process", DataTypes.OBJECT, RowGranularity.NODE);
    collectExpression = resolver.getImplementation(refInfo);
    collectExpression.setNextRow(CONTEXT);
    Map<String, Object> expectedCpu = new HashMap<>(4);
    expectedCpu.put("percent", (short) 50);
    expectedCpu.put("system", 1000L);
    expectedCpu.put("user", 500L);
    Map<String, Object> v = (Map<String, Object>) collectExpression.value();
    assertThat(v.get("open_file_descriptors"), is(42L));
    assertThat(v.get("max_open_file_descriptors"), is(1000L));
    assertThat(v.get("cpu"), Matchers.is(expectedCpu));
}
Also used : HashMap(java.util.HashMap) Reference(io.crate.metadata.Reference) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 34 with Reference

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

the class SysNodesExpressionsOnHandlerTest method testNetworkTCP.

@Test
public void testNetworkTCP() throws Exception {
    Reference refInfo = refInfo("sys.nodes.network", DataTypes.OBJECT, RowGranularity.NODE, "tcp");
    collectExpression = resolver.getImplementation(refInfo);
    collectExpression.setNextRow(CONTEXT);
    Map<String, Object> tcpStats = (Map<String, Object>) collectExpression.value();
    assertThat(tcpStats, instanceOf(Map.class));
    assertThat(mapToSortedString(tcpStats), is("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) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 35 with Reference

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

the class SysNodesExpressionsOnHandlerTest method testHeap.

@Test
public void testHeap() throws Exception {
    Reference refInfo = refInfo("sys.nodes.heap", DataTypes.STRING, RowGranularity.NODE);
    collectExpression = resolver.getImplementation(refInfo);
    collectExpression.setNextRow(CONTEXT);
    Map<String, Object> v = (Map<String, Object>) collectExpression.value();
    assertThat(v.get("max"), is(123456L));
    assertThat(v.get("used"), is(123456L));
    assertThat(v.get("free"), is(0L));
}
Also used : Reference(io.crate.metadata.Reference) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) HashMap(java.util.HashMap) Map(java.util.Map) 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