@Override
protected void configure() {
bind(Settings.class).toInstance(ImmutableSettings.EMPTY);
OsService osService = mock(OsService.class);
OsStats osStats = mock(OsStats.class);
when(osService.stats()).thenReturn(osStats);
when(osStats.loadAverage()).thenAnswer(new Answer<double[]>() {
@Override
public double[] answer(InvocationOnMock invocation) throws Throwable {
if (onWindows) {
return new double[0]; // windows behaviour
} else {
return new double[]{1, 5, 15}; // unix behaviour
}
}
});
ByteSizeValue byteSizeValue = mock(ByteSizeValue.class);
when(byteSizeValue.bytes()).thenReturn(12345342234L);
when(byteSizeValue.toString()).thenReturn("11.4gb");
OsStats.Mem mem = mock(OsStats.Mem.class);
when(osStats.mem()).thenReturn(mem);
when(mem.actualFree()).thenReturn(byteSizeValue);
when(mem.actualUsed()).thenReturn(byteSizeValue);
when(mem.usedPercent()).thenReturn((short) 22);
when(mem.freePercent()).thenReturn((short) 78);
bind(OsService.class).toInstance(osService);
NodeService nodeService = mock(NodeService.class);
NodeStats nodeStats = mock(NodeStats.class);
when(nodeService.stats()).thenReturn(nodeStats);
when(nodeStats.getHostname()).thenReturn("localhost");
DiscoveryNode node = mock(DiscoveryNode.class);
when(nodeStats.getNode()).thenReturn(node);
when(nodeStats.getOs()).thenReturn(osStats);
when(osStats.uptime()).thenReturn(new TimeValue(3600000));
OsStats.Cpu cpu = mock(OsStats.Cpu.class);
when(osStats.cpu()).thenReturn(cpu);
when(cpu.sys()).thenReturn((short) 2);
when(cpu.user()).thenReturn((short) 4);
when(cpu.idle()).thenReturn((short) 94);
when(cpu.stolen()).thenReturn((short) 10);