aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-07-06 11:49:59 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-07-17 10:52:47 +0200
commit15a91cd610798c913821f9a2bfbed33a32d058fa (patch)
treebe29503552f98f783e969ba3f13c2f8c2cde4bdc
parent525067cc13b2daf2b5f0ffa84e56ab0ceb20e84f (diff)
downloadsonarqube-15a91cd610798c913821f9a2bfbed33a32d058fa.tar.gz
sonarqube-15a91cd610798c913821f9a2bfbed33a32d058fa.zip
SONAR-9525 do not allow value > 10 from WorkerCountProvider
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java4
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java16
2 files changed, 15 insertions, 5 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 3f3433e3c08..75cd049f9a5 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
@@ -55,7 +55,7 @@ public class CeConfigurationImpl implements CeConfiguration, Startable {
public CeConfigurationImpl(WorkerCountProvider workerCountProvider) {
int value = workerCountProvider.get();
- if (value < 1) {
+ if (value < DEFAULT_WORKER_COUNT || value > MAX_WORKER_THREAD_COUNT) {
throw parsingError(value);
}
this.workerThreadCount = MAX_WORKER_THREAD_COUNT;
@@ -64,7 +64,7 @@ public class CeConfigurationImpl implements CeConfiguration, Startable {
private static MessageException parsingError(int value) {
return MessageException.of(format(
- "Worker count '%s' is invalid. It must an integer strictly greater than 0.",
+ "Worker count '%s' is invalid. It must an integer strictly greater than 0 and less or equal to 10",
value));
}
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 36c84903eab..2a8ac541d5c 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
@@ -46,7 +46,7 @@ public class CeConfigurationImplTest {
@Test
public void getWorkerCount_returns_value_returned_by_WorkerCountProvider_when_available() {
- int value = 1 + Math.abs(new Random().nextInt());
+ int value = 1 + Math.abs(new Random().nextInt(10));
workerCountProvider.set(value);
assertThat(new CeConfigurationImpl(workerCountProvider).getWorkerCount()).isEqualTo(value);
@@ -56,7 +56,7 @@ public class CeConfigurationImplTest {
public void getWorkerThreadCount_returns_10_whichever_the_value_returned_by_WorkerCountProvider() {
int value = 1 + Math.abs(new Random().nextInt(10));
workerCountProvider.set(value);
-
+
assertThat(new CeConfigurationImpl(workerCountProvider).getWorkerMaxCount()).isEqualTo(10);
}
@@ -79,10 +79,20 @@ public class CeConfigurationImplTest {
new CeConfigurationImpl(workerCountProvider);
}
+ @Test
+ public void constructor_throws_MessageException_when_WorkerCountProvider_returns_more_then_10() {
+ int value = 10 + abs(new Random().nextInt());
+ workerCountProvider.set(value);
+
+ expectMessageException(value);
+
+ new CeConfigurationImpl(workerCountProvider);
+ }
+
private void expectMessageException(int value) {
expectedException.expect(MessageException.class);
expectedException.expectMessage("Worker count '" + value + "' is invalid. " +
- "It must an integer strictly greater than 0");
+ "It must an integer strictly greater than 0 and less or equal to 10");
}
@Test