}
}
- public static void setAttribute(Section.Builder section, String key, boolean value) {
- section.addAttributesBuilder()
- .setKey(key)
- .setBooleanValue(value)
- .build();
+ public static void setAttribute(Section.Builder section, String key, @Nullable Boolean value) {
+ if (value != null) {
+ section.addAttributesBuilder()
+ .setKey(key)
+ .setBooleanValue(value)
+ .build();
+ }
}
public static void setAttribute(Section.Builder section, String key, long value) {
public class SystemInfoUtilsTest {
+ @Test
+ public void test_setAttribute_with_boolean_parameter() {
+ Section.Builder builder = Section.newBuilder();
+ SystemInfoUtils.setAttribute(builder, "isNull", (Boolean)null);
+ SystemInfoUtils.setAttribute(builder, "isTrue", true);
+ SystemInfoUtils.setAttribute(builder, "isFalse", false);
+
+ Section section = builder.build();
+ assertThat(SystemInfoUtils.attribute(section, "isNull")).isNull();
+ assertThat(SystemInfoUtils.attribute(section, "isTrue").getBooleanValue()).isTrue();
+ assertThat(SystemInfoUtils.attribute(section, "isFalse").getBooleanValue()).isFalse();
+ }
+
@Test
public void test_order() {
Collection<Section> sections = asList(
setAttribute(protobuf, "Disk Available", byteCountToDisplaySize(stats.getFs().getTotal().getAvailable().getBytes()));
setAttribute(protobuf, "Store Size", byteCountToDisplaySize(stats.getIndices().getStore().getSizeInBytes()));
setAttribute(protobuf, "Open Files", stats.getProcess().getOpenFileDescriptors());
+ setAttribute(protobuf, "Spinning", stats.getFs().getTotal().getSpins());
setAttribute(protobuf, "JVM Heap Usage", formatPercent(stats.getJvm().getMem().getHeapUsedPercent()));
setAttribute(protobuf, "JVM Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getHeapUsed().getBytes()));
setAttribute(protobuf, "JVM Heap Max", byteCountToDisplaySize(stats.getJvm().getMem().getHeapMax().getBytes()));