use of io.crate.operation.reference.NestedObjectExpression in project crate by crate.
the class SysNodesExpressionsWithDefaultExtendedStatsTest method testFsDataOnNonDataNode.
@Test
public void testFsDataOnNonDataNode() throws Exception {
prepare(false);
Reference refInfo = refInfo("sys.nodes.fs", DataTypes.STRING, RowGranularity.NODE, "data");
ColumnIdent columnIdent = refInfo.ident().columnIdent();
NestedObjectExpression fs = (NestedObjectExpression) resolver.getChildImplementation(columnIdent.name());
assertThat(((Object[]) fs.getChildImplementation(columnIdent.path().get(0)).value()).length, is(0));
}
use of io.crate.operation.reference.NestedObjectExpression in project crate by crate.
the class SysNodesExpressionsTest method testNetworkTCP.
@Test
public void testNetworkTCP() throws Exception {
Reference refInfo = refInfo("sys.nodes.network", DataTypes.OBJECT, RowGranularity.NODE, "tcp");
ColumnIdent columnIdent = refInfo.ident().columnIdent();
io.crate.operation.reference.NestedObjectExpression network = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(columnIdent.name());
NestedObjectExpression tcpRef = (NestedObjectExpression) network.getChildImplementation(columnIdent.path().get(0));
Map<String, Object> tcpStats = tcpRef.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}"));
}
use of io.crate.operation.reference.NestedObjectExpression 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));
}
}
use of io.crate.operation.reference.NestedObjectExpression 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()));
}
use of io.crate.operation.reference.NestedObjectExpression in project crate by crate.
the class SysShardsExpressionsTest method testRecoveryShardField.
@Test
public void testRecoveryShardField() throws Exception {
Reference refInfo = refInfo("sys.shards.recovery", DataTypes.OBJECT, RowGranularity.SHARD);
NestedObjectExpression ref = (NestedObjectExpression) resolver.getImplementation(refInfo);
Map<String, Object> recovery = ref.value();
assertEquals(RecoveryState.Stage.DONE.name(), recovery.get("stage"));
assertEquals(RecoveryState.Type.REPLICA.name(), recovery.get("type"));
assertEquals(10_000L, recovery.get("total_time"));
Map<String, Object> expectedFiles = new HashMap<String, Object>() {
{
put("used", 2);
put("reused", 1);
put("recovered", 1);
put("percent", 0.0f);
}
};
assertEquals(expectedFiles, recovery.get("files"));
Map<String, Object> expectedBytes = new HashMap<String, Object>() {
{
put("used", 2_048L);
put("reused", 1_024L);
put("recovered", 1_024L);
put("percent", 0.0f);
}
};
assertEquals(expectedBytes, recovery.get("size"));
}
Aggregations