From 2fbfee12b562f5fa2c16e3dd9293493678233b52 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 5 Dec 2014 18:38:24 +0100 Subject: [PATCH] Add assertions to sonar-server-benchmarks --- .../org/sonar/server/benchmark/Benchmark.java | 2 +- .../benchmark/IssueIndexBenchmarkTest.java | 9 ++++----- .../benchmark/SourceIndexBenchmarkTest.java | 16 +++++++++++----- 3 files changed, 16 insertions(+), 11 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 d8d7824e0ab..b839f2a4cd7 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 @@ -28,7 +28,7 @@ public class Benchmark extends ErrorCollector { static { if (ENABLED) { - System.out.println("Assertions are calibrated for a dedicated benchmark environment. " + + System.out.println("Assertions are calibrated for SonarSource dedicated box. " + "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 e1bfbaf0be9..640cdcf6abd 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 @@ -26,7 +26,6 @@ import com.google.common.collect.Lists; 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; @@ -60,8 +59,8 @@ public class IssueIndexBenchmarkTest { final static int FILES_PER_PROJECT = 100; final static int ISSUES_PER_FILE = 100; - @ClassRule - public static ServerTester tester = new ServerTester(); + @Rule + public ServerTester tester = new ServerTester(); @Rule public Benchmark benchmark = new Benchmark(); @@ -113,8 +112,8 @@ public class IssueIndexBenchmarkTest { 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); + LOGGER.info(String.format("ES dir: " + FileUtils.byteCountToDisplaySize(dirSize))); + benchmark.expectBetween("ES dir size (b)", dirSize, 385L * FileUtils.ONE_MB, 400L * FileUtils.ONE_MB); } private void benchmarkQueries() { 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 e3c8212561f..8cd10343264 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 @@ -24,6 +24,7 @@ import com.google.common.collect.Maps; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,8 +48,11 @@ public class SourceIndexBenchmarkTest { final static long FILES = 10000L; static final int LINES_PER_FILE = 200; - @ClassRule - public static ServerTester tester = new ServerTester(); + @Rule + public ServerTester tester = new ServerTester(); + + @Rule + public Benchmark benchmark = new Benchmark(); @Test public void benchmark() throws Exception { @@ -73,10 +77,12 @@ public class SourceIndexBenchmarkTest { timer.cancel(); long period = end - start; - long nbDocs = files.count.get() * LINES_PER_FILE; - LOGGER.info(String.format("%d files indexed in %d ms (%d docs/second)", nbDocs, period, 1000 * nbDocs / period)); - LOGGER.info(String.format("Index disk: " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfDirectory(tester.getEsServerHolder().getHomeDir())))); + long nbLines = files.count.get() * LINES_PER_FILE; + LOGGER.info(String.format("%d lines indexed in %d ms (%d docs/second)", nbLines, period, nbLines / period)); + long dirSize = FileUtils.sizeOfDirectory(tester.getEsServerHolder().getHomeDir()); + LOGGER.info(String.format("ES dir: " + FileUtils.byteCountToDisplaySize(dirSize))); + benchmark.expectBetween("ES dir size (b)", dirSize, 73L * FileUtils.ONE_MB, 80L * FileUtils.ONE_MB); } private void benchmarkQueries() { -- 2.39.5