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");
}
}
Aggregations