]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9525 do not allow value > 10 from WorkerCountProvider
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 6 Jul 2017 09:49:59 +0000 (11:49 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 17 Jul 2017 08:52:47 +0000 (10:52 +0200)
server/sonar-ce/src/main/java/org/sonar/ce/configuration/CeConfigurationImpl.java
server/sonar-ce/src/test/java/org/sonar/ce/configuration/CeConfigurationImplTest.java

index 3f3433e3c0827ec426f1d32deb9105929713f828..75cd049f9a5c6738db6fae2cec086b66c6b45920 100644 (file)
@@ -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));
   }
 
index 36c84903eab0089af512bc5c46205aaca5a88c55..2a8ac541d5c69aa16095b09468ef9b89b9f8958e 100644 (file)
@@ -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