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);
ProcessStats processStats = mock(ProcessStats.class);
when(nodeStats.getProcess()).thenReturn(processStats);
when(processStats.getOpenFileDescriptors()).thenReturn(42L);
NodeInfo nodeInfo = mock(NodeInfo.class);
when(nodeService.info()).thenReturn(nodeInfo);
ProcessInfo processInfo = mock(ProcessInfo.class);
when(nodeInfo.getProcess()).thenReturn(processInfo);
when(processInfo.getMaxFileDescriptors()).thenReturn(1000L);
Discovery discovery = mock(Discovery.class);
bind(Discovery.class).toInstance(discovery);
when(discovery.localNode()).thenReturn(node);
when(node.getId()).thenReturn("node-id-1");
when(node.getName()).thenReturn("node 1");
TransportAddress transportAddress = new InetSocketTransportAddress("localhost", 44300);
when(node.address()).thenReturn(transportAddress);
NetworkStats.Tcp tcp = mock(NetworkStats.Tcp.class, new Answer<Long>() {
@Override
public Long answer(InvocationOnMock invocation) throws Throwable {
return 42L;