aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-03-11 13:55:00 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-03-21 16:44:04 +0100
commit22abf3da18b2a8f1db05414ca91fe042cbdc8dd4 (patch)
tree159c983810e99974122716a72107865e026d1cbe
parent3591ebf7197ad6704e9bf54f8e27cde8013988f7 (diff)
downloadsonarqube-22abf3da18b2a8f1db05414ca91fe042cbdc8dd4.tar.gz
sonarqube-22abf3da18b2a8f1db05414ca91fe042cbdc8dd4.zip
SONAR-6732 there should be no static binding but in CeServer.main
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/ComputeEngineImpl.java5
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java3
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainer.java32
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java57
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/ComputeEngineImplTest.java21
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java (renamed from server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerTest.java)15
6 files changed, 99 insertions, 34 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/ComputeEngineImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/ComputeEngineImpl.java
index 457139516d8..c6c594d23f3 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/ComputeEngineImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/ComputeEngineImpl.java
@@ -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
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java b/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
index 22abe03bf12..35aa35e56e5 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
@@ -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);
}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainer.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainer.java
index 2caedf8d998..c58317296ef 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainer.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainer.java
@@ -19,36 +19,12 @@
*/
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
index 00000000000..445c5f95c96
--- /dev/null
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
@@ -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;
+ }
+}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/ComputeEngineImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/ComputeEngineImplTest.java
index 530eab7eddb..697a8d68032 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/ComputeEngineImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/ComputeEngineImplTest.java
@@ -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/ComputeEngineContainerTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
index 8108ecadefa..bf42fa8a390 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
@@ -28,8 +28,10 @@ import org.sonar.process.Props;
import static org.assertj.core.api.Assertions.assertThat;
-public class ComputeEngineContainerTest {
- private ComputeEngineContainer underTest = new ComputeEngineContainer();
+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() {
@@ -49,6 +51,15 @@ public class ComputeEngineContainerTest {
}
@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();