private static void addAttributeInMb(ProtobufSystemInfo.Section.Builder protobuf, String key, long valueInBytes) { if (valueInBytes >= 0L) { setAttribute(protobuf, key, valueInBytes / MEGABYTE); } } }
@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(); }
protected void writeSections(Collection<ProtobufSystemInfo.Section> sections, JsonWriter json) { SystemInfoUtils .order(sections, ORDERED_SECTION_NAMES) .forEach(section -> writeSection(section, json)); }
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); }
private static void addIfNotEmpty(ProtobufSystemInfo.Section.Builder protobuf, String key, @Nullable List<String> values) { if (values != null && !values.isEmpty()) { setAttribute(protobuf, key, COMMA_JOINER.join(values)); } } }
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); } }
@Test public void test_order() { Collection<Section> sections = asList( newSection("end2"), newSection("bar"), newSection("end1"), newSection("foo")); List<String> ordered = SystemInfoUtils.order(sections, "foo", "bar").stream() .map(Section::getName) .collect(Collectors.toList()); assertThat(ordered).isEqualTo(asList("foo", "bar", "end1", "end2")); }
private static void addIfNotEmpty(ProtobufSystemInfo.Section.Builder protobuf, String key, @Nullable List<String> values) { if (values != null && !values.isEmpty()) { setAttribute(protobuf, key, COMMA_JOINER.join(values)); } }
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); }
protected void writeSections(Collection<ProtobufSystemInfo.Section> sections, JsonWriter json) { SystemInfoUtils .order(sections, ORDERED_SECTION_NAMES) .forEach(section -> writeSection(section, json)); }
private void completePoolAttributes(Section.Builder protobuf) { setAttribute(protobuf, "Pool Active Connections", getPoolActiveConnections()); setAttribute(protobuf, "Pool Max Connections", getPoolMaxActiveConnections()); setAttribute(protobuf, "Pool Initial Size", getPoolInitialSize()); setAttribute(protobuf, "Pool Idle Connections", getPoolIdleConnections()); setAttribute(protobuf, "Pool Min Idle Connections", getPoolMinIdleConnections()); setAttribute(protobuf, "Pool Max Idle Connections", getPoolMaxIdleConnections()); setAttribute(protobuf, "Pool Max Wait (ms)", getPoolMaxWaitMillis()); setAttribute(protobuf, "Pool Remove Abandoned", getPoolRemoveAbandoned()); setAttribute(protobuf, "Pool Remove Abandoned Timeout (seconds)", getPoolRemoveAbandonedTimeoutSeconds()); }
@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); }
@Override public Section toProtobuf() { Section.Builder protobuf = Section.newBuilder(); protobuf.setName("Database"); try (DbSession dbSession = dbClient.openSession(false)) { DatabaseMetaData metadata = dbSession.getConnection().getMetaData(); setAttribute(protobuf, "Database", metadata.getDatabaseProductName()); setAttribute(protobuf, "Database Version", metadata.getDatabaseProductVersion()); setAttribute(protobuf, "Username", metadata.getUserName()); setAttribute(protobuf, "URL", metadata.getURL()); setAttribute(protobuf, "Driver", metadata.getDriverName()); setAttribute(protobuf, "Driver Version", metadata.getDriverVersion()); } catch (SQLException e) { throw new IllegalStateException("Fail to get DB metadata", e); } return protobuf.build(); } }
@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(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName(name); Map<Object, Object> sortedProperties = new TreeMap<>(System.getProperties()); for (Map.Entry<Object, Object> systemProp : sortedProperties.entrySet()) { if (systemProp.getValue() != null) { setAttribute(protobuf, Objects.toString(systemProp.getKey()), Objects.toString(systemProp.getValue())); } } return protobuf.build(); } }
@Test public void no_realm() { when(securityRealmFactory.getRealm()).thenReturn(null); ProtobufSystemInfo.Section protobuf = underTest.toProtobuf(); assertThat(attribute(protobuf, "External User Authentication")).isNull(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Version", server.getVersion()); setAttribute(protobuf, "Official Distribution", officialDistribution.check()); setAttribute(protobuf, "Home Dir", config.get(PATH_HOME.getKey()).orElse(null)); setAttribute(protobuf, "Data Dir", config.get(PATH_DATA.getKey()).orElse(null)); setAttribute(protobuf, "Temp Dir", config.get(PATH_TEMP.getKey()).orElse(null)); setAttribute(protobuf, "Processors", Runtime.getRuntime().availableProcessors()); return protobuf.build(); }
@Test public void no_realm() { when(securityRealmFactory.getRealm()).thenReturn(null); ProtobufSystemInfo.Section protobuf = underTest.toProtobuf(); assertThat(attribute(protobuf, "External User Authentication")).isNull(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Server ID", server.getId()); setAttribute(protobuf, "Version", getVersion()); setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication()); addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders()); addIfNotEmpty(protobuf, "External identity providers whose users are allowed to sign themselves up", getAllowsToSignUpEnabledIdentityProviders()); setAttribute(protobuf, "High Availability", false); setAttribute(protobuf, "Official Distribution", officialDistribution.check()); setAttribute(protobuf, "Force authentication", getForceAuthentication()); setAttribute(protobuf, "Home Dir", config.get(PATH_HOME.getKey()).orElse(null)); setAttribute(protobuf, "Data Dir", config.get(PATH_DATA.getKey()).orElse(null)); setAttribute(protobuf, "Temp Dir", config.get(PATH_TEMP.getKey()).orElse(null)); setAttribute(protobuf, "Processors", Runtime.getRuntime().availableProcessors()); return protobuf.build(); }