]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6732 there should be no static binding but in CeServer.main
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 11 Mar 2016 12:55:00 +0000 (13:55 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 21 Mar 2016 15:44:04 +0000 (16:44 +0100)
server/sonar-ce/src/main/java/org/sonar/ce/ComputeEngineImpl.java
server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainer.java
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java [new file with mode: 0644]
server/sonar-ce/src/test/java/org/sonar/ce/ComputeEngineImplTest.java
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java [new file with mode: 0644]
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerTest.java [deleted file]

index 457139516d8b892c3b400c262a5c4f81d41a130a..c6c594d23f36be5f48c6c7cd54982232fe058ff9 100644 (file)
@@ -26,12 +26,13 @@ import static com.google.common.base.Preconditions.checkState;
 
 public class ComputeEngineImpl implements ComputeEngine {
   private final Props props;
-  private final ComputeEngineContainer computeEngineContainer = new ComputeEngineContainer();
+  private final ComputeEngineContainer computeEngineContainer;
 
   private Status status = Status.INIT;
 
-  public ComputeEngineImpl(Props props) {
+  public ComputeEngineImpl(Props props, ComputeEngineContainer computeEngineContainer) {
     this.props = props;
+    this.computeEngineContainer = computeEngineContainer;
   }
 
   @Override
index 22abe03bf1298ca32c4fc450ba5e8be5d6cb5fdd..35aa35e56e516c55c02101992a2ae183b63a00c7 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.ce.ComputeEngine;
 import org.sonar.ce.ComputeEngineImpl;
+import org.sonar.ce.container.ComputeEngineContainerImpl;
 import org.sonar.process.MinimumViableSystem;
 import org.sonar.process.Monitored;
 import org.sonar.process.ProcessEntryPoint;
@@ -76,7 +77,7 @@ public class CeServer implements Monitored {
     ProcessEntryPoint entryPoint = ProcessEntryPoint.createForArguments(args);
     Props props = entryPoint.getProps();
     new ServerProcessLogging(PROCESS_NAME, LOG_LEVEL_PROPERTY).configure(props);
-    CeServer server = new CeServer(new WebServerWatcherImpl(entryPoint.getSharedDir()), new ComputeEngineImpl(props));
+    CeServer server = new CeServer(new WebServerWatcherImpl(entryPoint.getSharedDir()), new ComputeEngineImpl(props, new ComputeEngineContainerImpl()));
     entryPoint.launch(server);
   }
 
index 2caedf8d998e27e5f925d23eb780b58ad0836a46..c58317296efb6b5e5f8caab758ff30140286a4f0 100644 (file)
  */
 package org.sonar.ce.container;
 
-import com.google.common.annotations.VisibleForTesting;
-import org.sonar.core.platform.ComponentContainer;
 import org.sonar.process.Props;
 
-public class ComputeEngineContainer {
-  private final ComponentContainer componentContainer;
+public interface ComputeEngineContainer {
+  ComputeEngineContainer configure(Props props);
 
-  public ComputeEngineContainer() {
-    this.componentContainer = new ComponentContainer();
-  }
+  ComputeEngineContainer start();
 
-  public ComputeEngineContainer configure(Props props) {
-    this.componentContainer.add(
-      props.rawProperties()
-      );
-    return this;
-  }
-
-  public ComputeEngineContainer start() {
-    this.componentContainer.startComponents();
-    return this;
-  }
-
-  public ComputeEngineContainer stop() {
-    this.componentContainer.stopComponents();
-    return this;
-  }
-
-  @VisibleForTesting
-  protected ComponentContainer getComponentContainer() {
-    return componentContainer;
-  }
+  ComputeEngineContainer stop();
 }
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
new file mode 100644 (file)
index 0000000..445c5f9
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.container;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.sonar.core.platform.ComponentContainer;
+import org.sonar.process.Props;
+
+public class ComputeEngineContainerImpl implements ComputeEngineContainer {
+  private final ComponentContainer componentContainer;
+
+  public ComputeEngineContainerImpl() {
+    this.componentContainer = new ComponentContainer();
+  }
+
+  @Override
+  public ComputeEngineContainer configure(Props props) {
+    this.componentContainer.add(
+      props.rawProperties()
+      );
+    return this;
+  }
+
+  @Override
+  public ComputeEngineContainer start() {
+    this.componentContainer.startComponents();
+    return this;
+  }
+
+  @Override
+  public ComputeEngineContainer stop() {
+    this.componentContainer.stopComponents();
+    return this;
+  }
+
+  @VisibleForTesting
+  protected ComponentContainer getComponentContainer() {
+    return componentContainer;
+  }
+}
index 530eab7eddb4290d9fbfe5f4c4ef7c030cdeed49..697a8d680320b243244d7ecdb68e7234b4ac2ce4 100644 (file)
@@ -23,13 +23,15 @@ import java.util.Properties;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.sonar.ce.container.ComputeEngineContainer;
 import org.sonar.process.Props;
 
 public class ComputeEngineImplTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private ComputeEngine underTest = new ComputeEngineImpl(new Props(new Properties()));
+  private ComputeEngineContainer computeEngineContainer = new NoOpComputeEngineContainer();
+  private ComputeEngine underTest = new ComputeEngineImpl(new Props(new Properties()), computeEngineContainer);
 
   @Test
   public void startup_throws_ISE_when_called_twice() {
@@ -59,4 +61,21 @@ public class ComputeEngineImplTest {
 
     underTest.shutdown();
   }
+
+  private static class NoOpComputeEngineContainer implements ComputeEngineContainer {
+    @Override
+    public ComputeEngineContainer configure(Props props) {
+      return this;
+    }
+
+    @Override
+    public ComputeEngineContainer start() {
+      return this;
+    }
+
+    @Override
+    public ComputeEngineContainer stop() {
+      return this;
+    }
+  }
 }
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
new file mode 100644 (file)
index 0000000..bf42fa8
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.container;
+
+import java.util.Properties;
+import org.junit.Test;
+import org.picocontainer.MutablePicoContainer;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.core.platform.ComponentContainer;
+import org.sonar.process.Props;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ComputeEngineContainerImplTest {
+  private static final int COMPONENTS_IN_CONTAINER_AT_CONSTRUCTION = 2;
+
+  private ComputeEngineContainerImpl underTest = new ComputeEngineContainerImpl();
+
+  @Test
+  public void constructor_adds_only_container_and_PropertyDefinitions() {
+    ComponentContainer componentContainer = underTest.getComponentContainer();
+
+    assertThat(componentContainer.getComponentsByType(Object.class)).hasSize(2);
+    assertThat(componentContainer.getComponentByType(PropertyDefinitions.class)).isNotNull();
+    assertThat(componentContainer.getComponentByType(ComponentContainer.class)).isSameAs(componentContainer);
+  }
+
+  @Test
+  public void configure_adds_raw_properties_from_Props_to_container() {
+    Properties properties = new Properties();
+    underTest.configure(new Props(properties));
+
+    assertThat(underTest.getComponentContainer().getComponentByType(Properties.class)).isSameAs(properties);
+  }
+
+  @Test
+  public void verify_number_of_components_in_container() {
+    Properties properties = new Properties();
+    underTest.configure(new Props(properties));
+
+    assertThat(underTest.getComponentContainer().getPicoContainer().getComponentAdapters())
+        .hasSize(COMPONENTS_IN_CONTAINER_AT_CONSTRUCTION + 1);
+  }
+
+  @Test
+  public void start_starts_pico_container() {
+    MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer();
+
+    assertThat(picoContainer.getLifecycleState().isStarted()).isFalse();
+
+    underTest.start();
+
+    assertThat(picoContainer.getLifecycleState().isStarted()).isTrue();
+  }
+
+  @Test
+  public void stop_stops_and_dispose_pico_container() {
+    MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer();
+
+    assertThat(picoContainer.getLifecycleState().isStarted()).isFalse();
+    assertThat(picoContainer.getLifecycleState().isStopped()).isFalse();
+
+    underTest.start();
+    underTest.stop();
+
+    assertThat(picoContainer.getLifecycleState().isStarted()).isFalse();
+    assertThat(picoContainer.getLifecycleState().isStopped()).isFalse();
+    assertThat(picoContainer.getLifecycleState().isDisposed()).isTrue();
+  }
+}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerTest.java
deleted file mode 100644 (file)
index 8108eca..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.container;
-
-import java.util.Properties;
-import org.junit.Test;
-import org.picocontainer.MutablePicoContainer;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.core.platform.ComponentContainer;
-import org.sonar.process.Props;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ComputeEngineContainerTest {
-  private ComputeEngineContainer underTest = new ComputeEngineContainer();
-
-  @Test
-  public void constructor_adds_only_container_and_PropertyDefinitions() {
-    ComponentContainer componentContainer = underTest.getComponentContainer();
-
-    assertThat(componentContainer.getComponentsByType(Object.class)).hasSize(2);
-    assertThat(componentContainer.getComponentByType(PropertyDefinitions.class)).isNotNull();
-    assertThat(componentContainer.getComponentByType(ComponentContainer.class)).isSameAs(componentContainer);
-  }
-
-  @Test
-  public void configure_adds_raw_properties_from_Props_to_container() {
-    Properties properties = new Properties();
-    underTest.configure(new Props(properties));
-
-    assertThat(underTest.getComponentContainer().getComponentByType(Properties.class)).isSameAs(properties);
-  }
-
-  @Test
-  public void start_starts_pico_container() {
-    MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer();
-
-    assertThat(picoContainer.getLifecycleState().isStarted()).isFalse();
-
-    underTest.start();
-
-    assertThat(picoContainer.getLifecycleState().isStarted()).isTrue();
-  }
-
-  @Test
-  public void stop_stops_and_dispose_pico_container() {
-    MutablePicoContainer picoContainer = underTest.getComponentContainer().getPicoContainer();
-
-    assertThat(picoContainer.getLifecycleState().isStarted()).isFalse();
-    assertThat(picoContainer.getLifecycleState().isStopped()).isFalse();
-
-    underTest.start();
-    underTest.stop();
-
-    assertThat(picoContainer.getLifecycleState().isStarted()).isFalse();
-    assertThat(picoContainer.getLifecycleState().isStopped()).isFalse();
-    assertThat(picoContainer.getLifecycleState().isDisposed()).isTrue();
-  }
-}