From 08e74cebd49de12780885e2d6427e56d624daa02 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 2 Dec 2014 18:58:46 +0100 Subject: [PATCH] Add module sonar-data-test to build --- server/pom.xml | 1 + server/sonar-data-test/pom.xml | 28 +++++++++++++++- .../server/benchmark/BenchmarkAssertions.java | 33 +++++++++++++++++++ .../benchmark/IssueIndexBenchmarkTest.java | 7 ++-- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 server/sonar-data-test/src/test/java/org/sonar/server/benchmark/BenchmarkAssertions.java 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 @@ sonar-server sonar-web sonar-ws-client + sonar-data-test 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 @@ sonar-data-test SonarQube :: Server :: Benchmark + + + true + + org.codehaus.sonar @@ -49,10 +54,31 @@ org.apache.maven.plugins maven-surefire-plugin - -Xmx1G -Xms256m -server -Djava.awt.headless=true + ${skipServerTests} + -Xmx1G -Xms256m -server -Djava.awt.headless=true -DenableBenchmarkAssertions=${enableBenchmarkAssertions} + + ${testInclusions} + + + + + runBenchmarks + + + runBenchmarks + + + + org/sonar/server/benchmark/**/*.java + + + 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 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())))); } -- 2.39.5