3 * Copyright (C) 2009-2022 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.monitoring;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.sonar.api.SonarQubeSide;
25 import org.sonar.api.SonarRuntime;
26 import org.sonar.api.utils.System2;
27 import org.sonar.db.DbTester;
28 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
29 import org.sonar.server.platform.db.migration.version.DatabaseVersion;
31 import static org.assertj.core.api.Assertions.assertThat;
32 import static org.mockito.Mockito.mock;
33 import static org.mockito.Mockito.when;
34 import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
36 public class DbConnectionSectionTest {
39 public DbTester dbTester = DbTester.create(System2.INSTANCE);
41 private DatabaseVersion databaseVersion = mock(DatabaseVersion.class);
42 private SonarRuntime runtime = mock(SonarRuntime.class);
43 private DbConnectionSection underTest = new DbConnectionSection(databaseVersion, dbTester.getDbClient(), runtime);
46 public void jmx_name_is_not_empty() {
47 assertThat(underTest.name()).isEqualTo("Database");
51 public void pool_info() {
52 ProtobufSystemInfo.Section section = underTest.toProtobuf();
53 assertThat(attribute(section, "Pool Max Connections").getLongValue()).isGreaterThan(0L);
54 assertThat(attribute(section, "Pool Idle Connections").getLongValue()).isGreaterThanOrEqualTo(0L);
55 assertThat(attribute(section, "Pool Min Idle Connections").getLongValue()).isGreaterThanOrEqualTo(0L);
56 assertThat(attribute(section, "Pool Max Idle Connections").getLongValue()).isGreaterThanOrEqualTo(0L);
57 assertThat(attribute(section, "Pool Max Wait (ms)")).isNotNull();
58 assertThat(attribute(section, "Pool Remove Abandoned")).isNotNull();
59 assertThat(attribute(section, "Pool Remove Abandoned Timeout (seconds)").getLongValue()).isGreaterThanOrEqualTo(0L);
63 public void section_name_depends_on_runtime_side() {
64 when(runtime.getSonarQubeSide()).thenReturn(SonarQubeSide.COMPUTE_ENGINE);
65 assertThat(underTest.toProtobuf().getName()).isEqualTo("Compute Engine Database Connection");
67 when(runtime.getSonarQubeSide()).thenReturn(SonarQubeSide.SERVER );
68 assertThat(underTest.toProtobuf().getName()).isEqualTo("Web Database Connection");