Search in sources :

Example 1 with FileSystem

use of com.sonar.orchestrator.config.FileSystem 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)

Example 2 with FileSystem

use of com.sonar.orchestrator.config.FileSystem in project sonar-scanner-jenkins by SonarSource.

the class JenkinsOrchestrator method start.

public void start() {
    if (started.getAndSet(true)) {
        throw new IllegalStateException("Jenkins is already started");
    }
    int port = config.getInt("jenkins.container.port", 0);
    if (port <= 0) {
        port = NetworkUtils.getNextAvailablePort(NetworkUtils.getLocalhost());
    }
    distribution.setPort(port);
    FileSystem fileSystem = config.fileSystem();
    ServerInstaller serverInstaller = new ServerInstaller(fileSystem);
    server = serverInstaller.install(distribution);
    server.setUrl(String.format("http://localhost:%d", port));
    jenkinsWrapper = new JenkinsWrapper(server, config, fileSystem.javaHome(), port);
    jenkinsWrapper.start();
    FirefoxProfile profile = new FirefoxProfile();
    // force language to be English
    profile.setPreference("intl.accept_languages", "en");
    FirefoxOptions options = new FirefoxOptions().setProfile(profile);
    driver = new FirefoxDriver(options);
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.get(server.getUrl());
    // Fix window size for having reproducible test behavior
    driver.manage().window().setPosition(new Point(20, 20));
    driver.manage().window().setSize(new Dimension(1024, 768));
    try {
        cli = new CLI(new URL(server.getUrl()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // Force updatecenter initialization
    driver.get(server.getUrl() + "/pluginManager");
    findElement(By.linkText("Advanced")).click();
    findElement(buttonByText("Check now")).click();
}
Also used : CLI(hudson.cli.CLI) JenkinsWrapper(com.sonar.it.jenkins.orchestrator.container.JenkinsWrapper) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) Point(org.openqa.selenium.Point) URL(java.net.URL) IOException(java.io.IOException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FileSystem(com.sonar.orchestrator.config.FileSystem) ServerInstaller(com.sonar.it.jenkins.orchestrator.container.ServerInstaller)

Aggregations

FileSystem (com.sonar.orchestrator.config.FileSystem)2 IOException (java.io.IOException)2 JenkinsWrapper (com.sonar.it.jenkins.orchestrator.container.JenkinsWrapper)1 ServerInstaller (com.sonar.it.jenkins.orchestrator.container.ServerInstaller)1 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 CLI (hudson.cli.CLI)1 File (java.io.File)1 URL (java.net.URL)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 Dimension (org.openqa.selenium.Dimension)1 NoSuchElementException (org.openqa.selenium.NoSuchElementException)1 Point (org.openqa.selenium.Point)1 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)1