diff options
4 files changed, 66 insertions, 3 deletions
diff --git a/server/pom.xml b/server/pom.xml index 7a5c9de19d8..8e087ad3f87 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -17,5 +17,6 @@ <module>sonar-server</module> <module>sonar-web</module> <module>sonar-ws-client</module> + <module>sonar-data-test</module> </modules> </project> diff --git a/server/sonar-data-test/pom.xml b/server/sonar-data-test/pom.xml index 02417b40099..6f0afb22757 100644 --- a/server/sonar-data-test/pom.xml +++ b/server/sonar-data-test/pom.xml @@ -11,6 +11,11 @@ <artifactId>sonar-data-test</artifactId> <name>SonarQube :: Server :: Benchmark</name> + <properties> + <testInclusions/> + <enableBenchmarkAssertions>true</enableBenchmarkAssertions> + </properties> + <dependencies> <dependency> <groupId>org.codehaus.sonar</groupId> @@ -49,10 +54,31 @@ <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 index 00000000000..33c616faf89 --- /dev/null +++ b/server/sonar-data-test/src/test/java/org/sonar/server/benchmark/BenchmarkAssertions.java @@ -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."); + } + } + +} diff --git a/server/sonar-data-test/src/test/java/org/sonar/server/benchmark/IssueIndexBenchmarkTest.java b/server/sonar-data-test/src/test/java/org/sonar/server/benchmark/IssueIndexBenchmarkTest.java index 820d1b6a9f7..4a48f050968 100644 --- a/server/sonar-data-test/src/test/java/org/sonar/server/benchmark/IssueIndexBenchmarkTest.java +++ b/server/sonar-data-test/src/test/java/org/sonar/server/benchmark/IssueIndexBenchmarkTest.java @@ -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())))); } |