]> source.dussan.org Git - sonarqube.git/commitdiff
Add module sonar-data-test to build
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 2 Dec 2014 17:58:46 +0000 (18:58 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 2 Dec 2014 17:58:56 +0000 (18:58 +0100)
server/pom.xml
server/sonar-data-test/pom.xml
server/sonar-data-test/src/test/java/org/sonar/server/benchmark/BenchmarkAssertions.java [new file with mode: 0644]
server/sonar-data-test/src/test/java/org/sonar/server/benchmark/IssueIndexBenchmarkTest.java

index 7a5c9de19d8b7a41521b2a4ecdd6b90c960d81f9..8e087ad3f874465e31ec51d2d364fc4a6a6e674e 100644 (file)
@@ -17,5 +17,6 @@
     <module>sonar-server</module>
     <module>sonar-web</module>
     <module>sonar-ws-client</module>
+    <module>sonar-data-test</module>
   </modules>
 </project>
index 02417b40099a51e2390192c251aecf3cf4efb898..6f0afb22757175a7f6f890677118c4a2b48410d6 100644 (file)
   <artifactId>sonar-data-test</artifactId>
   <name>SonarQube :: Server :: Benchmark</name>
 
+  <properties>
+    <testInclusions/>
+    <enableBenchmarkAssertions>true</enableBenchmarkAssertions>
+  </properties>
+
   <dependencies>
     <dependency>
       <groupId>org.codehaus.sonar</groupId>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
-          <argLine>-Xmx1G -Xms256m -server -Djava.awt.headless=true</argLine>
+          <skipTests>${skipServerTests}</skipTests>
+          <argLine>-Xmx1G -Xms256m -server -Djava.awt.headless=true -DenableBenchmarkAssertions=${enableBenchmarkAssertions}</argLine>
+          <includes>
+            <include>${testInclusions}</include>
+          </includes>
         </configuration>
       </plugin>
     </plugins>
   </build>
 
+  <!--
+  mvn install -DrunBenchmarks=true -DenableBenchmarkAssertions=true
+
+  -->
+  <profiles>
+    <profile>
+      <id>runBenchmarks</id>
+      <activation>
+        <property>
+          <name>runBenchmarks</name>
+        </property>
+      </activation>
+      <properties>
+        <testInclusions>org/sonar/server/benchmark/**/*.java</testInclusions>
+      </properties>
+    </profile>
+  </profiles>
 </project>
diff --git a/server/sonar-data-test/src/test/java/org/sonar/server/benchmark/BenchmarkAssertions.java b/server/sonar-data-test/src/test/java/org/sonar/server/benchmark/BenchmarkAssertions.java
new file mode 100644 (file)
index 0000000..33c616f
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.benchmark;
+
+public class BenchmarkAssertions {
+
+  private static final boolean ENABLED = "true".equals(System.getProperty("enableBenchmarkAssertions"));
+
+  static {
+    if (ENABLED) {
+      System.out.println("Assertions are calibrated for a dedicated benchmark environment. " +
+        "They can be disabled by setting the property -DenableBenchmarkAssertions=false.");
+    }
+  }
+
+}
index 820d1b6a9f765421e2b86f482822d213022b6d68..4a48f050968602811a5de22d1c0f56ad12582402 100644 (file)
@@ -75,6 +75,7 @@ public class IssueIndexBenchmarkTest {
   }
 
   private void indexAuthorizations() {
+    LOGGER.info("Indexing issue authorizations");
     IssueAuthorizationIndexer indexer = tester.get(IssueAuthorizationIndexer.class);
     List<IssueAuthorizationDao.Dto> authorizations = Lists.newArrayList();
     for (int i = 0; i < PROJECTS; i++) {
@@ -83,7 +84,10 @@ public class IssueIndexBenchmarkTest {
       authorization.addUser("admin");
       authorizations.add(authorization);
     }
+    long start = System.currentTimeMillis();
     indexer.index(authorizations);
+    long period = System.currentTimeMillis() - start;
+    LOGGER.info(String.format("%d authorizations indexed in %d ms (%d docs/second)", PROJECTS, period, 1000 * PROJECTS / period));
   }
 
   private void benchmarkIssueIndexing() {
@@ -95,10 +99,9 @@ public class IssueIndexBenchmarkTest {
 
     long start = System.currentTimeMillis();
     tester.get(IssueIndexer.class).index(issues);
-    long end = System.currentTimeMillis();
 
     timer.cancel();
-    long period = end - start;
+    long period = System.currentTimeMillis() - start;
     LOGGER.info(String.format("%d issues indexed in %d ms (%d docs/second)", issues.count.get(), period, 1000 * issues.count.get() / period));
     LOGGER.info(String.format("Index disk: " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(tester.getEsServerHolder().getHomeDir()))));
   }