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.

WebTest.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.server;
  21. import com.github.kevinsawicki.http.HttpRequest;
  22. import com.sonar.orchestrator.Orchestrator;
  23. import com.sonar.orchestrator.build.MavenBuild;
  24. import com.sonar.orchestrator.locator.FileLocation;
  25. import org.junit.Ignore;
  26. import org.sonarsource.sonarqube.perf.PerfTestCase;
  27. import org.junit.BeforeClass;
  28. import org.junit.ClassRule;
  29. import org.junit.Test;
  30. import static org.junit.Assert.fail;
  31. @Ignore("Temporarily disabled as it requires access to IT_SOURCES")
  32. public class WebTest extends PerfTestCase {
  33. static final int DEFAULT_PAGE_TIMEOUT_MS = 1000;
  34. @ClassRule
  35. public static Orchestrator orchestrator = Orchestrator.builderEnv()
  36. .setOrchestratorProperty("javaVersion", "LATEST_RELEASE")
  37. .addPlugin("java")
  38. .restoreProfileAtStartup(FileLocation.ofClasspath("/java-quality-profile.xml"))
  39. .build();
  40. @BeforeClass
  41. public static void scan_struts() throws Exception {
  42. FileLocation strutsHome = orchestrator.getFileLocationOfShared("it-sonar-performancing/struts-1.3.9/pom.xml");
  43. MavenBuild scan = MavenBuild.create(strutsHome.getFile());
  44. scan.setGoals("sonar:sonar -V");
  45. scan.setEnvironmentVariable("MAVEN_OPTS", "-Xmx512m -server");
  46. scan.setProperty("sonar.scm.disabled", "true");
  47. scan.setProperty("sonar.sourceEncoding", "UTF-8");
  48. orchestrator.executeBuild(scan);
  49. }
  50. @Test
  51. public void homepage() throws Exception {
  52. PageStats counters = request("/");
  53. assertDurationLessThan(counters.durationMs, 300);
  54. }
  55. @Test
  56. public void quality_profiles() throws Exception {
  57. PageStats counters = request("/profiles");
  58. assertDurationLessThan(counters.durationMs, DEFAULT_PAGE_TIMEOUT_MS);
  59. }
  60. @Test
  61. public void issues_search() throws Exception {
  62. PageStats counters = request("/issues/search");
  63. assertDurationLessThan(counters.durationMs, 300);
  64. }
  65. @Test
  66. public void measures_search() throws Exception {
  67. PageStats counters = request("/measures");
  68. assertDurationLessThan(counters.durationMs, 550);
  69. }
  70. @Test
  71. public void all_projects() throws Exception {
  72. PageStats counters = request("/all_projects?qualifier=TRK");
  73. assertDurationLessThan(counters.durationMs, 300);
  74. }
  75. @Test
  76. public void project_measures_search() throws Exception {
  77. PageStats counters = request("/measures/search?qualifiers[]=TRK");
  78. assertDurationLessThan(counters.durationMs, 300);
  79. }
  80. @Test
  81. public void file_measures_search() throws Exception {
  82. PageStats counters = request("/measures/search?qualifiers[]=FIL");
  83. assertDurationLessThan(counters.durationMs, 500);
  84. }
  85. @Test
  86. public void struts_dashboard() throws Exception {
  87. PageStats counters = request("/dashboard/index/org.apache.struts:struts-parent?name=Custom");
  88. assertDurationLessThan(counters.durationMs, 400);
  89. }
  90. @Test
  91. public void struts_issues() throws Exception {
  92. PageStats counters = request("/issues/search?componentRoots=org.apache.struts:struts-parent");
  93. assertDurationLessThan(counters.durationMs, 300);
  94. }
  95. @Test
  96. public void struts_issues_drilldown() throws Exception {
  97. PageStats counters = request("/drilldown/issues/org.apache.struts:struts-parent");
  98. assertDurationLessThan(counters.durationMs, 400);
  99. }
  100. @Test
  101. public void struts_measures_drilldown() throws Exception {
  102. PageStats counters = request("/drilldown/measures/org.apache.struts:struts-parent?metric=ncloc");
  103. // sounds too high !
  104. assertDurationLessThan(counters.durationMs, DEFAULT_PAGE_TIMEOUT_MS);
  105. }
  106. @Test
  107. public void struts_debt_overview() throws Exception {
  108. PageStats counters = request("/overview/issues?id=org.apache.struts:struts-parent");
  109. assertDurationLessThan(counters.durationMs, DEFAULT_PAGE_TIMEOUT_MS);
  110. }
  111. @Test
  112. public void stylesheet_file() throws Exception {
  113. PageStats counters = request("/css/sonar.css");
  114. assertDurationLessThan(counters.durationMs, 40);
  115. }
  116. @Test
  117. public void javascript_file() throws Exception {
  118. PageStats counters = request("/js/bundles/sonar.js");
  119. assertDurationLessThan(counters.durationMs, 40);
  120. }
  121. PageStats request(String path) {
  122. String url = orchestrator.getServer().getUrl() + path;
  123. // warm-up
  124. for (int i = 0; i < 5; i++) {
  125. newRequest(url).code();
  126. }
  127. long targetDuration = Long.MAX_VALUE;
  128. long targetSize = 0L;
  129. for (int i = 0; i < 10; i++) {
  130. HttpRequest request = newRequest(url);
  131. long start = System.currentTimeMillis();
  132. if (request.ok()) {
  133. long duration = System.currentTimeMillis() - start;
  134. int size = request.body().length();
  135. if (duration < targetDuration) {
  136. targetDuration = duration;
  137. targetSize = size;
  138. }
  139. System.out.printf("##### Page %50s %7d ms %7d bytes\n", path, duration, size);
  140. }
  141. }
  142. if (targetDuration == Long.MAX_VALUE) {
  143. fail(String.format("Failed to load page: %s", url));
  144. }
  145. return new PageStats(targetDuration, targetSize);
  146. }
  147. private HttpRequest newRequest(String url) {
  148. HttpRequest request = HttpRequest.get(url);
  149. request.followRedirects(false).acceptJson().acceptCharset(HttpRequest.CHARSET_UTF8);
  150. return request;
  151. }
  152. static class PageStats {
  153. long durationMs;
  154. long sizeBytes;
  155. PageStats(long durationMs, long sizeBytes) {
  156. this.durationMs = durationMs;
  157. this.sizeBytes = sizeBytes;
  158. }
  159. }
  160. }