--- /dev/null
+/*
+ * 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));
+ }
+ }
+
+}
+++ /dev/null
-/*
- * 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.");
- }
- }
-
-}
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;
@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
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() {
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() {