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.

FileSystemTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2016 SonarSource SA
  4. * mailto:contact 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.sonarsource.sonarqube.perf.scanner.suite;
  21. import com.sonar.orchestrator.Orchestrator;
  22. import com.sonar.orchestrator.build.SonarRunner;
  23. import org.sonarsource.sonarqube.perf.PerfRule;
  24. import org.sonarsource.sonarqube.perf.PerfTestCase;
  25. import java.io.File;
  26. import java.io.IOException;
  27. import java.util.Properties;
  28. import org.apache.commons.io.FileUtils;
  29. import org.apache.commons.lang.StringUtils;
  30. import org.junit.Before;
  31. import org.junit.BeforeClass;
  32. import org.junit.ClassRule;
  33. import org.junit.Rule;
  34. import org.junit.Test;
  35. import org.junit.rules.TemporaryFolder;
  36. public class FileSystemTest extends PerfTestCase {
  37. @Rule
  38. public PerfRule perfRule = new PerfRule(4) {
  39. @Override
  40. protected void beforeEachRun() {
  41. orchestrator.resetData();
  42. }
  43. };
  44. @ClassRule
  45. public static TemporaryFolder temp = new TemporaryFolder();
  46. @ClassRule
  47. public static Orchestrator orchestrator = ScannerPerfTestSuite.ORCHESTRATOR;
  48. private static File baseDir;
  49. @BeforeClass
  50. public static void setUp() throws IOException {
  51. // Execute a first analysis to prevent any side effects with cache of plugin JAR files
  52. orchestrator.executeBuild(newScanner("-Xmx512m -server", "sonar.profile", "one-xoo-issue-per-line"));
  53. baseDir = prepareProject();
  54. }
  55. @Before
  56. public void cleanDatabase() {
  57. orchestrator.resetData();
  58. }
  59. @Test
  60. public void indexProjectWith1000BigFilesXmx128() throws IOException {
  61. run(128, 30000L);
  62. }
  63. private void run(int xmx, long expectedDuration) throws IOException {
  64. SonarRunner runner = SonarRunner.create()
  65. .setProperties(
  66. "sonar.projectName", "filesystem xmx" + xmx,
  67. "sonar.projectVersion", "1.0",
  68. "sonar.sources", "src",
  69. "sonar.analysis.mode", "issues",
  70. "sonar.showProfiling", "true")
  71. .setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx" + xmx + "m -server -XX:MaxPermSize=64m")
  72. .setProjectDir(baseDir);
  73. orchestrator.executeBuild(runner);
  74. Properties prof = readProfiling(baseDir, "project");
  75. perfRule.assertDurationAround(Long.valueOf(prof.getProperty("Index filesystem")), expectedDuration);
  76. }
  77. private static File prepareProject() throws IOException {
  78. File baseDir = temp.newFolder();
  79. File srcDir = new File(baseDir, "src");
  80. srcDir.mkdir();
  81. int nbFiles = 1000;
  82. int lines = 10000;
  83. for (int nb = 1; nb <= nbFiles; nb++) {
  84. File xooFile = new File(srcDir, "sample" + nb + ".xoo");
  85. FileUtils.write(xooFile, StringUtils.repeat(StringUtils.repeat("a", 100) + "\n", lines));
  86. }
  87. return baseDir;
  88. }
  89. }