123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarsource.sonarqube.perf.scanner.suite;
-
- import com.sonar.orchestrator.Orchestrator;
- import com.sonar.orchestrator.build.SonarRunner;
- import org.sonarsource.sonarqube.perf.PerfRule;
- import org.sonarsource.sonarqube.perf.PerfTestCase;
- import java.io.File;
- import java.io.IOException;
- import java.util.Properties;
- import org.apache.commons.io.FileUtils;
- import org.apache.commons.lang.StringUtils;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import org.junit.ClassRule;
- import org.junit.Rule;
- import org.junit.Test;
- import org.junit.rules.TemporaryFolder;
-
- public class FileSystemTest extends PerfTestCase {
-
- @Rule
- public PerfRule perfRule = new PerfRule(4) {
- @Override
- protected void beforeEachRun() {
- orchestrator.resetData();
- }
- };
-
- @ClassRule
- public static TemporaryFolder temp = new TemporaryFolder();
-
- @ClassRule
- public static Orchestrator orchestrator = ScannerPerfTestSuite.ORCHESTRATOR;
-
- private static File baseDir;
-
- @BeforeClass
- public static void setUp() throws IOException {
- // Execute a first analysis to prevent any side effects with cache of plugin JAR files
- orchestrator.executeBuild(newScanner("-Xmx512m -server", "sonar.profile", "one-xoo-issue-per-line"));
- baseDir = prepareProject();
- }
-
- @Before
- public void cleanDatabase() {
- orchestrator.resetData();
- }
-
- @Test
- public void indexProjectWith1000BigFilesXmx128() throws IOException {
- run(128, 30000L);
- }
-
- private void run(int xmx, long expectedDuration) throws IOException {
- SonarRunner runner = SonarRunner.create()
- .setProperties(
- "sonar.projectName", "filesystem xmx" + xmx,
- "sonar.projectVersion", "1.0",
- "sonar.sources", "src",
- "sonar.analysis.mode", "issues",
- "sonar.showProfiling", "true")
- .setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx" + xmx + "m -server -XX:MaxPermSize=64m")
- .setProjectDir(baseDir);
-
- orchestrator.executeBuild(runner);
-
- Properties prof = readProfiling(baseDir, "project");
- perfRule.assertDurationAround(Long.valueOf(prof.getProperty("Index filesystem")), expectedDuration);
- }
-
- private static File prepareProject() throws IOException {
- File baseDir = temp.newFolder();
- File srcDir = new File(baseDir, "src");
- srcDir.mkdir();
-
- int nbFiles = 1000;
- int lines = 10000;
- for (int nb = 1; nb <= nbFiles; nb++) {
- File xooFile = new File(srcDir, "sample" + nb + ".xoo");
- FileUtils.write(xooFile, StringUtils.repeat(StringUtils.repeat("a", 100) + "\n", lines));
- }
- return baseDir;
- }
-
- }
|