aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-10-10 11:42:06 +0200
committerSonarTech <sonartech@sonarsource.com>2018-10-11 20:20:55 +0200
commitb89a430d01ffb30aa9f7cdde9c2d6f202ebe63fb (patch)
treece09c8947f170cb35343571be8b5645558d6dbf0 /server/sonar-ce
parent5b5488398259fcd6c1db21e5bd26bf005c7731a5 (diff)
downloadsonarqube-b89a430d01ffb30aa9f7cdde9c2d6f202ebe63fb.tar.gz
sonarqube-b89a430d01ffb30aa9f7cdde9c2d6f202ebe63fb.zip
SONAR-11923 do not return pending count via JMX in DataCenter edition
Diffstat (limited to 'server/sonar-ce')
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/CeQueueModule.java2
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java14
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/monitoring/DistributedCEQueueStatusImpl.java33
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplTest.java120
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CommonCEQueueStatusImplTest.java154
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/monitoring/DistributedCEQueueStatusImplTest.java48
6 files changed, 255 insertions, 116 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/CeQueueModule.java b/server/sonar-ce/src/main/java/org/sonar/ce/CeQueueModule.java
index df7633cd553..177aef33d64 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/CeQueueModule.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/CeQueueModule.java
@@ -19,7 +19,6 @@
*/
package org.sonar.ce;
-import org.sonar.ce.monitoring.CEQueueStatusImpl;
import org.sonar.ce.monitoring.CeTasksMBeanImpl;
import org.sonar.ce.queue.CeQueueInitializer;
import org.sonar.ce.queue.InternalCeQueueImpl;
@@ -33,7 +32,6 @@ public class CeQueueModule extends Module {
InternalCeQueueImpl.class,
// queue monitoring
- CEQueueStatusImpl.class,
CeTasksMBeanImpl.class,
// init queue state and queue processing
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
index 58669757d7d..fa97df37480 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
@@ -52,6 +52,8 @@ import org.sonar.ce.async.SynchronousAsyncExecution;
import org.sonar.ce.cleaning.CeCleaningModule;
import org.sonar.ce.db.ReadOnlyPropertiesDao;
import org.sonar.ce.logging.CeProcessLogging;
+import org.sonar.ce.monitoring.CEQueueStatusImpl;
+import org.sonar.ce.monitoring.DistributedCEQueueStatusImpl;
import org.sonar.ce.platform.CECoreExtensionsInstaller;
import org.sonar.ce.platform.ComputeEngineExtensionInstaller;
import org.sonar.ce.platform.DatabaseCompatibility;
@@ -464,9 +466,17 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
// system info
DbSection.class,
- ProcessInfoProvider.class);
+ ProcessInfoProvider.class,
+
+ DistributedCEQueueStatusImpl.class
+
+ );
} else {
- container.add(StandaloneCeDistributedInformation.class);
+ container.add(
+ StandaloneCeDistributedInformation.class,
+ CEQueueStatusImpl.class
+
+ );
}
}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/DistributedCEQueueStatusImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/DistributedCEQueueStatusImpl.java
new file mode 100644
index 00000000000..64b7239d37a
--- /dev/null
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/DistributedCEQueueStatusImpl.java
@@ -0,0 +1,33 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.ce.monitoring;
+
+import org.sonar.db.DbClient;
+
+public class DistributedCEQueueStatusImpl extends CEQueueStatusImpl {
+ public DistributedCEQueueStatusImpl(DbClient dbClient) {
+ super(dbClient);
+ }
+
+ @Override
+ public long getPendingCount() {
+ return 0;
+ }
+}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplTest.java
index 285c86ee4b0..b712d402d4b 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplTest.java
@@ -19,15 +19,10 @@
*/
package org.sonar.ce.monitoring;
-import java.util.Optional;
-import java.util.Random;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.sonar.db.DbClient;
import org.sonar.db.ce.CeQueueDto;
-import org.sonar.server.property.InternalProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -35,121 +30,22 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class CEQueueStatusImplTest {
- private static final int SOME_RANDOM_MAX = 96535;
- private static final int SOME_PROCESSING_TIME = 8723;
+public class CEQueueStatusImplTest extends CommonCEQueueStatusImplTest {
+ private CEQueueStatusImpl underTest = new CEQueueStatusImpl(getDbClient());
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- private DbClient dbClient = mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS);
- private CEQueueStatusImpl underTest = new CEQueueStatusImpl(dbClient);
-
- @Test
- public void verify_just_created_instance_metrics() {
- assertThat(underTest.getInProgressCount()).isEqualTo(0);
- assertThat(underTest.getErrorCount()).isEqualTo(0);
- assertThat(underTest.getSuccessCount()).isEqualTo(0);
- assertThat(underTest.getProcessingTime()).isEqualTo(0);
- }
-
- @Test
- public void addInProgress_increases_InProgress() {
- underTest.addInProgress();
-
- assertThat(underTest.getInProgressCount()).isEqualTo(1);
- assertThat(underTest.getErrorCount()).isEqualTo(0);
- assertThat(underTest.getSuccessCount()).isEqualTo(0);
- assertThat(underTest.getProcessingTime()).isEqualTo(0);
- }
-
- @Test
- public void addInProgress_any_number_of_call_change_by_1_per_call() {
- int calls = new Random().nextInt(SOME_RANDOM_MAX);
- for (int i = 0; i < calls; i++) {
- underTest.addInProgress();
- }
-
- assertThat(underTest.getInProgressCount()).isEqualTo(calls);
- assertThat(underTest.getProcessingTime()).isEqualTo(0);
- }
-
- @Test
- public void addError_throws_IAE_if_time_is_less_than_0() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Processing time can not be < 0");
-
- underTest.addError(-1);
- }
-
- @Test
- public void addError_increases_Error_and_decreases_InProgress_by_1_without_check_on_InProgress() {
- underTest.addError(SOME_PROCESSING_TIME);
-
- assertThat(underTest.getInProgressCount()).isEqualTo(-1);
- assertThat(underTest.getErrorCount()).isEqualTo(1);
- assertThat(underTest.getSuccessCount()).isEqualTo(0);
- assertThat(underTest.getProcessingTime()).isEqualTo(SOME_PROCESSING_TIME);
- }
-
- @Test
- public void addError_any_number_of_call_change_by_1_per_call() {
- int calls = new Random().nextInt(SOME_RANDOM_MAX);
- for (int i = 0; i < calls; i++) {
- underTest.addError(1);
- }
-
- assertThat(underTest.getErrorCount()).isEqualTo(calls);
- assertThat(underTest.getInProgressCount()).isEqualTo(-calls);
- assertThat(underTest.getProcessingTime()).isEqualTo(calls);
- }
-
- @Test
- public void addSuccess_throws_IAE_if_time_is_less_than_0() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Processing time can not be < 0");
-
- underTest.addSuccess(-1);
- }
-
- @Test
- public void addSuccess_increases_Error_and_decreases_InProgress_by_1_without_check_on_InProgress() {
- underTest.addSuccess(SOME_PROCESSING_TIME);
-
- assertThat(underTest.getInProgressCount()).isEqualTo(-1);
- assertThat(underTest.getErrorCount()).isEqualTo(0);
- assertThat(underTest.getSuccessCount()).isEqualTo(1);
- assertThat(underTest.getProcessingTime()).isEqualTo(SOME_PROCESSING_TIME);
+ public CEQueueStatusImplTest() {
+ super(mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS));
}
- @Test
- public void addSuccess_any_number_of_call_change_by_1_per_call() {
- int calls = new Random().nextInt(SOME_RANDOM_MAX);
- for (int i = 0; i < calls; i++) {
- underTest.addSuccess(1);
- }
-
- assertThat(underTest.getSuccessCount()).isEqualTo(calls);
- assertThat(underTest.getInProgressCount()).isEqualTo(-calls);
- assertThat(underTest.getProcessingTime()).isEqualTo(calls);
+ @Override
+ protected CEQueueStatusImpl getUnderTest() {
+ return underTest;
}
@Test
public void count_Pending_from_database() {
- when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.PENDING))).thenReturn(42);
+ when(getDbClient().ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.PENDING))).thenReturn(42);
assertThat(underTest.getPendingCount()).isEqualTo(42);
}
-
- @Test
- public void workers_pause_is_loaded_from_db() {
- when(dbClient.internalPropertiesDao().selectByKey(any(), eq(InternalProperties.COMPUTE_ENGINE_PAUSE))).thenReturn(Optional.of("true"));
-
- assertThat(underTest.areWorkersPaused()).isTrue();
- }
-
- @Test
- public void workers_pause_is_false_by_default() {
- assertThat(underTest.areWorkersPaused()).isFalse();
- }
}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CommonCEQueueStatusImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CommonCEQueueStatusImplTest.java
new file mode 100644
index 00000000000..1301f2a1818
--- /dev/null
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CommonCEQueueStatusImplTest.java
@@ -0,0 +1,154 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.ce.monitoring;
+
+import java.util.Optional;
+import java.util.Random;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.DbClient;
+import org.sonar.server.property.InternalProperties;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+public abstract class CommonCEQueueStatusImplTest {
+ private static final int SOME_RANDOM_MAX = 96535;
+ private static final int SOME_PROCESSING_TIME = 8723;
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private DbClient dbClient;
+
+ protected CommonCEQueueStatusImplTest(DbClient dbClient) {
+ this.dbClient = dbClient;
+ }
+
+ public DbClient getDbClient() {
+ return dbClient;
+ }
+
+ protected abstract CEQueueStatusImpl getUnderTest();
+
+ @Test
+ public void verify_just_created_instance_metrics() {
+ assertThat(getUnderTest().getInProgressCount()).isEqualTo(0);
+ assertThat(getUnderTest().getErrorCount()).isEqualTo(0);
+ assertThat(getUnderTest().getSuccessCount()).isEqualTo(0);
+ assertThat(getUnderTest().getProcessingTime()).isEqualTo(0);
+ }
+
+ @Test
+ public void addInProgress_increases_InProgress() {
+ getUnderTest().addInProgress();
+
+ assertThat(getUnderTest().getInProgressCount()).isEqualTo(1);
+ assertThat(getUnderTest().getErrorCount()).isEqualTo(0);
+ assertThat(getUnderTest().getSuccessCount()).isEqualTo(0);
+ assertThat(getUnderTest().getProcessingTime()).isEqualTo(0);
+ }
+
+ @Test
+ public void addInProgress_any_number_of_call_change_by_1_per_call() {
+ int calls = new Random().nextInt(SOME_RANDOM_MAX);
+ for (int i = 0; i < calls; i++) {
+ getUnderTest().addInProgress();
+ }
+
+ assertThat(getUnderTest().getInProgressCount()).isEqualTo(calls);
+ assertThat(getUnderTest().getProcessingTime()).isEqualTo(0);
+ }
+
+ @Test
+ public void addError_throws_IAE_if_time_is_less_than_0() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Processing time can not be < 0");
+
+ getUnderTest().addError(-1);
+ }
+
+ @Test
+ public void addError_increases_Error_and_decreases_InProgress_by_1_without_check_on_InProgress() {
+ getUnderTest().addError(SOME_PROCESSING_TIME);
+
+ assertThat(getUnderTest().getInProgressCount()).isEqualTo(-1);
+ assertThat(getUnderTest().getErrorCount()).isEqualTo(1);
+ assertThat(getUnderTest().getSuccessCount()).isEqualTo(0);
+ assertThat(getUnderTest().getProcessingTime()).isEqualTo(SOME_PROCESSING_TIME);
+ }
+
+ @Test
+ public void addError_any_number_of_call_change_by_1_per_call() {
+ int calls = new Random().nextInt(SOME_RANDOM_MAX);
+ for (int i = 0; i < calls; i++) {
+ getUnderTest().addError(1);
+ }
+
+ assertThat(getUnderTest().getErrorCount()).isEqualTo(calls);
+ assertThat(getUnderTest().getInProgressCount()).isEqualTo(-calls);
+ assertThat(getUnderTest().getProcessingTime()).isEqualTo(calls);
+ }
+
+ @Test
+ public void addSuccess_throws_IAE_if_time_is_less_than_0() {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Processing time can not be < 0");
+
+ getUnderTest().addSuccess(-1);
+ }
+
+ @Test
+ public void addSuccess_increases_Error_and_decreases_InProgress_by_1_without_check_on_InProgress() {
+ getUnderTest().addSuccess(SOME_PROCESSING_TIME);
+
+ assertThat(getUnderTest().getInProgressCount()).isEqualTo(-1);
+ assertThat(getUnderTest().getErrorCount()).isEqualTo(0);
+ assertThat(getUnderTest().getSuccessCount()).isEqualTo(1);
+ assertThat(getUnderTest().getProcessingTime()).isEqualTo(SOME_PROCESSING_TIME);
+ }
+
+ @Test
+ public void addSuccess_any_number_of_call_change_by_1_per_call() {
+ int calls = new Random().nextInt(SOME_RANDOM_MAX);
+ for (int i = 0; i < calls; i++) {
+ getUnderTest().addSuccess(1);
+ }
+
+ assertThat(getUnderTest().getSuccessCount()).isEqualTo(calls);
+ assertThat(getUnderTest().getInProgressCount()).isEqualTo(-calls);
+ assertThat(getUnderTest().getProcessingTime()).isEqualTo(calls);
+ }
+
+ @Test
+ public void workers_pause_is_loaded_from_db() {
+ when(dbClient.internalPropertiesDao().selectByKey(any(), eq(InternalProperties.COMPUTE_ENGINE_PAUSE))).thenReturn(Optional.of("true"));
+
+ assertThat(getUnderTest().areWorkersPaused()).isTrue();
+ }
+
+ @Test
+ public void workers_pause_is_false_by_default() {
+ assertThat(getUnderTest().areWorkersPaused()).isFalse();
+ }
+}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/DistributedCEQueueStatusImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/DistributedCEQueueStatusImplTest.java
new file mode 100644
index 00000000000..c738d284f55
--- /dev/null
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/DistributedCEQueueStatusImplTest.java
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.ce.monitoring;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.sonar.db.DbClient;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
+public class DistributedCEQueueStatusImplTest extends CommonCEQueueStatusImplTest {
+ private DistributedCEQueueStatusImpl underTest = new DistributedCEQueueStatusImpl(getDbClient());
+
+ public DistributedCEQueueStatusImplTest() {
+ super(mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS));
+ }
+
+ @Override
+ protected CEQueueStatusImpl getUnderTest() {
+ return underTest;
+ }
+
+ @Test
+ public void getPendingCount_returns_0_without_querying_database() {
+ assertThat(underTest.getPendingCount()).isZero();
+
+ verifyZeroInteractions(getDbClient());
+ }
+}