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
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;
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);
}
*/
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();
}
--- /dev/null
+/*
+ * 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;
+ }
+}
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() {
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;
+ }
+ }
}
--- /dev/null
+/*
+ * 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();
+ }
+}
+++ /dev/null
-/*
- * 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();
- }
-}