import org.sonar.server.platform.WebServerImpl;
import org.sonar.server.platform.db.migration.MigrationConfigurationModule;
import org.sonar.server.platform.db.migration.version.DatabaseVersion;
-import org.sonar.server.platform.monitoring.DatabaseSection;
+import org.sonar.server.platform.monitoring.DbSection;
import org.sonar.server.platform.monitoring.cluster.LoggingSection;
import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider;
import org.sonar.server.plugins.InstalledPluginReferentialFactory;
CeDistributedInformationImpl.class,
// system info
- DatabaseSection.class,
+ DbSection.class,
ProcessInfoProvider.class,
LoggingSection.class);
} else {
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.monitoring;
-
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
-import org.apache.commons.dbcp.BasicDataSource;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo.Section;
-import org.sonar.server.platform.db.migration.version.DatabaseVersion;
-
-import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
-
-/**
- * Information about database and connection pool
- */
-public class DatabaseSection extends BaseSectionMBean implements DatabaseSectionMBean {
-
- private final DatabaseVersion dbVersion;
- private final DbClient dbClient;
-
- public DatabaseSection(DatabaseVersion dbVersion, DbClient dbClient) {
- this.dbVersion = dbVersion;
- this.dbClient = dbClient;
- }
-
- @Override
- public String name() {
- return "Database";
- }
-
- @Override
- public String getMigrationStatus() {
- return dbVersion.getStatus().name();
- }
-
- @Override
- public int getPoolActiveConnections() {
- return commonsDbcp().getNumActive();
- }
-
- @Override
- public int getPoolMaxActiveConnections() {
- return commonsDbcp().getMaxActive();
- }
-
- @Override
- public int getPoolIdleConnections() {
- return commonsDbcp().getNumIdle();
- }
-
- @Override
- public int getPoolMaxIdleConnections() {
- return commonsDbcp().getMaxIdle();
- }
-
- @Override
- public int getPoolMinIdleConnections() {
- return commonsDbcp().getMinIdle();
- }
-
- @Override
- public int getPoolInitialSize() {
- return commonsDbcp().getInitialSize();
- }
-
- @Override
- public long getPoolMaxWaitMillis() {
- return commonsDbcp().getMaxWait();
- }
-
- @Override
- public boolean getPoolRemoveAbandoned() {
- return commonsDbcp().getRemoveAbandoned();
- }
-
- @Override
- public int getPoolRemoveAbandonedTimeoutSeconds() {
- return commonsDbcp().getRemoveAbandonedTimeout();
- }
-
- @Override
- public Section toProtobuf() {
- Section.Builder protobuf = Section.newBuilder();
- protobuf.setName(name());
- completeDbAttributes(protobuf);
- completePoolAttributes(protobuf);
- return protobuf.build();
- }
-
- 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());
- }
-
- private BasicDataSource commonsDbcp() {
- return (BasicDataSource) dbClient.getDatabase().getDataSource();
- }
-
- private void completeDbAttributes(Section.Builder protobuf) {
- 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());
- setAttribute(protobuf, "Version Status", getMigrationStatus());
- } catch (SQLException e) {
- throw new IllegalStateException("Fail to get DB metadata", e);
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.monitoring;
-
-public interface DatabaseSectionMBean {
-
- /**
- * Is database schema up-to-date or should it be upgraded ?
- */
- String getMigrationStatus();
-
- /**
- *
- */
- int getPoolActiveConnections();
-
- /**
- * The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.
- */
- int getPoolMaxActiveConnections();
-
- int getPoolIdleConnections();
-
- /**
- * The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit.
- */
- int getPoolMaxIdleConnections();
-
- /**
- * The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero to create none.
- */
- int getPoolMinIdleConnections();
-
- /**
- * The initial number of connections that are created when the pool is started.
- */
- int getPoolInitialSize();
-
- /**
- * The maximum number of milliseconds that the pool will wait
- * (when there are no available connections) for a connection to be returned before throwing an exception, or -1 to wait indefinitely.
- */
- long getPoolMaxWaitMillis();
-
- /**
- * Flag to remove abandoned connections if they exceed the {@link #getPoolRemoveAbandonedTimeoutSeconds()}.
- */
- boolean getPoolRemoveAbandoned();
-
- /**
- * Timeout in seconds before an abandoned connection can be removed.
- */
- int getPoolRemoveAbandonedTimeoutSeconds();
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.monitoring;
+
+import org.apache.commons.dbcp.BasicDataSource;
+import org.sonar.api.SonarQubeSide;
+import org.sonar.api.SonarRuntime;
+import org.sonar.db.DbClient;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo.Section;
+import org.sonar.server.platform.db.migration.version.DatabaseVersion;
+
+import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
+
+/**
+ * Information about database connection pool
+ */
+public class DbConnectionSection extends BaseSectionMBean implements DbConnectionSectionMBean {
+
+ private final DatabaseVersion dbVersion;
+ private final DbClient dbClient;
+ private final SonarRuntime runtime;
+
+ public DbConnectionSection(DatabaseVersion dbVersion, DbClient dbClient, SonarRuntime runtime) {
+ this.dbVersion = dbVersion;
+ this.dbClient = dbClient;
+ this.runtime = runtime;
+ }
+
+ @Override
+ public String name() {
+ return "Database";
+ }
+
+ @Override
+ public String getMigrationStatus() {
+ return dbVersion.getStatus().name();
+ }
+
+ @Override
+ public int getPoolActiveConnections() {
+ return commonsDbcp().getNumActive();
+ }
+
+ @Override
+ public int getPoolMaxActiveConnections() {
+ return commonsDbcp().getMaxActive();
+ }
+
+ @Override
+ public int getPoolIdleConnections() {
+ return commonsDbcp().getNumIdle();
+ }
+
+ @Override
+ public int getPoolMaxIdleConnections() {
+ return commonsDbcp().getMaxIdle();
+ }
+
+ @Override
+ public int getPoolMinIdleConnections() {
+ return commonsDbcp().getMinIdle();
+ }
+
+ @Override
+ public int getPoolInitialSize() {
+ return commonsDbcp().getInitialSize();
+ }
+
+ @Override
+ public long getPoolMaxWaitMillis() {
+ return commonsDbcp().getMaxWait();
+ }
+
+ @Override
+ public boolean getPoolRemoveAbandoned() {
+ return commonsDbcp().getRemoveAbandoned();
+ }
+
+ @Override
+ public int getPoolRemoveAbandonedTimeoutSeconds() {
+ return commonsDbcp().getRemoveAbandonedTimeout();
+ }
+
+ @Override
+ public Section toProtobuf() {
+ Section.Builder protobuf = Section.newBuilder();
+ String side = runtime.getSonarQubeSide() == SonarQubeSide.COMPUTE_ENGINE ? "Compute Engine" : "Web";
+ protobuf.setName(side + " Database Connection");
+ completePoolAttributes(protobuf);
+ return protobuf.build();
+ }
+
+ 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());
+ }
+
+ private BasicDataSource commonsDbcp() {
+ return (BasicDataSource) dbClient.getDatabase().getDataSource();
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.monitoring;
+
+public interface DbConnectionSectionMBean {
+
+ /**
+ * Is database schema up-to-date or should it be upgraded ?
+ */
+ String getMigrationStatus();
+
+ /**
+ *
+ */
+ int getPoolActiveConnections();
+
+ /**
+ * The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.
+ */
+ int getPoolMaxActiveConnections();
+
+ int getPoolIdleConnections();
+
+ /**
+ * The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit.
+ */
+ int getPoolMaxIdleConnections();
+
+ /**
+ * The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero to create none.
+ */
+ int getPoolMinIdleConnections();
+
+ /**
+ * The initial number of connections that are created when the pool is started.
+ */
+ int getPoolInitialSize();
+
+ /**
+ * The maximum number of milliseconds that the pool will wait
+ * (when there are no available connections) for a connection to be returned before throwing an exception, or -1 to wait indefinitely.
+ */
+ long getPoolMaxWaitMillis();
+
+ /**
+ * Flag to remove abandoned connections if they exceed the {@link #getPoolRemoveAbandonedTimeoutSeconds()}.
+ */
+ boolean getPoolRemoveAbandoned();
+
+ /**
+ * Timeout in seconds before an abandoned connection can be removed.
+ */
+ int getPoolRemoveAbandonedTimeoutSeconds();
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.monitoring;
+
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.process.systeminfo.Global;
+import org.sonar.process.systeminfo.SystemInfoSection;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo.Section;
+
+import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
+
+/**
+ * Information about database
+ */
+public class DbSection implements SystemInfoSection, Global {
+
+ private final DbClient dbClient;
+
+ public DbSection(DbClient dbClient) {
+ this.dbClient = dbClient;
+ }
+
+ @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();
+ }
+}
import org.sonar.process.systeminfo.JvmPropertiesSection;
import org.sonar.process.systeminfo.JvmStateSection;
import org.sonar.server.platform.monitoring.cluster.AppNodesInfoLoaderImpl;
+import org.sonar.server.platform.monitoring.cluster.CeQueueGlobalSection;
import org.sonar.server.platform.monitoring.cluster.GlobalInfoLoader;
import org.sonar.server.platform.monitoring.cluster.GlobalSystemSection;
-import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider;
import org.sonar.server.platform.monitoring.cluster.LoggingSection;
import org.sonar.server.platform.monitoring.cluster.NodeSystemSection;
+import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider;
import org.sonar.server.platform.monitoring.cluster.SearchNodesInfoLoaderImpl;
import org.sonar.server.platform.ws.ClusterInfoAction;
import org.sonar.server.platform.ws.InfoAction;
return new Object[] {
new JvmPropertiesSection("Web JVM Properties"),
new JvmStateSection("Web JVM State"),
- DatabaseSection.class,
+ DbSection.class,
+ DbConnectionSection.class,
EsStateSection.class,
EsIndexesSection.class,
PluginsSection.class,
return new Object[] {
new JvmPropertiesSection("Web JVM Properties"),
new JvmStateSection("Web JVM State"),
- DatabaseSection.class,
+ CeQueueGlobalSection.class,
+ DbSection.class,
+ DbConnectionSection.class,
EsIndexesSection.class,
GlobalSystemSection.class,
LoggingSection.class,
public abstract class BaseInfoWsAction implements SystemWsAction {
private static final String[] ORDERED_SECTION_NAMES = {
+ // standalone
"System", "Database", "Plugins",
+
+ // cluster
"Web JVM State", "Web Database Connection", "Web Logging", "Web JVM Properties",
- "Search State", "Search Indexes",
- "Compute Engine Tasks", "Compute Engine JVM State", "Compute Engine Database Connection", "Compute Engine Logging", "Compute Engine JVM Properties"};
+ "Compute Engine Tasks", "Compute Engine JVM State", "Compute Engine Database Connection", "Compute Engine Logging", "Compute Engine JVM Properties",
+ "Search State", "Search Indexes"};
private final UserSession userSession;
private final TelemetryDataLoader telemetry;
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.monitoring;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
-import org.sonar.server.platform.db.migration.version.DatabaseVersion;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
-import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
-
-public class DatabaseSectionTest {
-
- @Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
- private DatabaseVersion databaseVersion = mock(DatabaseVersion.class);
- private DatabaseSection underTest = new DatabaseSection(databaseVersion, dbTester.getDbClient());
-
- @Before
- public void setUp() throws Exception {
- when(databaseVersion.getStatus()).thenReturn(DatabaseVersion.Status.UP_TO_DATE);
- }
-
- @Test
- public void name_is_not_empty() {
- assertThat(underTest.name()).isNotEmpty();
- }
-
- @Test
- public void db_info() {
- ProtobufSystemInfo.Section section = underTest.toProtobuf();
- assertThatAttributeIs(section, "Database", "H2");
- assertThat(attribute(section, "Database Version").getStringValue()).startsWith("1.");
- assertThatAttributeIs(section, "Username", "SONAR");
- assertThat(attribute(section, "Driver Version").getStringValue()).startsWith("1.");
- }
-
- @Test
- public void pool_info() {
- ProtobufSystemInfo.Section section = underTest.toProtobuf();
- assertThat(attribute(section, "Pool Max Connections").getLongValue()).isGreaterThan(0L);
- }
-}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.monitoring;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.SonarQubeSide;
+import org.sonar.api.SonarRuntime;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import org.sonar.server.platform.db.migration.version.DatabaseVersion;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
+
+public class DbConnectionSectionTest {
+
+ @Rule
+ public DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+ private DatabaseVersion databaseVersion = mock(DatabaseVersion.class);
+ private SonarRuntime runtime = mock(SonarRuntime.class);
+ private DbConnectionSection underTest = new DbConnectionSection(databaseVersion, dbTester.getDbClient(), runtime);
+
+ @Test
+ public void jmx_name_is_not_empty() {
+ assertThat(underTest.name()).isEqualTo("Database");
+ }
+
+ @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 section_name_depends_on_runtime_side() {
+ when(runtime.getSonarQubeSide()).thenReturn(SonarQubeSide.COMPUTE_ENGINE);
+ assertThat(underTest.toProtobuf().getName()).isEqualTo("Compute Engine Database Connection");
+
+ when(runtime.getSonarQubeSide()).thenReturn(SonarQubeSide.SERVER );
+ assertThat(underTest.toProtobuf().getName()).isEqualTo("Web Database Connection");
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.monitoring;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
+import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
+
+public class DbSectionTest {
+
+ @Rule
+ public DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+ private DbSection underTest = new DbSection(dbTester.getDbClient());
+
+ @Test
+ public void db_info() {
+ ProtobufSystemInfo.Section section = underTest.toProtobuf();
+ assertThatAttributeIs(section, "Database", "H2");
+ assertThat(attribute(section, "Database Version").getStringValue()).startsWith("1.");
+ assertThatAttributeIs(section, "Username", "SONAR");
+ assertThat(attribute(section, "Driver Version").getStringValue()).startsWith("1.");
+ }
+}
*/
package org.sonar.server.platform.monitoring;
-import java.util.Collection;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
import static org.assertj.core.api.Assertions.assertThat;
assertThat(value.getBooleanValue()).isEqualTo(expectedValue);
}
- public static void assertThatAttributeHasOnlyValues(ProtobufSystemInfo.Section section, String key, Collection<String> expectedValues) {
+ public static void assertThatAttributeIs(ProtobufSystemInfo.Section section, String key, long expectedValue) {
ProtobufSystemInfo.Attribute value = attribute(section, key);
assertThat(value).as(key).isNotNull();
- assertThat((Collection<String>)value.getStringValuesList()).containsExactlyInAnyOrder(expectedValues.toArray(new String[expectedValues.size()]));
+ assertThat(value.getLongValue()).isEqualTo(expectedValue);
}
}
import com.codeborne.selenide.SelenideElement;
+import static com.codeborne.selenide.Condition.exactText;
import static com.codeborne.selenide.Condition.exist;
import static com.codeborne.selenide.Condition.text;
public SystemInfoPageItem shouldNotHaveField(String field) {
ensureOpen();
- elt.$$(".system-info-section-item-name").findBy(text(field)).shouldNot(exist);
+ elt.$$(".system-info-section-item-name").findBy(exactText(field)).shouldNot(exist);
return this;
}
page.getCardItem("System")
.shouldHaveHealth()
.shouldHaveMainSection()
- .shouldNotHaveSection("Database")
+ .shouldHaveSection("Database")
+ .shouldHaveField("Database Version")
.shouldNotHaveSection("Settings")
.shouldNotHaveSection("Plugins")
.shouldHaveField("High Availability")
page.getCardItem("Search")
.shouldHaveSection("Search State")
- .shouldHaveSection("Search Statistics");
+ .shouldHaveSection("Search Indexes");
}
@Test