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"));
}
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));
}
}
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}" + "}"));
}
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"));
}
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"));
}
Aggregations