From: Simon Brandhof Date: Fri, 5 Dec 2014 17:14:37 +0000 (+0100) Subject: Add assertions for SonarSource performancing box to sonar-server-benchmarks X-Git-Tag: 5.0-RC1~40 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=50cfbe42ac5173082c584b25b1a016b60573eaa7;p=sonarqube.git Add assertions for SonarSource performancing box to sonar-server-benchmarks --- diff --git a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/Benchmark.java b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/Benchmark.java new file mode 100644 index 00000000000..d8d7824e0ab --- /dev/null +++ b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/Benchmark.java @@ -0,0 +1,48 @@ +/* + * 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; + +import org.hamcrest.Matchers; +import org.junit.rules.ErrorCollector; + +public class Benchmark extends ErrorCollector { + + 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."); + } + } + + public void expectBetween(String label, long val, long min, long max) { + if (ENABLED) { + checkThat(label, val, Matchers.allOf(Matchers.greaterThan(min), Matchers.lessThan(max))); + } + } + + public void expectLessThanOrEqualTo(String label, long val, long max) { + if (ENABLED) { + checkThat(label, val, Matchers.lessThan(max)); + } + } + +} diff --git a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/BenchmarkAssertions.java b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/BenchmarkAssertions.java deleted file mode 100644 index 33c616faf89..00000000000 --- a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/BenchmarkAssertions.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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-server-benchmarks/src/test/java/org/sonar/server/benchmark/IssueIndexBenchmarkTest.java b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/IssueIndexBenchmarkTest.java index 771155528f5..e1bfbaf0be9 100644 --- a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/IssueIndexBenchmarkTest.java +++ b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/IssueIndexBenchmarkTest.java @@ -27,6 +27,7 @@ import com.google.common.collect.Maps; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.math.RandomUtils; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,6 +63,9 @@ public class IssueIndexBenchmarkTest { @ClassRule public static ServerTester tester = new ServerTester(); + @Rule + public Benchmark benchmark = new Benchmark(); + @Test public void benchmark() throws Exception { // initialization - feed issues/issueAuthorization with projects and hardcoded users @@ -88,6 +92,9 @@ public class IssueIndexBenchmarkTest { 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)); + + // big range as absolute value is quite slow + benchmark.expectBetween("Time to index issue authorizations", period, 200L, 500L); } private void benchmarkIssueIndexing() { @@ -103,7 +110,11 @@ public class IssueIndexBenchmarkTest { timer.cancel(); 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())))); + benchmark.expectBetween("Time to index issues", period, 350000L, 430000L); + + long dirSize = FileUtils.sizeOfDirectory(tester.getEsServerHolder().getHomeDir()); + LOGGER.info(String.format("ES disk: " + FileUtils.byteCountToDisplaySize(dirSize))); + benchmark.expectBetween("ES disk size (b)", dirSize, 385000000L, 395000000L); } private void benchmarkQueries() {