aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-07-04 17:36:56 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-07-17 10:52:47 +0200
commit28886acf8527efacf4f6c9732852aa10b8576459 (patch)
tree99cc5c89d207b0db9044e08d4217edd278876a51 /server/sonar-ce
parentc818fc85b3d32c358b5149647d384cc42f4ba5a1 (diff)
downloadsonarqube-28886acf8527efacf4f6c9732852aa10b8576459.tar.gz
sonarqube-28886acf8527efacf4f6c9732852aa10b8576459.zip
SONAR-9507 make sonar.ce.workerCount an internal property
Diffstat (limited to 'server/sonar-ce')
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java15
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java49
2 files changed, 32 insertions, 32 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java
index be00dbc3d08..3489c453c1a 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java
@@ -20,10 +20,10 @@
package org.sonar.ce.configuration;
import org.picocontainer.Startable;
-import org.sonar.api.config.Configuration;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
+import org.sonar.server.property.InternalProperties;
import static java.lang.String.format;
@@ -47,13 +47,12 @@ public class CeConfigurationImpl implements CeConfiguration, Startable {
private final int workerCount;
- public CeConfigurationImpl(Configuration config) {
- String workerCountAsStr = config.get(CE_WORKERS_COUNT_PROPERTY).orElse(null);
- if (workerCountAsStr == null || workerCountAsStr.isEmpty()) {
- this.workerCount = DEFAULT_WORKER_COUNT;
- } else {
- this.workerCount = parseStringValue(workerCountAsStr);
- }
+ public CeConfigurationImpl(InternalProperties internalProperties) {
+ this.workerCount = internalProperties.read(CE_WORKERS_COUNT_PROPERTY)
+ .map(String::trim)
+ .filter(s -> !s.isEmpty())
+ .map(CeConfigurationImpl::parseStringValue)
+ .orElse(DEFAULT_WORKER_COUNT);
}
private static int parseStringValue(String workerCountAsStr) {
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java
index 2f501716b2d..1f80b0b8eaa 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java
@@ -23,8 +23,9 @@ import java.util.Random;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.utils.MessageException;
+import org.sonar.server.property.InternalProperties;
+import org.sonar.server.property.MapInternalProperties;
import static java.lang.Math.abs;
import static org.assertj.core.api.Assertions.assertThat;
@@ -35,89 +36,89 @@ public class CeConfigurationImplTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private MapSettings settings = new MapSettings();
+ private InternalProperties settings = new MapInternalProperties();
@Test
public void getWorkerCount_returns_1_when_worker_property_is_not_defined() {
- assertThat(new CeConfigurationImpl(settings.asConfig()).getWorkerCount()).isEqualTo(1);
+ assertThat(new CeConfigurationImpl(settings).getWorkerCount()).isEqualTo(1);
}
@Test
public void getWorkerCount_returns_1_when_worker_property_is_empty() {
- settings.setProperty(CE_WORKERS_COUNT_PROPERTY, "");
+ settings.write(CE_WORKERS_COUNT_PROPERTY, "");
- assertThat(new CeConfigurationImpl(settings.asConfig()).getWorkerCount()).isEqualTo(1);
+ assertThat(new CeConfigurationImpl(settings).getWorkerCount()).isEqualTo(1);
}
@Test
public void getWorkerCount_returns_1_when_worker_property_is_space_chars() {
- settings.setProperty(CE_WORKERS_COUNT_PROPERTY, " \n ");
+ settings.write(CE_WORKERS_COUNT_PROPERTY, " \n ");
- assertThat(new CeConfigurationImpl(settings.asConfig()).getWorkerCount()).isEqualTo(1);
+ assertThat(new CeConfigurationImpl(settings).getWorkerCount()).isEqualTo(1);
}
@Test
public void getWorkerCount_returns_1_when_worker_property_is_1() {
- settings.setProperty(CE_WORKERS_COUNT_PROPERTY, 1);
+ settings.write(CE_WORKERS_COUNT_PROPERTY, String.valueOf(1));
- assertThat(new CeConfigurationImpl(settings.asConfig()).getWorkerCount()).isEqualTo(1);
+ assertThat(new CeConfigurationImpl(settings).getWorkerCount()).isEqualTo(1);
}
@Test
public void getWorkerCount_returns_value_when_worker_property_is_integer_greater_than_1() {
int value = abs(new Random().nextInt()) + 2;
- settings.setProperty(CE_WORKERS_COUNT_PROPERTY, value);
+ settings.write(CE_WORKERS_COUNT_PROPERTY, String.valueOf(value));
- assertThat(new CeConfigurationImpl(settings.asConfig()).getWorkerCount()).isEqualTo(value);
+ assertThat(new CeConfigurationImpl(settings).getWorkerCount()).isEqualTo(value);
}
@Test
public void constructor_throws_MessageException_when_worker_property_is_0() {
int value = 0;
- settings.setProperty(CE_WORKERS_COUNT_PROPERTY, String.valueOf(value));
+ settings.write(CE_WORKERS_COUNT_PROPERTY, String.valueOf(value));
expectMessageException(value);
- new CeConfigurationImpl(settings.asConfig());
+ new CeConfigurationImpl(settings);
}
@Test
public void constructor_throws_MessageException_when_worker_property_is_less_than_0() {
int value = -1 * abs(new Random().nextInt());
- settings.setProperty(CE_WORKERS_COUNT_PROPERTY, String.valueOf(value));
+ settings.write(CE_WORKERS_COUNT_PROPERTY, String.valueOf(value));
expectMessageException(value);
- new CeConfigurationImpl(settings.asConfig());
+ new CeConfigurationImpl(settings);
}
@Test
- public void constructor_throws_MessageException_when_worker_property_is_not_an_double() {
+ public void constructor_throws_MessageException_when_worker_property_is_a_double() {
double value = 3.5;
- settings.setProperty(CE_WORKERS_COUNT_PROPERTY, String.valueOf(value));
+ settings.write(CE_WORKERS_COUNT_PROPERTY, String.valueOf(value));
expectedException.expect(MessageException.class);
expectedException.expectMessage("value '" + value + "' of property " + CE_WORKERS_COUNT_PROPERTY + " is invalid. " +
- "It must an integer strictly greater than 0");
+ "It must an integer strictly greater than 0");
- new CeConfigurationImpl(settings.asConfig());
+ new CeConfigurationImpl(settings);
}
private void expectMessageException(int value) {
expectedException.expect(MessageException.class);
expectedException.expectMessage("value '" + value + "' of property " + CE_WORKERS_COUNT_PROPERTY + " is invalid. " +
- "It must an integer strictly greater than 0");
+ "It must an integer strictly greater than 0");
}
@Test
public void getCleanCeTasksInitialDelay_returns_1() {
- assertThat(new CeConfigurationImpl(settings.asConfig()).getCleanCeTasksInitialDelay())
- .isEqualTo(1L);
+ assertThat(new CeConfigurationImpl(settings).getCleanCeTasksInitialDelay())
+ .isEqualTo(1L);
}
@Test
public void getCleanCeTasksDelay_returns_10() {
- assertThat(new CeConfigurationImpl(settings.asConfig()).getCleanCeTasksDelay())
- .isEqualTo(10L);
+ assertThat(new CeConfigurationImpl(settings).getCleanCeTasksDelay())
+ .isEqualTo(10L);
}
}