assertThat(logTester.logs(LoggerLevel.INFO)).contains("Waiting for Web Server to be operational...");
}
+ @Test
+ public void waitForOperational_returns_false_if_thread_is_interrupted() throws InterruptedException {
+ WaitingThread waitingThread = new WaitingThread(new CountDownLatch(1));
+ waitingThread.start();
+
+ assertThat(waitingThread.latch.await(50, MILLISECONDS)).isTrue();
+ waitingThread.interrupt();
+
+ assertThat(waitingThread.result).isFalse();
+ }
+
private void setWebServerOperational() {
try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(sharedDir, WEB_SERVER_PROCESS_NUMBER)) {
processCommands.setOperational();
}
}
+
+ private class WaitingThread extends Thread {
+ CountDownLatch latch;
+ boolean result = true;
+
+ public WaitingThread(CountDownLatch latch) {
+ this.latch = latch;
+ result = false;
+ }
+
+ @Override
+ public void run() {
+ latch.countDown();
+ this.result = underTest.waitForOperational();
+ }
+ }
}
public ServerSettingsImpl(PropertyDefinitions definitions, Properties rootProperties) {
super(definitions);
this.rootProperties = rootProperties;
- addProperties(rootProperties);
+ super.addProperties(rootProperties);
// Secret key is loaded from conf/sonar.properties
- getEncryption().setPathToSecretKey(getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
+ super.getEncryption().setPathToSecretKey(super.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
}
@Override
public ServerSettings activateDatabaseSettings(Map<String, String> databaseProperties) {
- clear();
+ super.clear();
// order is important : the last override the first
- addProperties(databaseProperties);
- addProperties(rootProperties);
+ super.addProperties(databaseProperties);
+ super.addProperties(rootProperties);
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.server.governance.bridge;
+
+import org.junit.Test;
+import org.sonar.api.platform.Server;
+import org.sonar.core.platform.ComponentContainer;
+import org.sonar.server.governance.GovernanceBridge;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+public class GovernanceBootstrapTest {
+ private Server server = mock(Server.class);
+ private ComponentContainer componentContainer = spy(new ComponentContainer());
+ private GovernanceBootstrap underTest = new GovernanceBootstrap(componentContainer);
+
+ @Test
+ public void onServerStart_has_no_effect_when_ComponentContainer_contains_no_GovernanceBridge() {
+ underTest.onServerStart(server);
+
+ verify(componentContainer).getComponentByType(GovernanceBridge.class);
+ verifyNoMoreInteractions(componentContainer);
+ }
+
+ @Test
+ public void onServerStart_calls_GovernanceBridge_startGovernance_when_present_in_ComponentContainer() {
+ GovernanceBridge governanceBridge = mock(GovernanceBridge.class);
+ componentContainer.add(governanceBridge);
+
+ underTest.onServerStart(server);
+
+ verify(governanceBridge).startGovernance(componentContainer);
+ }
+}
--- /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.server.governance.bridge;
+
+import org.junit.Test;
+import org.sonar.core.platform.ComponentContainer;
+import org.sonar.server.governance.GovernanceBridge;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+public class GovernanceStopperTest {
+ private ComponentContainer componentContainer = spy(new ComponentContainer());
+ private GovernanceStopper underTest = new GovernanceStopper(componentContainer);
+
+ @Test
+ public void start_has_no_effect() {
+ underTest.start();
+
+ verifyNoMoreInteractions(componentContainer);
+ }
+
+ @Test
+ public void stop_has_no_effect_when_no_GovernanceBridge() {
+ underTest.stop();
+
+ verify(componentContainer).getComponentByType(GovernanceBridge.class);
+ verifyNoMoreInteractions(componentContainer);
+ }
+
+ @Test
+ public void stop_calls_GovernanceBridge_stopGovernance_when_in_ComponentContainer() {
+ GovernanceBridge governanceBridge = mock(GovernanceBridge.class);
+
+ componentContainer.add(governanceBridge);
+
+ underTest.stop();
+
+ verify(governanceBridge).stopGovernance();
+ }
+}