public static ProtobufSystemInfo.SystemInfo provide() { ProtobufSystemInfo.SystemInfo.Builder protobuf = ProtobufSystemInfo.SystemInfo.newBuilder(); if (instance != null) { instance.sections.forEach(section -> protobuf.addSections(section.toProtobuf())); } return protobuf.build(); } }
@Test public void load_info_from_all_nodes() throws Exception { DistributedAnswer<SystemInfo> answer = new DistributedAnswer<>(); answer.setAnswer(newMember("foo"), SystemInfo.newBuilder().addSections(Section.newBuilder().build()).build()); answer.setTimedOut(newMember("bar")); answer.setFailed(newMember("baz"), new IOException("BOOM")); when(hzMember.call(any(DistributedCall.class), any(MemberSelector.class), anyLong())).thenReturn(answer); Collection<NodeInfo> nodes = underTest.load(); assertThat(nodes).hasSize(3); NodeInfo successfulNodeInfo = findNode(nodes, "foo"); assertThat(successfulNodeInfo.getName()).isEqualTo("foo"); assertThat(successfulNodeInfo.getHost()).hasValue(AN_ADDRESS.getHostAddress()); assertThat(successfulNodeInfo.getErrorMessage()).isEmpty(); assertThat(successfulNodeInfo.getSections()).hasSize(1); NodeInfo timedOutNodeInfo = findNode(nodes, "bar"); assertThat(timedOutNodeInfo.getName()).isEqualTo("bar"); assertThat(timedOutNodeInfo.getErrorMessage()).hasValue("Failed to retrieve information on time"); assertThat(timedOutNodeInfo.getSections()).isEmpty(); NodeInfo failedNodeInfo = findNode(nodes, "baz"); assertThat(failedNodeInfo.getName()).isEqualTo("baz"); assertThat(failedNodeInfo.getErrorMessage()).hasValue("Failed to retrieve information: BOOM"); assertThat(failedNodeInfo.getSections()).isEmpty(); }
@Override public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) { if (session.getMethod() != NanoHTTPD.Method.GET) { return newFixedLengthResponse(METHOD_NOT_ALLOWED, MIME_PLAINTEXT, null); } ProtobufSystemInfo.SystemInfo.Builder infoBuilder = ProtobufSystemInfo.SystemInfo.newBuilder(); for (SystemInfoSection sectionProvider : sectionProviders) { ProtobufSystemInfo.Section section = sectionProvider.toProtobuf(); infoBuilder.addSections(section); } byte[] bytes = infoBuilder.build().toByteArray(); return newFixedLengthResponse(OK, PROTOBUF_MIME_TYPE, new ByteArrayInputStream(bytes), bytes.length); } }
@Override public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session) { if (session.getMethod() != NanoHTTPD.Method.GET) { return newFixedLengthResponse(METHOD_NOT_ALLOWED, MIME_PLAINTEXT, null); } ProtobufSystemInfo.SystemInfo.Builder infoBuilder = ProtobufSystemInfo.SystemInfo.newBuilder(); for (SystemInfoSection sectionProvider : sectionProviders) { ProtobufSystemInfo.Section section = sectionProvider.toProtobuf(); infoBuilder.addSections(section); } byte[] bytes = infoBuilder.build().toByteArray(); return newFixedLengthResponse(OK, PROTOBUF_MIME_TYPE, new ByteArrayInputStream(bytes), bytes.length); } }
public static ProtobufSystemInfo.SystemInfo provide() { ProtobufSystemInfo.SystemInfo.Builder protobuf = ProtobufSystemInfo.SystemInfo.newBuilder(); if (instance != null) { instance.sections.forEach(section -> protobuf.addSections(section.toProtobuf())); } return protobuf.build(); } }