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.

IssuesModeBigTest.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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;
  21. import com.sonar.orchestrator.Orchestrator;
  22. import com.sonar.orchestrator.build.SonarScanner;
  23. import com.sonar.orchestrator.locator.FileLocation;
  24. import java.io.File;
  25. import java.io.IOException;
  26. import org.apache.commons.io.FileUtils;
  27. import org.apache.commons.lang.StringUtils;
  28. import org.junit.BeforeClass;
  29. import org.junit.ClassRule;
  30. import org.junit.Test;
  31. import org.junit.rules.TemporaryFolder;
  32. import org.sonarsource.sonarqube.perf.PerfTestCase;
  33. // Can't afford multiple executions of this long test, so it does not
  34. // use PerfRule
  35. public class IssuesModeBigTest extends PerfTestCase {
  36. @ClassRule
  37. public static TemporaryFolder temp = new TemporaryFolder();
  38. private static File baseProjectDir;
  39. @ClassRule
  40. public static final Orchestrator ORCHESTRATOR = Orchestrator
  41. .builderEnv()
  42. .addPlugin(FileLocation.byWildcardMavenFilename(new File("../../plugins/sonar-xoo-plugin/target"), "sonar-xoo-plugin-*.jar"))
  43. // should not be so high, but required as long embedded h2 is used -> requires more memory on server
  44. .setServerProperty("sonar.web.javaOpts", "-Xmx1G -XX:MaxPermSize=100m -XX:+HeapDumpOnOutOfMemoryError")
  45. .restoreProfileAtStartup(FileLocation.ofClasspath("/one-xoo-issue-per-line.xml"))
  46. .build();
  47. @BeforeClass
  48. public static void setUp() throws Exception {
  49. // Execute a first analysis to prevent any side effects with cache of plugin JAR files
  50. // ORCHESTRATOR.executeBuild(PerfTestCase.newScanner("-Xmx512m -server", "sonar.profile", "one-xoo-issue-per-line"));
  51. generateAndScanProject();
  52. }
  53. @Test
  54. public void issues_mode_scan_big_project() throws IOException {
  55. File userHome = temp.newFolder();
  56. SonarScanner scanner = createScanner();
  57. scanner.setProperty("sonar.analysis.mode", "issues");
  58. scanner.setProperty("sonar.scanAllFiles", "true");
  59. // Use a new home to start with empty cache
  60. scanner.setProperty("sonar.userHome", userHome.getAbsolutePath());
  61. long start = System.currentTimeMillis();
  62. ORCHESTRATOR.executeBuild(scanner);
  63. long firstIssuesDuration = System.currentTimeMillis() - start;
  64. System.out.println("First issues analysis skipping unchanged files: " + firstIssuesDuration + "ms");
  65. // caches are warmed
  66. start = System.currentTimeMillis();
  67. ORCHESTRATOR.executeBuild(scanner);
  68. long secondIssuesDuration = System.currentTimeMillis() - start;
  69. System.out.println("Second issues analysis skipping unchanged files: " + secondIssuesDuration + "ms");
  70. assertDurationAround(secondIssuesDuration, 109_000L);
  71. }
  72. @Test
  73. public void issues_mode_scan_big_project_only_changed() throws IOException {
  74. File userHome = temp.newFolder();
  75. SonarScanner scanner = createScanner();
  76. scanner.setProperty("sonar.analysis.mode", "issues");
  77. // Use a new home to start with empty cache
  78. scanner.setProperty("sonar.userHome", userHome.getAbsolutePath());
  79. long start = System.currentTimeMillis();
  80. ORCHESTRATOR.executeBuild(scanner);
  81. long firstIssuesDuration = System.currentTimeMillis() - start;
  82. System.out.println("First issues analysis: " + firstIssuesDuration + "ms");
  83. // caches are warmed
  84. start = System.currentTimeMillis();
  85. ORCHESTRATOR.executeBuild(scanner);
  86. long secondIssuesDuration = System.currentTimeMillis() - start;
  87. System.out.println("Second issues analysis: " + secondIssuesDuration + "ms");
  88. assertDurationAround(secondIssuesDuration, 69_000L);
  89. }
  90. private static void generateAndScanProject() throws IOException {
  91. ORCHESTRATOR.getServer().provisionProject("big", "xoo-big");
  92. ORCHESTRATOR.getServer().associateProjectToQualityProfile("big", "xoo", "one-xoo-issue-per-line");
  93. baseProjectDir = generateProject();
  94. SonarScanner scanner = createScanner();
  95. long start = System.currentTimeMillis();
  96. ORCHESTRATOR.executeBuild(scanner);
  97. long firstDuration = System.currentTimeMillis() - start;
  98. System.out.println("Publishing: " + firstDuration + "ms");
  99. }
  100. private static File generateProject() throws IOException {
  101. File baseDir = temp.newFolder();
  102. File srcDir = new File(baseDir, "src");
  103. srcDir.mkdir();
  104. int nbFiles = 100;
  105. int lines = 10000;
  106. for (int nb = 1; nb <= nbFiles; nb++) {
  107. File xooFile = new File(srcDir, "sample" + nb + ".xoo");
  108. FileUtils.write(xooFile, StringUtils.repeat(StringUtils.repeat("a", 100) + "\n", lines));
  109. }
  110. return baseDir;
  111. }
  112. private static SonarScanner createScanner() {
  113. SonarScanner scanner = SonarScanner.create()
  114. .setProperties(
  115. "sonar.projectKey", "big",
  116. "sonar.projectName", "xoo-big",
  117. "sonar.projectVersion", "1.0",
  118. "sonar.sources", "src",
  119. "sonar.showProfiling", "true");
  120. scanner
  121. .setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx128m -server -XX:MaxPermSize=64m")
  122. .setProjectDir(baseProjectDir);
  123. return scanner;
  124. }
  125. }