use of io.crate.monitor.DummyExtendedNodeInfo in project crate by crate.
the class SysNodesExpressionsOnHandlerTest method setup.
@BeforeClass
public static void setup() throws IOException {
// jvm
JvmStats jvmStats = mock(JvmStats.class);
JvmStats.Mem jvmStatsMem = mock(JvmStats.Mem.class);
ByteSizeValue heapByteSizeValueMax = new ByteSizeValue(123456L);
when(jvmStatsMem.getHeapMax()).thenReturn(heapByteSizeValueMax);
when(jvmStatsMem.getHeapUsed()).thenReturn(heapByteSizeValueMax);
when(jvmStats.getMem()).thenReturn(jvmStatsMem);
// mem
ByteSizeValue byteSizeValue = new ByteSizeValue(12345342234L);
// os service
OsService osService = mock(OsService.class);
OsStats osStats = mock(OsStats.class);
when(osService.stats()).thenReturn(osStats);
OsStats.Mem mem = mock(OsStats.Mem.class);
when(osStats.getMem()).thenReturn(mem);
when(mem.getFree()).thenReturn(byteSizeValue);
when(mem.getUsed()).thenReturn(byteSizeValue);
when(mem.getUsedPercent()).thenReturn((short) 22);
when(mem.getFreePercent()).thenReturn((short) 78);
// os info
OsInfo osInfo = mock(OsInfo.class);
when(osService.info()).thenReturn(osInfo);
when(osInfo.getAvailableProcessors()).thenReturn(4);
// node info
NodeEnvironment nodeEnv = mock(NodeEnvironment.class);
Path[] dataLocations = new Path[] { new File("/foo").toPath(), new File("/bar").toPath() };
when(nodeEnv.hasNodeFile()).then(invocation -> true);
when(nodeEnv.nodeDataPaths()).thenReturn(dataLocations);
ExtendedNodeInfo extendedNodeInfo = new DummyExtendedNodeInfo(nodeEnv);
// process stats
ProcessStats processStats = mock(ProcessStats.class);
when(processStats.getOpenFileDescriptors()).thenReturn(42L);
when(processStats.getMaxFileDescriptors()).thenReturn(1000L);
CONTEXT.id(BytesRefs.toBytesRef("93c7ff92-52fa-11e6-aad8-3c15c2d3ad18"));
CONTEXT.name(BytesRefs.toBytesRef("crate1"));
CONTEXT.hostname(BytesRefs.toBytesRef("crate1.example.com"));
CONTEXT.version(Version.CURRENT);
CONTEXT.build(Build.CURRENT);
CONTEXT.timestamp(100L);
CONTEXT.restUrl(BytesRefs.toBytesRef("10.0.0.1:4200"));
CONTEXT.port(new HashMap<String, Integer>(2) {
{
put("http", 4200);
put("transport", 4300);
}
});
CONTEXT.jvmStats(jvmStats);
CONTEXT.osInfo(osInfo);
CONTEXT.processStats(processStats);
CONTEXT.osStats(osStats);
CONTEXT.extendedOsStats(extendedNodeInfo.osStats());
CONTEXT.networkStats(extendedNodeInfo.networkStats());
CONTEXT.extendedProcessCpuStats(extendedNodeInfo.processCpuStats());
CONTEXT.extendedFsStats(extendedNodeInfo.fsStats());
}
Aggregations