Search in sources :

Example 16 with Reference

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

the class SysNodesExpressionsTest method testHostname.

@Test
public void testHostname() throws Exception {
    Reference refInfo = refInfo("sys.nodes.hostname", DataTypes.STRING, RowGranularity.NODE);
    @SuppressWarnings("unchecked") ReferenceImplementation<BytesRef> expression = (ReferenceImplementation) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    BytesRef hostname = expression.value();
    assertThat(hostname, notNullValue());
    assertThat(InetAddresses.isInetAddress(BytesRefs.toString(hostname)), is(false));
}
Also used : Reference(io.crate.metadata.Reference) BytesRef(org.apache.lucene.util.BytesRef) ReferenceImplementation(io.crate.metadata.ReferenceImplementation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 17 with Reference

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

the class SysNodesExpressionsTest method testFs.

@SuppressWarnings("unchecked")
@Test
public void testFs() throws Exception {
    Reference refInfo = refInfo("sys.nodes.fs", DataTypes.STRING, RowGranularity.NODE);
    io.crate.operation.reference.NestedObjectExpression fs = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    Map<String, Object> v = fs.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((String) disk0.get("dev"), is("/dev/sda1"));
    assertThat((Long) disk0.get("size"), is(42L));
    Map<String, Object> disk1 = (Map<String, Object>) disks[1];
    assertThat((String) disk1.get("dev"), is("/dev/sda2"));
    assertThat((Long) disk0.get("used"), is(42L));
    Object[] data = (Object[]) v.get("data");
    assertThat(data.length, is(2));
    assertThat((String) ((Map<String, Object>) data[0]).get("dev"), is("/dev/sda1"));
    assertThat((String) ((Map<String, Object>) data[0]).get("path"), is("/foo"));
    assertThat((String) ((Map<String, Object>) data[1]).get("dev"), is("/dev/sda2"));
    assertThat((String) ((Map<String, Object>) data[1]).get("path"), is("/bar"));
    refInfo = refInfo("sys.nodes.fs", DataTypes.STRING, RowGranularity.NODE, "data", "dev");
    NestedObjectExpression fsRef = (NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    SysStaticObjectArrayReference dataRef = (SysStaticObjectArrayReference) fsRef.getChildImplementation(refInfo.ident().columnIdent().path().get(0));
    for (io.crate.operation.reference.NestedObjectExpression exp : dataRef.getChildImplementations()) {
        assertThat(exp.getChildImplementation(refInfo.ident().columnIdent().path().get(1)).value(), instanceOf(BytesRef.class));
    }
}
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) Map(java.util.Map) HashMap(java.util.HashMap) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 18 with Reference

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

the class SysNodesExpressionsTest method testId.

@Test
public void testId() throws Exception {
    Reference refInfo = refInfo("sys.nodes.id", DataTypes.STRING, RowGranularity.NODE);
    @SuppressWarnings("unchecked") ReferenceImplementation<BytesRef> id = (ReferenceImplementation<BytesRef>) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    assertEquals(new BytesRef("node-id-1"), id.value());
}
Also used : Reference(io.crate.metadata.Reference) BytesRef(org.apache.lucene.util.BytesRef) ReferenceImplementation(io.crate.metadata.ReferenceImplementation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 19 with Reference

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

the class SysNodesExpressionsTest method testLoad.

@Test
public void testLoad() throws Exception {
    Reference refInfo = refInfo("sys.nodes.load", DataTypes.OBJECT, RowGranularity.NODE);
    io.crate.operation.reference.NestedObjectExpression load = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    Map<String, Object> v = load.value();
    assertNull(v.get("something"));
    assertEquals(1D, v.get("1"));
    assertEquals(5D, v.get("5"));
    assertEquals(15D, v.get("15"));
    Input ci = load.getChildImplementation("1");
    assertEquals(1D, ci.value());
    ci = load.getChildImplementation("5");
    assertEquals(5D, ci.value());
    ci = load.getChildImplementation("15");
    assertEquals(15D, ci.value());
}
Also used : Input(io.crate.data.Input) 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 20 with Reference

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

the class TestGlobalSysExpressions method testClusterSettings.

@Test
public void testClusterSettings() throws Exception {
    Reference refInfo = refInfo("sys.cluster.settings", DataTypes.OBJECT, RowGranularity.CLUSTER);
    NestedObjectExpression settingsExpression = (NestedObjectExpression) resolver.getImplementation(refInfo);
    Map settings = settingsExpression.value();
    Map stats = (Map) settings.get(CrateSettings.STATS.name());
    assertThat(stats.get(CrateSettings.STATS_ENABLED.name()), is(CrateSettings.STATS_ENABLED.defaultValue()));
    assertThat(stats.get(CrateSettings.STATS_JOBS_LOG_SIZE.name()), is(CrateSettings.STATS_JOBS_LOG_SIZE.defaultValue()));
    assertThat(stats.get(CrateSettings.STATS_OPERATIONS_LOG_SIZE.name()), is(CrateSettings.STATS_OPERATIONS_LOG_SIZE.defaultValue()));
    Map statsBreakerLog = (Map) ((Map) stats.get(CrateSettings.STATS_BREAKER.name())).get(CrateSettings.STATS_BREAKER_LOG.name());
    Map statsBreakerLogJobs = (Map) statsBreakerLog.get(CrateSettings.STATS_BREAKER_LOG_JOBS.name());
    assertThat(statsBreakerLogJobs.get(CrateSettings.STATS_BREAKER_LOG_JOBS_LIMIT.name()), is(// convert default string value (percentage) to byte size string
    MemorySizeValue.parseBytesSizeValueOrHeapRatio(CrateSettings.STATS_BREAKER_LOG_JOBS_LIMIT.defaultValue(), CrateSettings.STATS_BREAKER_LOG_JOBS_LIMIT.settingName()).toString()));
    Map cluster = (Map) settings.get(CrateSettings.CLUSTER.name());
    Map gracefulStop = (Map) cluster.get(CrateSettings.GRACEFUL_STOP.name());
    assertThat(gracefulStop.get(CrateSettings.GRACEFUL_STOP_MIN_AVAILABILITY.name()), is(CrateSettings.GRACEFUL_STOP_MIN_AVAILABILITY.defaultValue()));
    assertThat(gracefulStop.get(CrateSettings.GRACEFUL_STOP_REALLOCATE.name()), is(CrateSettings.GRACEFUL_STOP_REALLOCATE.defaultValue()));
    assertThat(gracefulStop.get(CrateSettings.GRACEFUL_STOP_TIMEOUT.name()), is(CrateSettings.GRACEFUL_STOP_TIMEOUT.defaultValue().toString()));
    assertThat(gracefulStop.get(CrateSettings.GRACEFUL_STOP_FORCE.name()), is(CrateSettings.GRACEFUL_STOP_FORCE.defaultValue()));
    assertThat(gracefulStop.get(CrateSettings.GRACEFUL_STOP_TIMEOUT.name()), is(CrateSettings.GRACEFUL_STOP_TIMEOUT.defaultValue().toString()));
    Map routing = (Map) cluster.get(CrateSettings.ROUTING.name());
    Map routingAllocation = (Map) routing.get(CrateSettings.ROUTING_ALLOCATION.name());
    assertThat(routingAllocation.get(CrateSettings.ROUTING_ALLOCATION_ENABLE.name()), is(CrateSettings.ROUTING_ALLOCATION_ENABLE.defaultValue()));
    Map gateway = (Map) settings.get(CrateSettings.GATEWAY.name());
    assertThat(gateway.get(CrateSettings.GATEWAY_RECOVER_AFTER_TIME.name()), is(CrateSettings.GATEWAY_RECOVER_AFTER_TIME.defaultValue().toString()));
    assertThat(gateway.get(CrateSettings.GATEWAY_RECOVERY_AFTER_NODES.name()), is(CrateSettings.GATEWAY_RECOVERY_AFTER_NODES.defaultValue()));
    assertThat(gateway.get(CrateSettings.GATEWAY_EXPECTED_NODES.name()), is(CrateSettings.GATEWAY_EXPECTED_NODES.defaultValue()));
    Map licence = (Map) settings.get(CrateSettings.LICENSE.name());
    assertThat(licence.get(CrateSettings.LICENSE_ENTERPRISE.name()), is(CrateSettings.LICENSE_ENTERPRISE.defaultValue()));
}
Also used : Reference(io.crate.metadata.Reference) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) 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