You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EsJvmOptionsTest.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.application.command;
  21. import java.io.File;
  22. import java.io.IOException;
  23. import org.junit.Rule;
  24. import org.junit.Test;
  25. import org.junit.rules.ExpectedException;
  26. import org.junit.rules.TemporaryFolder;
  27. import org.sonar.test.ExceptionCauseMatcher;
  28. import static org.assertj.core.api.Assertions.assertThat;
  29. public class EsJvmOptionsTest {
  30. @Rule
  31. public TemporaryFolder temporaryFolder = new TemporaryFolder();
  32. @Rule
  33. public ExpectedException expectedException = ExpectedException.none();
  34. @Test
  35. public void constructor_sets_mandatory_JVM_options() {
  36. EsJvmOptions underTest = new EsJvmOptions();
  37. assertThat(underTest.getAll()).containsExactly(
  38. "-XX:+UseConcMarkSweepGC",
  39. "-XX:CMSInitiatingOccupancyFraction=75",
  40. "-XX:+UseCMSInitiatingOccupancyOnly",
  41. "-XX:+AlwaysPreTouch",
  42. "-server",
  43. "-Xss1m",
  44. "-Djava.awt.headless=true",
  45. "-Dfile.encoding=UTF-8",
  46. "-Djna.nosys=true",
  47. "-Djdk.io.permissionsUseCanonicalPath=true",
  48. "-Dio.netty.noUnsafe=true",
  49. "-Dio.netty.noKeySetOptimization=true",
  50. "-Dio.netty.recycler.maxCapacityPerThread=0",
  51. "-Dlog4j.shutdownHookEnabled=false",
  52. "-Dlog4j2.disable.jmx=true",
  53. "-Dlog4j.skipJansi=true");
  54. }
  55. @Test
  56. public void writeToJvmOptionFile_writes_all_JVM_options_to_file_with_warning_header() throws IOException {
  57. File file = temporaryFolder.newFile();
  58. EsJvmOptions underTest = new EsJvmOptions()
  59. .add("-foo")
  60. .add("-bar");
  61. underTest.writeToJvmOptionFile(file);
  62. assertThat(file).hasContent(
  63. "# This file has been automatically generated by SonarQube during startup.\n" +
  64. "# Please use sonar.search.javaOpts and/or sonar.search.javaAdditionalOpts in sonar.properties to specify jvm options for Elasticsearch\n" +
  65. "\n" +
  66. "# DO NOT EDIT THIS FILE\n" +
  67. "\n" +
  68. "-XX:+UseConcMarkSweepGC\n" +
  69. "-XX:CMSInitiatingOccupancyFraction=75\n" +
  70. "-XX:+UseCMSInitiatingOccupancyOnly\n" +
  71. "-XX:+AlwaysPreTouch\n" +
  72. "-server\n" +
  73. "-Xss1m\n" +
  74. "-Djava.awt.headless=true\n" +
  75. "-Dfile.encoding=UTF-8\n" +
  76. "-Djna.nosys=true\n" +
  77. "-Djdk.io.permissionsUseCanonicalPath=true\n" +
  78. "-Dio.netty.noUnsafe=true\n" +
  79. "-Dio.netty.noKeySetOptimization=true\n" +
  80. "-Dio.netty.recycler.maxCapacityPerThread=0\n" +
  81. "-Dlog4j.shutdownHookEnabled=false\n" +
  82. "-Dlog4j2.disable.jmx=true\n" +
  83. "-Dlog4j.skipJansi=true\n" +
  84. "-foo\n" +
  85. "-bar");
  86. }
  87. @Test
  88. public void writeToJvmOptionFile_throws_ISE_in_case_of_IOException() throws IOException {
  89. File notAFile = temporaryFolder.newFolder();
  90. EsJvmOptions underTest = new EsJvmOptions();
  91. expectedException.expect(IllegalStateException.class);
  92. expectedException.expectMessage("Cannot write Elasticsearch jvm options file");
  93. expectedException.expectCause(ExceptionCauseMatcher.hasType(IOException.class));
  94. underTest.writeToJvmOptionFile(notAFile);
  95. }
  96. }