Search in sources :

Example 1 with SonarScannerInstaller

use of com.sonar.orchestrator.build.SonarScannerInstaller in project sonarqube by SonarSource.

the class IssuesModeTest method runConcurrentIssues.

private void runConcurrentIssues(final String workDirPath) throws Exception {
    // Install sonar-runner in advance to avoid concurrent unzip issues
    FileSystem fileSystem = orchestrator.getConfiguration().fileSystem();
    new SonarScannerInstaller(fileSystem).install(Version.create(SonarScanner.DEFAULT_SCANNER_VERSION), fileSystem.workspace(), true);
    final int nThreads = 3;
    ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
    List<Callable<BuildResult>> tasks = new ArrayList<>();
    final File homeDir = temp.newFolder();
    for (int i = 0; i < nThreads; i++) {
        tasks.add(new Callable<BuildResult>() {

            public BuildResult call() throws Exception {
                SonarScanner runner = configureRunnerIssues("shared/xoo-sample", homeDir, "sonar.it.enableWaitingSensor", "true", "sonar.working.directory", workDirPath);
                return orchestrator.executeBuild(runner);
            }
        });
    }
    boolean expectedError = false;
    for (Future<BuildResult> result : executorService.invokeAll(tasks)) {
        try {
            result.get();
        } catch (ExecutionException e) {
            if (e.getCause() instanceof BuildFailureException) {
                BuildFailureException bfe = (BuildFailureException) e.getCause();
                assertThat(bfe.getResult().getLogs()).contains("Another SonarQube analysis is already in progress for this project");
                expectedError = true;
            } else {
                throw e;
            }
        }
    }
    if (!expectedError) {
        fail("At least one of the threads should have failed");
    }
}
Also used : BuildFailureException(com.sonar.orchestrator.build.BuildFailureException) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ExpectedException(org.junit.rules.ExpectedException) BuildFailureException(com.sonar.orchestrator.build.BuildFailureException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BuildResult(com.sonar.orchestrator.build.BuildResult) FileSystem(com.sonar.orchestrator.config.FileSystem) ExecutorService(java.util.concurrent.ExecutorService) SonarScannerInstaller(com.sonar.orchestrator.build.SonarScannerInstaller) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner)

Aggregations

BuildFailureException (com.sonar.orchestrator.build.BuildFailureException)1 BuildResult (com.sonar.orchestrator.build.BuildResult)1 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 SonarScannerInstaller (com.sonar.orchestrator.build.SonarScannerInstaller)1 FileSystem (com.sonar.orchestrator.config.FileSystem)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 ExpectedException (org.junit.rules.ExpectedException)1