diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-03-04 09:51:33 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-03-04 09:52:21 +0100 |
commit | f460d931a6af094623c4a15e0315756fb892ce53 (patch) | |
tree | 6298d3dd303807431d9859153442541ec6ffb52a /server/sonar-server-benchmarks/src | |
parent | 7112f00bad9ebb9081d08200ec41f210ed7cbe3b (diff) | |
download | sonarqube-f460d931a6af094623c4a15e0315756fb892ce53.tar.gz sonarqube-f460d931a6af094623c4a15e0315756fb892ce53.zip |
Improve assertions in server benchmarks
Diffstat (limited to 'server/sonar-server-benchmarks/src')
4 files changed, 13 insertions, 4 deletions
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 index 05ddb828634..a6003b576b0 100644 --- 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 @@ -40,9 +40,14 @@ public class Benchmark extends ErrorCollector { } } - public void expectLessThanOrEqualTo(String label, long val, long max) { + public void expectAround(String label, long val, long expect, double marginPercents) { if (ENABLED) { - checkThat(label, val, Matchers.lessThan(max)); + if (marginPercents > 0.2) { + throw new IllegalArgumentException("Error margin must be less than 0.2 (20%). Has: " + marginPercents); + } + long min = (long) (expect * (1.0 - marginPercents)); + long max = (long) (expect * (1.0 + marginPercents)); + checkThat(label, val, Matchers.allOf(Matchers.greaterThan(min), 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 4d2a9de9f5b..c10ee9983ef 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 @@ -112,7 +112,7 @@ public class IssueIndexBenchmarkTest { long period = System.currentTimeMillis() - start; long throughputPerSecond = 1000 * issues.count.get() / period; LOGGER.info(String.format("%d issues indexed in %d ms (%d docs/second)", issues.count.get(), period, throughputPerSecond)); - benchmark.expectBetween("Throughput to index issues", throughputPerSecond, 3000, 3400); + benchmark.expectAround("Throughput to index issues", throughputPerSecond, 3000, 0.04); // be sure that physical files do not evolve during estimation of size tester.get(EsClient.class).prepareOptimize("issues").get(); diff --git a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceDbBenchmarkTest.java b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceDbBenchmarkTest.java index 3d6dbf32645..34dbdf0e3cc 100644 --- a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceDbBenchmarkTest.java +++ b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceDbBenchmarkTest.java @@ -53,6 +53,9 @@ public class SourceDbBenchmarkTest { @Rule public DbTester dbTester = new DbTester(); + @Rule + public Benchmark benchmark = new Benchmark(); + @Test public void benchmark() throws Exception { prepareTable(); @@ -81,6 +84,7 @@ public class SourceDbBenchmarkTest { long period = end - start; long throughputPerSecond = 1000L * counter.get() / period; LOGGER.info(String.format("%d FILE_SOURCES rows scrolled in %d ms (%d rows/second)", counter.get(), period, throughputPerSecond)); + benchmark.expectAround("Throughput to scroll FILE_SOURCES", throughputPerSecond, 120, 0.04); } finally { DbUtils.closeQuietly(connection); diff --git a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceIndexBenchmarkTest.java b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceIndexBenchmarkTest.java index 7ed033e45a9..6480c4ef0df 100644 --- a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceIndexBenchmarkTest.java +++ b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/SourceIndexBenchmarkTest.java @@ -88,7 +88,7 @@ public class SourceIndexBenchmarkTest { long nbLines = files.count.get() * LINES_PER_FILE; long throughputPerSecond = 1000L * nbLines / period; LOGGER.info(String.format("%d lines indexed in %d ms (%d docs/second)", nbLines, period, throughputPerSecond)); - benchmark.expectBetween("Throughput to index source lines", throughputPerSecond, 7500, 8000); + benchmark.expectAround("Throughput to index source lines", throughputPerSecond, 7800, 0.04); // be sure that physical files do not evolve during estimation of size tester.get(EsClient.class).prepareOptimize(SourceLineIndexDefinition.INDEX).get(); |