@CheckForNull public static ProtobufSystemInfo.Attribute attribute(Section section, String key) { for (ProtobufSystemInfo.Attribute attribute : section.getAttributesList()) { if (attribute.getKey().equals(key)) { return attribute; } } return null; }
@Test public void system_properties_are_returned_in_alphabetical_order() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); List<String> keys = section.getAttributesList() .stream() .map(ProtobufSystemInfo.Attribute::getKey) .collect(Collectors.toList()); assertThat(keys).contains("java.vm.vendor", "os.name"); List<String> sortedKeys = new ArrayList<>(keys); Collections.sort(sortedKeys); assertThat(sortedKeys).isEqualTo(keys); } }
@Test public void should_hide_attributes_without_values() { MemoryMXBean memoryBean = mock(MemoryMXBean.class, Mockito.RETURNS_DEEP_STUBS); when(memoryBean.getHeapMemoryUsage().getCommitted()).thenReturn(-1L); JvmStateSection underTest = new JvmStateSection(PROCESS_NAME); ProtobufSystemInfo.Section section = underTest.toProtobuf(memoryBean); assertThat(section.getAttributesList()).extracting("key").doesNotContain("Heap Committed (MB)"); } }
private void writeSection(ProtobufSystemInfo.Section section, JsonWriter json) { json.name(section.getName()); json.beginObject(); for (ProtobufSystemInfo.Attribute attribute : section.getAttributesList()) { writeAttribute(attribute, json); } json.endObject(); }
@Test public void return_info_from_elasticsearch_api() { Collection<NodeInfo> nodes = underTest.load(); assertThat(nodes).hasSize(1); NodeInfo node = nodes.iterator().next(); assertThat(node.getName()).isNotEmpty(); assertThat(node.getHost()).isNotEmpty(); assertThat(node.getSections()).hasSize(1); ProtobufSystemInfo.Section stateSection = node.getSections().get(0); assertThat(stateSection.getAttributesList()) .extracting(ProtobufSystemInfo.Attribute::getKey) .contains( "Disk Available", "Store Size", "JVM Heap Usage", "JVM Heap Used", "JVM Heap Max", "JVM Non Heap Used", "JVM Threads", "Field Data Memory", "Field Data Circuit Breaker Limit", "Field Data Circuit Breaker Estimation", "Request Circuit Breaker Limit", "Request Circuit Breaker Estimation", "Query Cache Memory", "Request Cache Memory"); } }
@Test public void return_properties_and_sort_by_key() { settings.setProperty("foo", "foo value"); settings.setProperty("bar", "bar value"); ProtobufSystemInfo.Section protobuf = underTest.toProtobuf(); assertThatAttributeIs(protobuf, "bar", "bar value"); assertThatAttributeIs(protobuf, "foo", "foo value"); // keys are ordered alphabetically assertThat(protobuf.getAttributesList()) .extracting(ProtobufSystemInfo.Attribute::getKey) .containsExactly("bar", "foo"); }
private void writeSection(ProtobufSystemInfo.Section section, JsonWriter json) { json.name(section.getName()); json.beginObject(); for (ProtobufSystemInfo.Attribute attribute : section.getAttributesList()) { writeAttribute(attribute, json); } json.endObject(); }
@Test public void toSystemInfoSection() { JvmStateSection underTest = new JvmStateSection(PROCESS_NAME); ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(section.getName()).isEqualTo(PROCESS_NAME); assertThat(section.getAttributesCount()).isGreaterThan(0); assertThat(section.getAttributesList()).extracting("key") .contains( "Max Memory (MB)", "Free Memory (MB)", "Heap Max (MB)", "System Load Average", "Threads"); }