public static void assertThatAttributeIs(ProtobufSystemInfo.Section section, String key, long expectedValue) { ProtobufSystemInfo.Attribute value = attribute(section, key); assertThat(value).as(key).isNotNull(); assertThat(value.getLongValue()).isEqualTo(expectedValue); } }
public static void assertThatAttributeIs(ProtobufSystemInfo.Section section, String key, boolean expectedValue) { ProtobufSystemInfo.Attribute value = attribute(section, key); assertThat(value).as(key).isNotNull(); assertThat(value.getBooleanValue()).isEqualTo(expectedValue); }
@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; }
private void writeAttribute(ProtobufSystemInfo.Attribute attribute, JsonWriter json) { switch (attribute.getValueCase()) { case BOOLEAN_VALUE: json.prop(attribute.getKey(), attribute.getBooleanValue()); break; case LONG_VALUE: json.prop(attribute.getKey(), attribute.getLongValue()); break; case DOUBLE_VALUE: json.prop(attribute.getKey(), attribute.getDoubleValue()); break; case STRING_VALUE: json.prop(attribute.getKey(), attribute.getStringValue()); break; case VALUE_NOT_SET: json.name(attribute.getKey()).beginArray().values(attribute.getStringValuesList()).endArray(); break; default: throw new IllegalArgumentException("Unsupported type: " + attribute.getValueCase()); } }
private void writeAttribute(ProtobufSystemInfo.Attribute attribute, JsonWriter json) { switch (attribute.getValueCase()) { case BOOLEAN_VALUE: json.prop(attribute.getKey(), attribute.getBooleanValue()); break; case LONG_VALUE: json.prop(attribute.getKey(), attribute.getLongValue()); break; case DOUBLE_VALUE: json.prop(attribute.getKey(), attribute.getDoubleValue()); break; case STRING_VALUE: json.prop(attribute.getKey(), attribute.getStringValue()); break; case VALUE_NOT_SET: json.name(attribute.getKey()).beginArray().values(attribute.getStringValuesList()).endArray(); break; default: throw new IllegalArgumentException("Unsupported type: " + attribute.getValueCase()); } }
@Test public void pool_info() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(attribute(section, "Pool Max Connections").getLongValue()).isGreaterThan(0L); assertThat(attribute(section, "Pool Idle Connections").getLongValue()).isGreaterThanOrEqualTo(0L); assertThat(attribute(section, "Pool Min Idle Connections").getLongValue()).isGreaterThanOrEqualTo(0L); assertThat(attribute(section, "Pool Max Idle Connections").getLongValue()).isGreaterThanOrEqualTo(0L); assertThat(attribute(section, "Pool Max Wait (ms)")).isNotNull(); assertThat(attribute(section, "Pool Remove Abandoned")).isNotNull(); assertThat(attribute(section, "Pool Remove Abandoned Timeout (seconds)").getLongValue()).isGreaterThanOrEqualTo(0L); }
@Test public void db_info() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); SystemInfoTesting.assertThatAttributeIs(section, "Database", "H2"); assertThat(attribute(section, "Database Version").getStringValue()).startsWith("1."); SystemInfoTesting.assertThatAttributeIs(section, "Username", "SONAR"); assertThat(attribute(section, "Driver Version").getStringValue()).startsWith("1."); } }
@Test public void return_nb_of_processors() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(attribute(section, "Processors").getLongValue()).isGreaterThan(0); }
@Test public void test_attributes() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(attribute(section, "Nodes").getLongValue()).isGreaterThan(0); assertThat(attribute(section, "State").getStringValue()).isIn("RED", "YELLOW", "GREEN"); } }
@Test public void index_attributes() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); // one index "issues" assertThat(attribute(section, "Index issues - Docs").getLongValue()).isEqualTo(0L); assertThat(attribute(section, "Index issues - Shards").getLongValue()).isGreaterThan(0); assertThat(attribute(section, "Index issues - Store Size").getStringValue()).isNotNull(); }
@Test public void export_system_info() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(section.getName()).isEqualTo("Compute Engine Database Connection"); assertThat(section.getAttributesCount()).isEqualTo(9); assertThat(section.getAttributes(0).getKey()).isEqualTo("Pool Initial Size"); assertThat(section.getAttributes(0).getLongValue()).isGreaterThanOrEqualTo(0); }
@Test public void return_nb_of_processors() { ProtobufSystemInfo.Section protobuf = underTest.toProtobuf(); assertThat(attribute(protobuf, "Processors").getLongValue()).isGreaterThan(0); } }
public static void assertThatAttributeIs(ProtobufSystemInfo.Section section, String key, String expectedValue) { ProtobufSystemInfo.Attribute value = attribute(section, key); assertThat(value).as(key).isNotNull(); assertThat(value.getStringValue()).isEqualTo(expectedValue); }
@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(); }