diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-09-14 16:33:26 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-09-26 23:49:37 +0200 |
commit | 87ce833df2754dc1a23d29e56571ba826978b7bd (patch) | |
tree | 31c73987010443b47bdff75f5aeed1d05370d094 /server/sonar-process/src/test/java | |
parent | e3f8991bf2bb425f2829a4767a2d5fe6e3236c8c (diff) | |
download | sonarqube-87ce833df2754dc1a23d29e56571ba826978b7bd.tar.gz sonarqube-87ce833df2754dc1a23d29e56571ba826978b7bd.zip |
SONAR-9803 restrict sonar-process to classes shared by all processes only
Diffstat (limited to 'server/sonar-process/src/test/java')
12 files changed, 0 insertions, 1807 deletions
diff --git a/server/sonar-process/src/test/java/org/sonar/process/command/AbstractCommandTest.java b/server/sonar-process/src/test/java/org/sonar/process/command/AbstractCommandTest.java deleted file mode 100644 index dec2dde6008..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/command/AbstractCommandTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.command; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.Random; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.mockito.Mockito; -import org.sonar.process.ProcessId; -import org.sonar.process.System2; - -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - -public class AbstractCommandTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void constructor_throws_NPE_of_ProcessId_is_null() throws IOException { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("ProcessId can't be null"); - - new AbstractCommand<AbstractCommand>(null, temp.newFolder(), System2.INSTANCE) { - - }; - } - - @Test - public void constructor_throws_NPE_of_workDir_is_null() throws IOException { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("workDir can't be null"); - - new AbstractCommand<AbstractCommand>(ProcessId.WEB_SERVER, null, System2.INSTANCE) { - - }; - } - - @Test - public void test_command_with_complete_information() throws Exception { - File workDir = temp.newFolder(); - AbstractCommand command = new AbstractCommand(ProcessId.ELASTICSEARCH, workDir, System2.INSTANCE) { - - }; - - command.setArgument("first_arg", "val1"); - Properties args = new Properties(); - args.setProperty("second_arg", "val2"); - command.setArguments(args); - - command.setEnvVariable("JAVA_COMMAND_TEST", "1000"); - - assertThat(command.toString()).isNotNull(); - assertThat(command.getWorkDir()).isSameAs(workDir); - - // copy current env variables - assertThat(command.getEnvVariables().get("JAVA_COMMAND_TEST")).isEqualTo("1000"); - assertThat(command.getEnvVariables().size()).isEqualTo(System.getenv().size() + 1); - } - - @Test - public void setEnvVariable_fails_with_NPE_if_key_is_null() throws IOException { - File workDir = temp.newFolder(); - AbstractCommand underTest = new AbstractCommand(ProcessId.ELASTICSEARCH, workDir, System2.INSTANCE) { - - }; - - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("key can't be null"); - - underTest.setEnvVariable(null, randomAlphanumeric(30)); - } - - @Test - public void setEnvVariable_fails_with_NPE_if_value_is_null() throws IOException { - File workDir = temp.newFolder(); - AbstractCommand underTest = new AbstractCommand(ProcessId.ELASTICSEARCH, workDir, System2.INSTANCE) { - - }; - - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("value can't be null"); - - underTest.setEnvVariable(randomAlphanumeric(30), null); - } - - @Test - public void constructor_puts_System_getEnv_into_map_of_env_variables() throws IOException { - File workDir = temp.newFolder(); - System2 system2 = Mockito.mock(System2.class); - Map<String, String> env = IntStream.range(0, 1 + new Random().nextInt(99)).mapToObj(String::valueOf).collect(Collectors.toMap(i -> "key" + i, j -> "value" + j)); - when(system2.getenv()).thenReturn(env); - AbstractCommand underTest = new AbstractCommand(ProcessId.ELASTICSEARCH, workDir, system2) { - - }; - - assertThat(underTest.getEnvVariables()).isEqualTo(env); - } - - @Test - public void suppressEnvVariable_remove_existing_env_variable_and_add_variable_to_set_of_suppressed_variables() throws IOException { - File workDir = temp.newFolder(); - System2 system2 = Mockito.mock(System2.class); - Map<String, String> env = new HashMap<>(); - String key1 = randomAlphanumeric(3); - env.put(key1, randomAlphanumeric(9)); - when(system2.getenv()).thenReturn(env); - AbstractCommand underTest = new AbstractCommand(ProcessId.ELASTICSEARCH, workDir, system2) { - - }; - - underTest.suppressEnvVariable(key1); - - assertThat(underTest.getEnvVariables()).doesNotContainKey(key1); - assertThat(underTest.getSuppressedEnvVariables()).containsOnly(key1); - } - -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/command/CommandFactoryImplTest.java b/server/sonar-process/src/test/java/org/sonar/process/command/CommandFactoryImplTest.java deleted file mode 100644 index c6b2abc4e09..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/command/CommandFactoryImplTest.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.command; - -import ch.qos.logback.classic.spi.ILoggingEvent; -import java.io.File; -import java.io.IOException; -import java.util.Properties; -import org.apache.commons.io.FileUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.mockito.Mockito; -import org.sonar.process.ProcessId; -import org.sonar.process.ProcessProperties; -import org.sonar.process.Props; -import org.sonar.process.System2; -import org.sonar.process.logging.ListAppender; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.when; - -public class CommandFactoryImplTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - private File homeDir; - private File tempDir; - private File logsDir; - private ListAppender listAppender; - - @Before - public void setUp() throws Exception { - homeDir = temp.newFolder(); - tempDir = temp.newFolder(); - logsDir = temp.newFolder(); - } - - @After - public void tearDown() throws Exception { - if (listAppender != null) { - ListAppender.detachMemoryAppenderToLoggerOf(CommandFactoryImpl.class, listAppender); - } - } - - @Test - public void constructor_logs_no_warning_if_env_variable_JAVA_TOOL_OPTIONS_is_not_set() { - System2 system2 = Mockito.mock(System2.class); - when(system2.getenv(anyString())).thenReturn(null); - attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class); - - new CommandFactoryImpl(new Props(new Properties()), tempDir, system2); - - assertThat(listAppender.getLogs()).isEmpty(); - } - - @Test - public void constructor_logs_warning_if_env_variable_JAVA_TOOL_OPTIONS_is_set() { - System2 system2 = Mockito.mock(System2.class); - when(system2.getenv("JAVA_TOOL_OPTIONS")).thenReturn("sds"); - attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class); - - new CommandFactoryImpl(new Props(new Properties()), tempDir, system2); - - assertThat(listAppender.getLogs()) - .extracting(ILoggingEvent::getMessage) - .containsOnly( - "JAVA_TOOL_OPTIONS is defined but will be ignored. " + - "Use properties sonar.*.javaOpts and/or sonar.*.javaAdditionalOpts in sonar.properties to change SQ JVM processes options"); - } - - @Test - public void createEsCommand_throws_ISE_if_es_binary_is_not_found() throws Exception { - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Cannot find elasticsearch binary"); - - newFactory(new Properties()).createEsCommand(); - } - - @Test - public void createEsCommand_returns_command_for_default_settings() throws Exception { - prepareEsFileSystem(); - - Properties props = new Properties(); - props.setProperty("sonar.search.host", "localhost"); - - EsCommand esCommand = newFactory(props).createEsCommand(); - - assertThat(esCommand.getClusterName()).isEqualTo("sonarqube"); - assertThat(esCommand.getHost()).isNotEmpty(); - assertThat(esCommand.getPort()).isEqualTo(9001); - assertThat(esCommand.getEsJvmOptions().getAll()) - // enforced values - .contains("-XX:+UseConcMarkSweepGC", "-server", "-Dfile.encoding=UTF-8") - // default settings - .contains("-Xms512m", "-Xmx512m", "-XX:+HeapDumpOnOutOfMemoryError"); - File esConfDir = new File(tempDir, "conf/es"); - assertThat(esCommand.getEsOptions()).containsOnly("-Epath.conf=" + esConfDir.getAbsolutePath()); - assertThat(esCommand.getEnvVariables()) - .contains(entry("ES_JVM_OPTIONS", new File(esConfDir, "jvm.options").getAbsolutePath())) - .containsKey("JAVA_HOME"); - assertThat(esCommand.getEsYmlSettings()).isNotNull(); - - assertThat(esCommand.getLog4j2Properties()) - .contains(entry("appender.file_es.fileName", new File(logsDir, "es.log").getAbsolutePath())); - - assertThat(esCommand.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS"); - } - - @Test - public void createEsCommand_returns_command_for_overridden_settings() throws Exception { - prepareEsFileSystem(); - - Properties props = new Properties(); - props.setProperty("sonar.search.host", "localhost"); - props.setProperty("sonar.cluster.name", "foo"); - props.setProperty("sonar.search.port", "1234"); - props.setProperty("sonar.search.javaOpts", "-Xms10G -Xmx10G"); - - EsCommand command = newFactory(props).createEsCommand(); - - assertThat(command.getClusterName()).isEqualTo("foo"); - assertThat(command.getPort()).isEqualTo(1234); - assertThat(command.getEsJvmOptions().getAll()) - // enforced values - .contains("-XX:+UseConcMarkSweepGC", "-server", "-Dfile.encoding=UTF-8") - // user settings - .contains("-Xms10G", "-Xmx10G") - // default values disabled - .doesNotContain("-XX:+HeapDumpOnOutOfMemoryError"); - } - - @Test - public void createWebCommand_returns_command_for_default_settings() throws Exception { - JavaCommand command = newFactory(new Properties()).createWebCommand(true); - - assertThat(command.getClassName()).isEqualTo("org.sonar.server.app.WebServer"); - assertThat(command.getWorkDir().getAbsolutePath()).isEqualTo(homeDir.getAbsolutePath()); - assertThat(command.getClasspath()) - .containsExactlyInAnyOrder("./lib/common/*", "./lib/server/*"); - assertThat(command.getJvmOptions().getAll()) - // enforced values - .contains("-Djava.awt.headless=true", "-Dfile.encoding=UTF-8") - // default settings - .contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath(), "-Dfile.encoding=UTF-8") - .contains("-Xmx512m", "-Xms128m", "-XX:+HeapDumpOnOutOfMemoryError"); - assertThat(command.getProcessId()).isEqualTo(ProcessId.WEB_SERVER); - assertThat(command.getEnvVariables()) - .containsKey("JAVA_HOME"); - assertThat(command.getArguments()) - // default settings - .contains(entry("sonar.web.javaOpts", "-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError")) - .contains(entry("sonar.cluster.enabled", "false")); - - assertThat(command.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS"); - } - - @Test - public void createWebCommand_configures_command_with_overridden_settings() throws Exception { - Properties props = new Properties(); - props.setProperty("sonar.web.port", "1234"); - props.setProperty("sonar.web.javaOpts", "-Xmx10G"); - JavaCommand command = newFactory(props).createWebCommand(true); - - assertThat(command.getJvmOptions().getAll()) - // enforced values - .contains("-Djava.awt.headless=true", "-Dfile.encoding=UTF-8") - // default settings - .contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath(), "-Dfile.encoding=UTF-8") - // overridden values - .contains("-Xmx10G") - .doesNotContain("-Xms128m", "-XX:+HeapDumpOnOutOfMemoryError"); - assertThat(command.getArguments()) - // default settings - .contains(entry("sonar.web.javaOpts", "-Xmx10G")) - .contains(entry("sonar.cluster.enabled", "false")); - - assertThat(command.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS"); - } - - @Test - public void createWebCommand_adds_configured_jdbc_driver_to_classpath() throws Exception { - Properties props = new Properties(); - File driverFile = temp.newFile(); - props.setProperty("sonar.jdbc.driverPath", driverFile.getAbsolutePath()); - - JavaCommand command = newFactory(props).createWebCommand(true); - - assertThat(command.getClasspath()) - .containsExactlyInAnyOrder("./lib/common/*", "./lib/server/*", driverFile.getAbsolutePath()); - } - - private void prepareEsFileSystem() throws IOException { - FileUtils.touch(new File(homeDir, "elasticsearch/bin/elasticsearch")); - FileUtils.touch(new File(homeDir, "elasticsearch/bin/elasticsearch.bat")); - } - - private CommandFactory newFactory(Properties userProps) throws IOException { - Properties p = new Properties(); - p.setProperty("sonar.path.home", homeDir.getAbsolutePath()); - p.setProperty("sonar.path.temp", tempDir.getAbsolutePath()); - p.setProperty("sonar.path.logs", logsDir.getAbsolutePath()); - p.putAll(userProps); - - Props props = new Props(p); - ProcessProperties.completeDefaults(props); - return new CommandFactoryImpl(props, tempDir, System2.INSTANCE); - } - - private <T> void attachMemoryAppenderToLoggerOf(Class<T> loggerClass) { - this.listAppender = ListAppender.attachMemoryAppenderToLoggerOf(loggerClass); - } - -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/command/JavaCommandTest.java b/server/sonar-process/src/test/java/org/sonar/process/command/JavaCommandTest.java deleted file mode 100644 index dd0f71a677c..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/command/JavaCommandTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.command; - -import java.io.File; -import java.util.Properties; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.process.ProcessId; -import org.sonar.process.jmvoptions.JvmOptions; - -import static org.assertj.core.api.Assertions.assertThat; - -public class JavaCommandTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Test - public void test_command_with_complete_information() throws Exception { - File workDir = temp.newFolder(); - JavaCommand<JvmOptions> command = new JavaCommand<>(ProcessId.ELASTICSEARCH, workDir); - - command.setArgument("first_arg", "val1"); - Properties args = new Properties(); - args.setProperty("second_arg", "val2"); - command.setArguments(args); - - command.setClassName("org.sonar.ElasticSearch"); - command.setEnvVariable("JAVA_COMMAND_TEST", "1000"); - command.addClasspath("lib/*.jar"); - command.addClasspath("conf/*.xml"); - JvmOptions<JvmOptions> jvmOptions = new JvmOptions<JvmOptions>() {}; - command.setJvmOptions(jvmOptions); - - assertThat(command.toString()).isNotNull(); - assertThat(command.getClasspath()).containsOnly("lib/*.jar", "conf/*.xml"); - assertThat(command.getJvmOptions()).isSameAs(jvmOptions); - assertThat(command.getWorkDir()).isSameAs(workDir); - assertThat(command.getClassName()).isEqualTo("org.sonar.ElasticSearch"); - - // copy current env variables - assertThat(command.getEnvVariables().get("JAVA_COMMAND_TEST")).isEqualTo("1000"); - assertThat(command.getEnvVariables().size()).isEqualTo(System.getenv().size() + 1); - } - -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/es/EsFileSystemTest.java b/server/sonar-process/src/test/java/org/sonar/process/es/EsFileSystemTest.java deleted file mode 100644 index d3d10693656..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/es/EsFileSystemTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.es; - -import java.io.File; -import java.io.IOException; -import java.util.Properties; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.sonar.process.ProcessProperties; -import org.sonar.process.Props; - -import static org.assertj.core.api.Assertions.assertThat; - -public class EsFileSystemTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void constructor_fails_with_IAE_if_sq_home_property_is_not_defined() { - Props props = new Props(new Properties()); - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Property sonar.path.home is not set"); - - new EsFileSystem(props); - } - - @Test - public void constructor_fails_with_IAE_if_temp_dir_property_is_not_defined() throws IOException { - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Property sonar.path.temp is not set"); - - new EsFileSystem(props); - } - - @Test - public void getHomeDirectory_is_elasticsearch_subdirectory_of_sq_home_directory() throws IOException { - File sqHomeDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, sqHomeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - - EsFileSystem underTest = new EsFileSystem(props); - - assertThat(underTest.getHomeDirectory()).isEqualTo(new File(sqHomeDir, "elasticsearch")); - } - - @Test - public void getDataDirectory_is_data_es_subdirectory_of_sq_home_directory_by_default() throws IOException { - File sqHomeDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, sqHomeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - - EsFileSystem underTest = new EsFileSystem(props); - - assertThat(underTest.getDataDirectory()).isEqualTo(new File(sqHomeDir, "data/es")); - } - - @Test - public void override_data_dir() throws Exception { - File sqHomeDir = temp.newFolder(); - File tempDir = temp.newFolder(); - File dataDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, sqHomeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - - props.set(ProcessProperties.PATH_DATA, dataDir.getAbsolutePath()); - - EsFileSystem underTest = new EsFileSystem(props); - - assertThat(underTest.getDataDirectory()).isEqualTo(new File(dataDir, "es")); - } - - @Test - public void getLogDirectory_is_configured_with_non_nullable_PATH_LOG_variable() throws IOException { - File sqHomeDir = temp.newFolder(); - File logDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, sqHomeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, logDir.getAbsolutePath()); - - EsFileSystem underTest = new EsFileSystem(props); - - assertThat(underTest.getLogDirectory()).isEqualTo(logDir); - } - - @Test - public void conf_directory_is_conf_es_subdirectory_of_sq_temp_directory() throws IOException { - File tempDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - - EsFileSystem underTest = new EsFileSystem(props); - - assertThat(underTest.getConfDirectory()).isEqualTo(new File(tempDir, "conf/es")); - } - - @Test - public void getExecutable_resolve_executable_for_platform() throws IOException { - File sqHomeDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, sqHomeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - - EsFileSystem underTest = new EsFileSystem(props); - - if (System.getProperty("os.name").startsWith("Windows")) { - assertThat(underTest.getExecutable()).isEqualTo(new File(sqHomeDir, "elasticsearch/bin/elasticsearch.bat")); - } else { - assertThat(underTest.getExecutable()).isEqualTo(new File(sqHomeDir, "elasticsearch/bin/elasticsearch")); - } - } - - @Test - public void getLog4j2Properties_is_in_es_conf_directory() throws IOException { - File tempDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - - EsFileSystem underTest = new EsFileSystem(props); - - assertThat(underTest.getLog4j2Properties()).isEqualTo(new File(tempDir, "conf/es/log4j2.properties")); - } - - @Test - public void getElasticsearchYml_is_in_es_conf_directory() throws IOException { - File tempDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - - EsFileSystem underTest = new EsFileSystem(props); - - assertThat(underTest.getElasticsearchYml()).isEqualTo(new File(tempDir, "conf/es/elasticsearch.yml")); - } - - @Test - public void getJvmOptions_is_in_es_conf_directory() throws IOException { - File tempDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, tempDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - - EsFileSystem underTest = new EsFileSystem(props); - - assertThat(underTest.getJvmOptions()).isEqualTo(new File(tempDir, "conf/es/jvm.options")); - } -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/es/EsLoggingTest.java b/server/sonar-process/src/test/java/org/sonar/process/es/EsLoggingTest.java deleted file mode 100644 index 4f511ef2260..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/es/EsLoggingTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.es; - -import java.io.File; -import java.io.IOException; -import java.util.HashSet; -import java.util.Properties; -import java.util.Set; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonar.process.Props; -import org.sonar.process.es.EsLogging; - -import static org.assertj.core.api.Assertions.assertThat; - -public class EsLoggingTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - private EsLogging underTest = new EsLogging(); - - @Test - public void createProperties_with_empty_props() throws IOException { - File logDir = temporaryFolder.newFolder(); - Properties properties = underTest.createProperties(newProps(), logDir); - - verifyProperties(properties, - "status", "ERROR", - "appender.file_es.type", "RollingFile", - "appender.file_es.name", "file_es", - "appender.file_es.filePattern", new File(logDir, "es.%d{yyyy-MM-dd}.log").getAbsolutePath(), - "appender.file_es.fileName", new File(logDir, "es.log").getAbsolutePath(), - "appender.file_es.layout.type", "PatternLayout", - "appender.file_es.layout.pattern", "%d{yyyy.MM.dd HH:mm:ss} %-5level es[][%logger{1.}] %msg%n", - "appender.file_es.policies.type", "Policies", - "appender.file_es.policies.time.type", "TimeBasedTriggeringPolicy", - "appender.file_es.policies.time.interval", "1", - "appender.file_es.policies.time.modulate", "true", - "appender.file_es.strategy.type", "DefaultRolloverStrategy", - "appender.file_es.strategy.fileIndex", "nomax", - "appender.file_es.strategy.action.type", "Delete", - "appender.file_es.strategy.action.basepath", logDir.getAbsolutePath(), - "appender.file_es.strategy.action.maxDepth", "1", - "appender.file_es.strategy.action.condition.type", "IfFileName", - "appender.file_es.strategy.action.condition.glob", "es*", - "appender.file_es.strategy.action.condition.nested_condition.type", "IfAccumulatedFileCount", - "appender.file_es.strategy.action.condition.nested_condition.exceeds", "7", - "rootLogger.level", "INFO", - "rootLogger.appenderRef.file_es.ref", "file_es"); - } - - @Test - public void createProperties_sets_root_logger_to_INFO_if_no_property_is_set() throws IOException { - File logDir = temporaryFolder.newFolder(); - Properties properties = underTest.createProperties(newProps(), logDir); - - assertThat(properties.getProperty("rootLogger.level")).isEqualTo("INFO"); - } - - @Test - public void createProperties_sets_root_logger_to_global_property_if_set() throws IOException { - File logDir = temporaryFolder.newFolder(); - Properties properties = underTest.createProperties(newProps("sonar.log.level", "TRACE"), logDir); - - assertThat(properties.getProperty("rootLogger.level")).isEqualTo("TRACE"); - } - - @Test - public void createProperties_sets_root_logger_to_process_property_if_set() throws IOException { - File logDir = temporaryFolder.newFolder(); - Properties properties = underTest.createProperties(newProps("sonar.log.level.es", "DEBUG"), logDir); - - assertThat(properties.getProperty("rootLogger.level")).isEqualTo("DEBUG"); - } - - @Test - public void createProperties_sets_root_logger_to_process_property_over_global_property_if_both_set() throws IOException { - File logDir = temporaryFolder.newFolder(); - Properties properties = underTest.createProperties( - newProps( - "sonar.log.level", "DEBUG", - "sonar.log.level.es", "TRACE"), - logDir); - - assertThat(properties.getProperty("rootLogger.level")).isEqualTo("TRACE"); - } - - private static Props newProps(String... propertyKeysAndValues) { - assertThat(propertyKeysAndValues.length % 2).describedAs("Number of parameters must be even").isEqualTo(0); - Properties properties = new Properties(); - for (int i = 0; i < propertyKeysAndValues.length; i++) { - properties.put(propertyKeysAndValues[i++], propertyKeysAndValues[i]); - } - return new Props(properties); - } - - private void verifyProperties(Properties properties, String... expectedPropertyKeysAndValuesOrdered) { - if (expectedPropertyKeysAndValuesOrdered.length == 0) { - assertThat(properties.size()).isEqualTo(0); - } else { - assertThat(expectedPropertyKeysAndValuesOrdered.length % 2).describedAs("Number of parameters must be even").isEqualTo(0); - Set<String> keys = new HashSet<>(expectedPropertyKeysAndValuesOrdered.length / 2 + 1); - keys.add("status"); - for (int i = 0; i < expectedPropertyKeysAndValuesOrdered.length; i++) { - String key = expectedPropertyKeysAndValuesOrdered[i++]; - String value = expectedPropertyKeysAndValuesOrdered[i]; - assertThat(properties.get(key)).describedAs("Unexpected value for property " + key).isEqualTo(value); - keys.add(key); - } - assertThat(properties.keySet()).containsOnly(keys.toArray()); - } - } -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java b/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java deleted file mode 100644 index d8bc647ae7c..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/es/EsSettingsTest.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.es; - -import ch.qos.logback.classic.spi.ILoggingEvent; -import java.io.File; -import java.io.IOException; -import java.util.Map; -import java.util.Properties; -import java.util.Random; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.sonar.cluster.ClusterProperties; -import org.sonar.process.ProcessProperties; -import org.sonar.process.Props; -import org.sonar.process.System2; -import org.sonar.process.logging.ListAppender; - -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.sonar.cluster.ClusterProperties.CLUSTER_NAME; -import static org.sonar.cluster.ClusterProperties.CLUSTER_SEARCH_HOSTS; - -public class EsSettingsTest { - - private static final boolean CLUSTER_ENABLED = true; - private static final boolean CLUSTER_DISABLED = false; - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - private ListAppender listAppender; - - @After - public void tearDown() throws Exception { - if (listAppender != null) { - ListAppender.detachMemoryAppenderToLoggerOf(EsSettings.class, listAppender); - } - } - - @Test - public void constructor_does_not_logs_warning_if_env_variable_ES_JVM_OPTIONS_is_not_set() { - this.listAppender = ListAppender.attachMemoryAppenderToLoggerOf(EsSettings.class); - Props props = minimalProps(); - System2 system2 = mock(System2.class); - new EsSettings(props, new EsFileSystem(props), system2); - - assertThat(listAppender.getLogs()).isEmpty(); - } - - @Test - public void constructor_does_not_logs_warning_if_env_variable_ES_JVM_OPTIONS_is_set_and_empty() { - this.listAppender = ListAppender.attachMemoryAppenderToLoggerOf(EsSettings.class); - Props props = minimalProps(); - System2 system2 = mock(System2.class); - when(system2.getenv("ES_JVM_OPTIONS")).thenReturn(" "); - new EsSettings(props, new EsFileSystem(props), system2); - - assertThat(listAppender.getLogs()).isEmpty(); - } - - @Test - public void constructor_logs_warning_if_env_variable_ES_JVM_OPTIONS_is_set_and_non_empty() throws IOException { - this.listAppender = ListAppender.attachMemoryAppenderToLoggerOf(EsSettings.class); - Props props = minimalProps(); - System2 system2 = mock(System2.class); - when(system2.getenv("ES_JVM_OPTIONS")).thenReturn(randomAlphanumeric(2)); - new EsSettings(props, new EsFileSystem(props), system2); - - assertThat(listAppender.getLogs()) - .extracting(ILoggingEvent::getMessage) - .containsOnly("ES_JVM_OPTIONS is defined but will be ignored. " + - "Use sonar.search.javaOpts and/or sonar.search.javaAdditionalOpts in sonar.properties to specify jvm options for Elasticsearch"); - } - - private Props minimalProps() { - Props props = new Props(new Properties()); - props.set(ProcessProperties.PATH_HOME, randomAlphanumeric(12)); - props.set(ProcessProperties.PATH_TEMP, randomAlphanumeric(12)); - props.set(ProcessProperties.PATH_LOGS, randomAlphanumeric(12)); - props.set(CLUSTER_NAME, randomAlphanumeric(12)); - return props; - } - - @Test - public void test_default_settings_for_standalone_mode() throws Exception { - File homeDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.SEARCH_PORT, "1234"); - props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1"); - props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - props.set(CLUSTER_NAME, "sonarqube"); - - EsSettings esSettings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE); - - Map<String, String> generated = esSettings.build(); - assertThat(generated.get("transport.tcp.port")).isEqualTo("1234"); - assertThat(generated.get("transport.host")).isEqualTo("127.0.0.1"); - - // no cluster, but cluster and node names are set though - assertThat(generated.get("cluster.name")).isEqualTo("sonarqube"); - assertThat(generated.get("node.name")).isEqualTo("sonarqube"); - - assertThat(generated.get("path.data")).isNotNull(); - assertThat(generated.get("path.logs")).isNotNull(); - assertThat(generated.get("path.home")).isNull(); - assertThat(generated.get("path.conf")).isNotNull(); - - // http is disabled for security reasons - assertThat(generated.get("http.enabled")).isEqualTo("false"); - - assertThat(generated.get("discovery.zen.ping.unicast.hosts")).isNull(); - assertThat(generated.get("discovery.zen.minimum_master_nodes")).isEqualTo("1"); - assertThat(generated.get("discovery.initial_state_timeout")).isEqualTo("30s"); - - assertThat(generated.get("action.auto_create_index")).isEqualTo("false"); - } - - @Test - public void test_default_settings_for_cluster_mode() throws Exception { - File homeDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ProcessProperties.SEARCH_PORT, "1234"); - props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1"); - props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - props.set(ClusterProperties.CLUSTER_NAME, "sonarqube-1"); - props.set(ClusterProperties.CLUSTER_ENABLED, "true"); - props.set(ClusterProperties.CLUSTER_NODE_NAME, "node-1"); - - EsSettings esSettings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE); - - Map<String, String> generated = esSettings.build(); - assertThat(generated.get("cluster.name")).isEqualTo("sonarqube-1"); - assertThat(generated.get("node.name")).isEqualTo("node-1"); - } - - @Test - public void test_node_name_default_for_cluster_mode() throws Exception { - File homeDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ClusterProperties.CLUSTER_NAME, "sonarqube"); - props.set(ClusterProperties.CLUSTER_ENABLED, "true"); - props.set(ProcessProperties.SEARCH_PORT, "1234"); - props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1"); - props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - EsSettings esSettings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE); - Map<String, String> generated = esSettings.build(); - assertThat(generated.get("node.name")).startsWith("sonarqube-"); - } - - @Test - public void test_node_name_default_for_standalone_mode() throws Exception { - File homeDir = temp.newFolder(); - Props props = new Props(new Properties()); - props.set(ClusterProperties.CLUSTER_NAME, "sonarqube"); - props.set(ClusterProperties.CLUSTER_ENABLED, "false"); - props.set(ProcessProperties.SEARCH_PORT, "1234"); - props.set(ProcessProperties.SEARCH_HOST, "127.0.0.1"); - props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ProcessProperties.PATH_TEMP, temp.newFolder().getAbsolutePath()); - props.set(ProcessProperties.PATH_LOGS, temp.newFolder().getAbsolutePath()); - EsSettings esSettings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE); - Map<String, String> generated = esSettings.build(); - assertThat(generated.get("node.name")).isEqualTo("sonarqube"); - } - - @Test - public void path_properties_are_values_from_EsFileSystem_argument() throws IOException { - EsFileSystem mockedEsFileSystem = mock(EsFileSystem.class); - when(mockedEsFileSystem.getHomeDirectory()).thenReturn(new File("/foo/home")); - when(mockedEsFileSystem.getConfDirectory()).thenReturn(new File("/foo/conf")); - when(mockedEsFileSystem.getLogDirectory()).thenReturn(new File("/foo/log")); - when(mockedEsFileSystem.getDataDirectory()).thenReturn(new File("/foo/data")); - - EsSettings underTest = new EsSettings(minProps(new Random().nextBoolean()), mockedEsFileSystem, System2.INSTANCE); - - Map<String, String> generated = underTest.build(); - assertThat(generated.get("path.data")).isEqualTo("/foo/data"); - assertThat(generated.get("path.logs")).isEqualTo("/foo/log"); - assertThat(generated.get("path.conf")).isEqualTo("/foo/conf"); - } - - @Test - public void set_discovery_settings_if_cluster_is_enabled() throws Exception { - Props props = minProps(CLUSTER_ENABLED); - props.set(CLUSTER_SEARCH_HOSTS, "1.2.3.4:9000,1.2.3.5:8080"); - Map<String, String> settings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE).build(); - - assertThat(settings.get("discovery.zen.ping.unicast.hosts")).isEqualTo("1.2.3.4:9000,1.2.3.5:8080"); - assertThat(settings.get("discovery.zen.minimum_master_nodes")).isEqualTo("2"); - assertThat(settings.get("discovery.initial_state_timeout")).isEqualTo("120s"); - } - - @Test - public void incorrect_values_of_minimum_master_nodes() throws Exception { - Props props = minProps(CLUSTER_ENABLED); - props.set(ProcessProperties.SEARCH_MINIMUM_MASTER_NODES, "ꝱꝲꝳପ"); - - EsSettings underTest = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE); - - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Value of property sonar.search.minimumMasterNodes is not an integer:"); - underTest.build(); - } - - @Test - public void cluster_is_enabled_with_defined_minimum_master_nodes() throws Exception { - Props props = minProps(CLUSTER_ENABLED); - props.set(ProcessProperties.SEARCH_MINIMUM_MASTER_NODES, "5"); - Map<String, String> settings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE).build(); - - assertThat(settings.get("discovery.zen.minimum_master_nodes")).isEqualTo("5"); - } - - @Test - public void cluster_is_enabled_with_defined_initialTimeout() throws Exception { - Props props = minProps(CLUSTER_ENABLED); - props.set(ProcessProperties.SEARCH_INITIAL_STATE_TIMEOUT, "10s"); - Map<String, String> settings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE).build(); - - assertThat(settings.get("discovery.initial_state_timeout")).isEqualTo("10s"); - } - - @Test - public void in_standalone_initialTimeout_is_not_overridable() throws Exception { - Props props = minProps(CLUSTER_DISABLED); - props.set(ProcessProperties.SEARCH_INITIAL_STATE_TIMEOUT, "10s"); - Map<String, String> settings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE).build(); - - assertThat(settings.get("discovery.initial_state_timeout")).isEqualTo("30s"); - } - - @Test - public void in_standalone_minimumMasterNodes_is_not_overridable() throws Exception { - Props props = minProps(CLUSTER_DISABLED); - props.set(ProcessProperties.SEARCH_MINIMUM_MASTER_NODES, "5"); - Map<String, String> settings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE).build(); - - assertThat(settings.get("discovery.zen.minimum_master_nodes")).isEqualTo("1"); - } - - @Test - public void enable_http_connector() throws Exception { - Props props = minProps(CLUSTER_DISABLED); - props.set(ProcessProperties.SEARCH_HTTP_PORT, "9010"); - Map<String, String> settings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE).build(); - - assertThat(settings.get("http.port")).isEqualTo("9010"); - assertThat(settings.get("http.host")).isEqualTo("127.0.0.1"); - assertThat(settings.get("http.enabled")).isEqualTo("true"); - } - - @Test - public void enable_http_connector_different_host() throws Exception { - Props props = minProps(CLUSTER_DISABLED); - props.set(ProcessProperties.SEARCH_HTTP_PORT, "9010"); - props.set(ProcessProperties.SEARCH_HOST, "127.0.0.2"); - Map<String, String> settings = new EsSettings(props, new EsFileSystem(props), System2.INSTANCE).build(); - - assertThat(settings.get("http.port")).isEqualTo("9010"); - assertThat(settings.get("http.host")).isEqualTo("127.0.0.2"); - assertThat(settings.get("http.enabled")).isEqualTo("true"); - } - - private Props minProps(boolean cluster) throws IOException { - File homeDir = temp.newFolder(); - Props props = new Props(new Properties()); - ProcessProperties.completeDefaults(props); - props.set(ProcessProperties.PATH_HOME, homeDir.getAbsolutePath()); - props.set(ClusterProperties.CLUSTER_ENABLED, Boolean.toString(cluster)); - return props; - } -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/es/EsYmlSettingsTest.java b/server/sonar-process/src/test/java/org/sonar/process/es/EsYmlSettingsTest.java deleted file mode 100644 index 0fd6dc82544..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/es/EsYmlSettingsTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.sonar.process.es;/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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. - */ - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; - -import static org.assertj.core.api.Assertions.assertThat; - -public class EsYmlSettingsTest { - - @Rule - public TemporaryFolder folder= new TemporaryFolder(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void test_generation_of_file() throws IOException { - File yamlFile = folder.newFile(); - new EsYmlSettings(new HashMap<>()).writeToYmlSettingsFile(yamlFile); - - assertThat(yamlFile).exists(); - assertThat(yamlFile).hasContent("# This file has been automatically generated by SonarQube during startup.\n" + - "\n" + - "# DO NOT EDIT THIS FILE\n" + - "\n" + - "{\n" + - " }"); - } - - @Test - public void if_file_is_not_writable_ISE_must_be_thrown() throws IOException { - File yamlFile = folder.newFile(); - yamlFile.setReadOnly(); - - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Cannot write Elasticsearch yml settings file"); - - new EsYmlSettings(new HashMap<>()).writeToYmlSettingsFile(yamlFile); - } -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/CeJvmOptionsTest.java b/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/CeJvmOptionsTest.java deleted file mode 100644 index 3bd8bf37d91..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/CeJvmOptionsTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.jmvoptions; - -import java.io.File; -import java.io.IOException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import static org.assertj.core.api.Assertions.assertThat; - -public class CeJvmOptionsTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Test - public void constructor_sets_mandatory_JVM_options() throws IOException { - File tmpDir = temporaryFolder.newFolder(); - CeJvmOptions underTest = new CeJvmOptions(tmpDir); - - assertThat(underTest.getAll()).containsExactly( - "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath()); - } -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/EsJvmOptionsTest.java b/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/EsJvmOptionsTest.java deleted file mode 100644 index dd47b1100a6..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/EsJvmOptionsTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.jmvoptions; - -import java.io.File; -import java.io.IOException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.test.ExceptionCauseMatcher.hasType; - -public class EsJvmOptionsTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void constructor_sets_mandatory_JVM_options() { - EsJvmOptions underTest = new EsJvmOptions(); - - assertThat(underTest.getAll()).containsExactly( - "-XX:+UseConcMarkSweepGC", - "-XX:CMSInitiatingOccupancyFraction=75", - "-XX:+UseCMSInitiatingOccupancyOnly", - "-XX:+AlwaysPreTouch", - "-server", - "-Xss1m", - "-Djava.awt.headless=true", - "-Dfile.encoding=UTF-8", - "-Djna.nosys=true", - "-Djdk.io.permissionsUseCanonicalPath=true", - "-Dio.netty.noUnsafe=true", - "-Dio.netty.noKeySetOptimization=true", - "-Dio.netty.recycler.maxCapacityPerThread=0", - "-Dlog4j.shutdownHookEnabled=false", - "-Dlog4j2.disable.jmx=true", - "-Dlog4j.skipJansi=true"); - } - - @Test - public void writeToJvmOptionFile_writes_all_JVM_options_to_file_with_warning_header() throws IOException { - File file = temporaryFolder.newFile(); - EsJvmOptions underTest = new EsJvmOptions() - .add("-foo") - .add("-bar"); - - underTest.writeToJvmOptionFile(file); - - assertThat(file).hasContent( - "# This file has been automatically generated by SonarQube during startup.\n" + - "# Please use sonar.search.javaOpts and/or sonar.search.javaAdditionalOpts in sonar.properties to specify jvm options for Elasticsearch\n" + - "\n" + - "# DO NOT EDIT THIS FILE\n" + - "\n" + - "-XX:+UseConcMarkSweepGC\n" + - "-XX:CMSInitiatingOccupancyFraction=75\n" + - "-XX:+UseCMSInitiatingOccupancyOnly\n" + - "-XX:+AlwaysPreTouch\n" + - "-server\n" + - "-Xss1m\n" + - "-Djava.awt.headless=true\n" + - "-Dfile.encoding=UTF-8\n" + - "-Djna.nosys=true\n" + - "-Djdk.io.permissionsUseCanonicalPath=true\n" + - "-Dio.netty.noUnsafe=true\n" + - "-Dio.netty.noKeySetOptimization=true\n" + - "-Dio.netty.recycler.maxCapacityPerThread=0\n" + - "-Dlog4j.shutdownHookEnabled=false\n" + - "-Dlog4j2.disable.jmx=true\n" + - "-Dlog4j.skipJansi=true\n" + - "-foo\n" + - "-bar"); - - } - - @Test - public void writeToJvmOptionFile_throws_ISE_in_case_of_IOException() throws IOException { - File notAFile = temporaryFolder.newFolder(); - EsJvmOptions underTest = new EsJvmOptions(); - - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Cannot write Elasticsearch jvm options file"); - expectedException.expectCause(hasType(IOException.class)); - - underTest.writeToJvmOptionFile(notAFile); - } -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/JvmOptionsTest.java b/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/JvmOptionsTest.java deleted file mode 100644 index 35de8ef0b8c..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/JvmOptionsTest.java +++ /dev/null @@ -1,427 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.jmvoptions; - -import com.google.common.collect.ImmutableMap; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Properties; -import java.util.Random; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.sonar.process.MessageException; -import org.sonar.process.Props; - -import static java.lang.String.valueOf; -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -@RunWith(DataProviderRunner.class) -public class JvmOptionsTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private final Random random = new Random(); - private final String randomPropertyName = randomAlphanumeric(3); - private final String randomPrefix = "-" + randomAlphabetic(5).toLowerCase(Locale.ENGLISH); - private final String randomValue = randomAlphanumeric(4).toLowerCase(Locale.ENGLISH); - private final Properties properties = new Properties(); - private final JvmOptions underTest = new JvmOptions(); - - @Test - public void constructor_without_arguments_creates_empty_JvmOptions() { - JvmOptions<JvmOptions> testJvmOptions = new JvmOptions<>(); - - assertThat(testJvmOptions.getAll()).isEmpty(); - } - - @Test - public void constructor_throws_NPE_if_argument_is_null() { - expectJvmOptionNotNullNPE(); - - new JvmOptions(null); - } - - @Test - public void constructor_throws_NPE_if_any_option_prefix_is_null() { - Map<String, String> mandatoryJvmOptions = shuffleThenToMap( - Stream.of( - IntStream.range(0, random.nextInt(10)).mapToObj(i -> new Option("-B", valueOf(i))), - Stream.of(new Option(null, "value"))) - .flatMap(s -> s)); - - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("JVM option prefix can't be null"); - - new JvmOptions(mandatoryJvmOptions); - } - - @Test - @UseDataProvider("variousEmptyStrings") - public void constructor_throws_IAE_if_any_option_prefix_is_empty(String emptyString) { - Map<String, String> mandatoryJvmOptions = shuffleThenToMap( - Stream.of( - IntStream.range(0, random.nextInt(10)).mapToObj(i -> new Option("-B", valueOf(i))), - Stream.of(new Option(emptyString, "value"))) - .flatMap(s -> s)); - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("JVM option prefix can't be empty"); - - new JvmOptions(mandatoryJvmOptions); - } - - @Test - public void constructor_throws_IAE_if_any_option_prefix_does_not_start_with_dash() { - String invalidPrefix = randomAlphanumeric(3); - Map<String, String> mandatoryJvmOptions = shuffleThenToMap( - Stream.of( - IntStream.range(0, random.nextInt(10)).mapToObj(i -> new Option("-B", valueOf(i))), - Stream.of(new Option(invalidPrefix, "value"))) - .flatMap(s -> s)); - - expectJvmOptionNotEmptyAndStartByDashIAE(); - - new JvmOptions(mandatoryJvmOptions); - } - - @Test - public void constructor_throws_NPE_if_any_option_value_is_null() { - Map<String, String> mandatoryJvmOptions = shuffleThenToMap( - Stream.of( - IntStream.range(0, random.nextInt(10)).mapToObj(i -> new Option("-B", valueOf(i))), - Stream.of(new Option("-prefix", null))) - .flatMap(s -> s)); - - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("JVM option value can't be null"); - - new JvmOptions(mandatoryJvmOptions); - } - - @Test - @UseDataProvider("variousEmptyStrings") - public void constructor_accepts_any_empty_option_value(String emptyString) { - Map<String, String> mandatoryJvmOptions = shuffleThenToMap( - Stream.of( - IntStream.range(0, random.nextInt(10)).mapToObj(i -> new Option("-B", valueOf(i))), - Stream.of(new Option("-prefix", emptyString))) - .flatMap(s -> s)); - - new JvmOptions(mandatoryJvmOptions); - } - - @Test - public void add_throws_NPE_if_argument_is_null() { - expectJvmOptionNotNullNPE(); - - underTest.add(null); - } - - @Test - @UseDataProvider("variousEmptyStrings") - public void add_throws_IAE_if_argument_is_empty(String emptyString) { - expectJvmOptionNotEmptyAndStartByDashIAE(); - - underTest.add(emptyString); - } - - @Test - public void add_throws_IAE_if_argument_does_not_start_with_dash() { - expectJvmOptionNotEmptyAndStartByDashIAE(); - - underTest.add(randomAlphanumeric(3)); - } - - @Test - @UseDataProvider("variousEmptyStrings") - public void add_adds_with_trimming(String emptyString) { - underTest.add(emptyString + "-foo" + emptyString); - - assertThat(underTest.getAll()).containsOnly("-foo"); - } - - @Test - public void add_throws_MessageException_if_option_starts_with_prefix_of_mandatory_option_but_has_different_value() { - String[] optionOverrides = { - randomPrefix, - randomPrefix + randomAlphanumeric(1), - randomPrefix + randomAlphanumeric(2), - randomPrefix + randomAlphanumeric(3), - randomPrefix + randomAlphanumeric(4), - randomPrefix + randomValue.substring(1), - randomPrefix + randomValue.substring(2), - randomPrefix + randomValue.substring(3) - }; - - JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); - - for (String optionOverride : optionOverrides) { - try { - underTest.add(optionOverride); - fail("an MessageException should have been thrown"); - } catch (MessageException e) { - assertThat(e.getMessage()).isEqualTo("a JVM option can't overwrite mandatory JVM options. " + optionOverride + " overwrites " + randomPrefix + randomValue); - } - } - } - - @Test - public void add_checks_against_mandatory_options_is_case_sensitive() { - String[] optionOverrides = { - randomPrefix, - randomPrefix + randomAlphanumeric(1), - randomPrefix + randomAlphanumeric(2), - randomPrefix + randomAlphanumeric(3), - randomPrefix + randomAlphanumeric(4), - randomPrefix + randomValue.substring(1), - randomPrefix + randomValue.substring(2), - randomPrefix + randomValue.substring(3) - }; - - JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); - - for (String optionOverride : optionOverrides) { - underTest.add(optionOverride.toUpperCase(Locale.ENGLISH)); - } - } - - @Test - public void add_accepts_property_equal_to_mandatory_option_and_does_not_add_it_twice() { - JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); - - underTest.add(randomPrefix + randomValue); - - assertThat(underTest.getAll()).containsOnly(randomPrefix + randomValue); - } - - @Test - public void addFromMandatoryProperty_fails_with_IAE_if_property_does_not_exist() { - expectMissingPropertyIAE(this.randomPropertyName); - - underTest.addFromMandatoryProperty(new Props(properties), this.randomPropertyName); - } - - @Test - public void addFromMandatoryProperty_fails_with_IAE_if_property_contains_an_empty_value() { - expectMissingPropertyIAE(this.randomPropertyName); - - underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); - } - - @Test - @UseDataProvider("variousEmptyStrings") - public void addFromMandatoryProperty_adds_single_option_of_property_with_trimming(String emptyString) { - properties.put(randomPropertyName, emptyString + "-foo" + emptyString); - - underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); - - assertThat(underTest.getAll()).containsOnly("-foo"); - } - - @Test - @UseDataProvider("variousEmptyStrings") - public void addFromMandatoryProperty_fails_with_MessageException_if_property_does_not_start_with_dash_after_trimmed(String emptyString) { - properties.put(randomPropertyName, emptyString + "foo -bar"); - - expectJvmOptionNotEmptyAndStartByDashMessageException(randomPropertyName, "foo"); - - underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); - } - - @Test - @UseDataProvider("variousEmptyStrings") - public void addFromMandatoryProperty_adds_options_of_property_with_trimming(String emptyString) { - properties.put(randomPropertyName, emptyString + "-foo" + emptyString + " -bar" + emptyString + " -duck" + emptyString); - - underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); - - assertThat(underTest.getAll()).containsOnly("-foo", "-bar", "-duck"); - } - - @Test - public void addFromMandatoryProperty_supports_spaces_inside_options() { - properties.put(randomPropertyName, "-foo bar -duck"); - - underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); - - assertThat(underTest.getAll()).containsOnly("-foo bar", "-duck"); - } - - @Test - public void addFromMandatoryProperty_throws_IAE_if_option_starts_with_prefix_of_mandatory_option_but_has_different_value() { - String[] optionOverrides = { - randomPrefix, - randomPrefix + randomValue.substring(1), - randomPrefix + randomValue.substring(1), - randomPrefix + randomValue.substring(2), - randomPrefix + randomValue.substring(3), - randomPrefix + randomValue.substring(3) + randomAlphanumeric(1), - randomPrefix + randomValue.substring(3) + randomAlphanumeric(2), - randomPrefix + randomValue.substring(3) + randomAlphanumeric(3), - randomPrefix + randomValue + randomAlphanumeric(1) - }; - - JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); - - for (String optionOverride : optionOverrides) { - try { - properties.put(randomPropertyName, optionOverride); - underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); - fail("an MessageException should have been thrown"); - } catch (MessageException e) { - assertThat(e.getMessage()) - .isEqualTo("a JVM option can't overwrite mandatory JVM options. " + - "The following JVM options defined by property '" + randomPropertyName + "' are invalid: " + optionOverride + " overwrites " + randomPrefix + randomValue); - } - } - } - - @Test - public void addFromMandatoryProperty_checks_against_mandatory_options_is_case_sensitive() { - String[] optionOverrides = { - randomPrefix, - randomPrefix + randomValue.substring(1), - randomPrefix + randomValue.substring(1), - randomPrefix + randomValue.substring(2), - randomPrefix + randomValue.substring(3), - randomPrefix + randomValue.substring(3) + randomAlphanumeric(1), - randomPrefix + randomValue.substring(3) + randomAlphanumeric(2), - randomPrefix + randomValue.substring(3) + randomAlphanumeric(3), - randomPrefix + randomValue + randomAlphanumeric(1) - }; - - JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); - - for (String optionOverride : optionOverrides) { - properties.setProperty(randomPropertyName, optionOverride.toUpperCase(Locale.ENGLISH)); - underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); - } - } - - @Test - public void addFromMandatoryProperty_reports_all_overriding_options_in_single_exception() { - String overriding1 = randomPrefix; - String overriding2 = randomPrefix + randomValue + randomAlphanumeric(1); - properties.setProperty(randomPropertyName, "-foo " + overriding1 + " -bar " + overriding2); - - JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); - - expectedException.expect(MessageException.class); - expectedException.expectMessage("a JVM option can't overwrite mandatory JVM options. " + - "The following JVM options defined by property '" + randomPropertyName + "' are invalid: " + - overriding1 + " overwrites " + randomPrefix + randomValue + ", " + overriding2 + " overwrites " + randomPrefix + randomValue); - - underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); - } - - @Test - public void addFromMandatoryProperty_accepts_property_equal_to_mandatory_option_and_does_not_add_it_twice() { - JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); - - properties.put(randomPropertyName, randomPrefix + randomValue); - underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); - - assertThat(underTest.getAll()).containsOnly(randomPrefix + randomValue); - } - - @Test - public void toString_prints_all_jvm_options() { - underTest.add("-foo").add("-bar"); - - assertThat(underTest.toString()).isEqualTo("[-foo, -bar]"); - } - - private void expectJvmOptionNotNullNPE() { - expectedException.expect(NullPointerException.class); - expectedException.expectMessage("a JVM option can't be null"); - } - - private void expectJvmOptionNotEmptyAndStartByDashIAE() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("a JVM option can't be empty and must start with '-'"); - } - - private void expectJvmOptionNotEmptyAndStartByDashMessageException(String randomPropertyName, String option) { - expectedException.expect(MessageException.class); - expectedException.expectMessage("a JVM option can't be empty and must start with '-'. " + - "The following JVM options defined by property '" + randomPropertyName + "' are invalid: " + option); - } - - public void expectMissingPropertyIAE(String randomPropertyName) { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Missing property: " + randomPropertyName); - } - - @DataProvider() - public static Object[][] variousEmptyStrings() { - return new Object[][] { - {""}, - {" "}, - {" "} - }; - } - - private static Map<String, String> shuffleThenToMap(Stream<Option> stream) { - List<Option> options = stream.collect(Collectors.toList()); - Collections.shuffle(options); - Map<String, String> res = new HashMap<>(options.size()); - for (Option option : options) { - res.put(option.getPrefix(), option.getValue()); - } - return res; - } - - private static final class Option { - private final String prefix; - private final String value; - - private Option(String prefix, String value) { - this.prefix = prefix; - this.value = value; - } - - public String getPrefix() { - return prefix; - } - - public String getValue() { - return value; - } - - @Override - public String toString() { - return "[" + prefix + "-" + value + ']'; - } - } -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/WebJvmOptionsTest.java b/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/WebJvmOptionsTest.java deleted file mode 100644 index 9387a15b808..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/jmvoptions/WebJvmOptionsTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.jmvoptions; - -import java.io.File; -import java.io.IOException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import static org.assertj.core.api.Assertions.assertThat; - -public class WebJvmOptionsTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Test - public void constructor_sets_mandatory_JVM_options() throws IOException { - File tmpDir = temporaryFolder.newFolder(); - WebJvmOptions underTest = new WebJvmOptions(tmpDir); - - assertThat(underTest.getAll()).containsExactly( - "-Djava.awt.headless=true", "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=" + tmpDir.getAbsolutePath()); - } - -} diff --git a/server/sonar-process/src/test/java/org/sonar/process/logging/ListAppender.java b/server/sonar-process/src/test/java/org/sonar/process/logging/ListAppender.java deleted file mode 100644 index fec800706c2..00000000000 --- a/server/sonar-process/src/test/java/org/sonar/process/logging/ListAppender.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.process.logging; - -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.AppenderBase; -import java.util.ArrayList; -import java.util.List; - -public final class ListAppender extends AppenderBase<ILoggingEvent> { - private final List<ILoggingEvent> logs = new ArrayList<>(); - - @Override - protected void append(ILoggingEvent eventObject) { - logs.add(eventObject); - } - - public List<ILoggingEvent> getLogs() { - return logs; - } - - public static <T> ListAppender attachMemoryAppenderToLoggerOf(Class<T> loggerClass) { - ListAppender listAppender = new ListAppender(); - new LogbackHelper().getRootContext().getLogger(loggerClass) - .addAppender(listAppender); - listAppender.start(); - return listAppender; - } - - public static <T> void detachMemoryAppenderToLoggerOf(Class<T> loggerClass, ListAppender listAppender) { - listAppender.stop(); - new LogbackHelper().getRootContext().getLogger(loggerClass) - .detachAppender(listAppender); - } -} |