Search in sources :

Example 1 with BuildFailureException

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

the class OrganizationTest method by_default_anonymous_cannot_analyse_project_on_organization.

@Test
public void by_default_anonymous_cannot_analyse_project_on_organization() {
    verifyNoExtraOrganization();
    String orgKeyAndName = "org-key";
    Organizations.Organization createdOrganization = adminOrganizationService.create(new CreateWsRequest.Builder().setName(orgKeyAndName).setKey(orgKeyAndName).build()).getOrganization();
    verifySingleSearchResult(createdOrganization, orgKeyAndName, null, null, null);
    try {
        ItUtils.runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.organization", orgKeyAndName);
        fail();
    } catch (BuildFailureException e) {
        assertThat(e.getResult().getLogs()).contains("Insufficient privileges");
    }
    ComponentsService componentsService = ItUtils.newAdminWsClient(orchestrator).components();
    assertThat(searchSampleProject(orgKeyAndName, componentsService).getComponentsCount()).isEqualTo(0);
    adminOrganizationService.delete(orgKeyAndName);
}
Also used : ComponentsService(org.sonarqube.ws.client.component.ComponentsService) BuildFailureException(com.sonar.orchestrator.build.BuildFailureException) Organizations(org.sonarqube.ws.Organizations) CreateWsRequest(org.sonarqube.ws.client.organization.CreateWsRequest) Test(org.junit.Test)

Example 2 with BuildFailureException

use of com.sonar.orchestrator.build.BuildFailureException 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)2 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 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1 Organizations (org.sonarqube.ws.Organizations)1 ComponentsService (org.sonarqube.ws.client.component.ComponentsService)1 CreateWsRequest (org.sonarqube.ws.client.organization.CreateWsRequest)1