From 50cfbe42ac5173082c584b25b1a016b60573eaa7 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 5 Dec 2014 18:14:37 +0100 Subject: [PATCH] Add assertions for SonarSource performancing box to sonar-server-benchmarks --- ...{BenchmarkAssertions.java => Benchmark.java} | 17 ++++++++++++++++- .../benchmark/IssueIndexBenchmarkTest.java | 13 ++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) rename server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/{BenchmarkAssertions.java => Benchmark.java} (72%) 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/Benchmark.java similarity index 72% rename from server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/BenchmarkAssertions.java rename to server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/Benchmark.java index 33c616faf89..d8d7824e0ab 100644 --- 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/Benchmark.java @@ -19,7 +19,10 @@ */ package org.sonar.server.benchmark; -public class BenchmarkAssertions { +import org.hamcrest.Matchers; +import org.junit.rules.ErrorCollector; + +public class Benchmark extends ErrorCollector { private static final boolean ENABLED = "true".equals(System.getProperty("enableBenchmarkAssertions")); @@ -30,4 +33,16 @@ public class BenchmarkAssertions { } } + 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/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() { -- 2.39.5