Search in sources :

Example 26 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class GitMaterialUpdaterTest method shouldDeleteAndRecheckoutDirectoryWhenBranchChanges.

@Test
public void shouldDeleteAndRecheckoutDirectoryWhenBranchChanges() throws Exception {
    GitTestRepo repoWithBranch = GitTestRepo.testRepoAtBranch(GIT_FOO_BRANCH_BUNDLE, "foo", temporaryFolder);
    GitMaterial material = new GitMaterial(repoWithBranch.projectRepositoryUrl(), true);
    updateTo(material, new RevisionContext(new StringRevision("origin/master")), JobResult.Passed);
    InMemoryStreamConsumer output = inMemoryConsumer();
    CommandLine.createCommandLine("git").withEncoding("UTF-8").withArg("branch").withWorkingDir(workingDir).run(output, "");
    assertThat(output.getStdOut(), Is.is("* master"));
    GitMaterial material1 = new GitMaterial(repoWithBranch.projectRepositoryUrl(), "foo", null, true);
    updateTo(material1, new RevisionContext(new StringRevision("origin/foo")), JobResult.Passed);
    output = inMemoryConsumer();
    CommandLine.createCommandLine("git").withEncoding("UTF-8").withArg("branch").withWorkingDir(workingDir).run(output, "");
    assertThat(output.getStdOut(), Is.is("* foo"));
}
Also used : RevisionContext(com.thoughtworks.go.domain.materials.RevisionContext) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.Test)

Example 27 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class GitMaterialTest method shouldDeleteAndRecheckoutDirectoryWhenBranchChanges.

@Test
public void shouldDeleteAndRecheckoutDirectoryWhenBranchChanges() throws Exception {
    git = new GitMaterial(gitFooBranchBundle.projectRepositoryUrl());
    git.latestModification(workingDir, new TestSubprocessExecutionContext());
    InMemoryStreamConsumer output = inMemoryConsumer();
    CommandLine.createCommandLine("git").withEncoding("UTF-8").withArg("branch").withWorkingDir(workingDir).run(output, "");
    assertThat(output.getStdOut(), is("* master"));
    git = new GitMaterial(gitFooBranchBundle.projectRepositoryUrl(), "foo");
    git.latestModification(workingDir, new TestSubprocessExecutionContext());
    output = inMemoryConsumer();
    CommandLine.createCommandLine("git").withEncoding("UTF-8").withArg("branch").withWorkingDir(workingDir).run(output, "");
    assertThat(output.getStdOut(), is("* foo"));
}
Also used : InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.Test)

Example 28 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class PipelineConfigServicePerformanceTest method takeHeapDump.

private void takeHeapDump(File dumpDir, int i) {
    InMemoryStreamConsumer outputStreamConsumer = inMemoryConsumer();
    CommandLine commandLine = CommandLine.createCommandLine("jmap").withArgs("-J-d64", String.format("-dump:format=b,file=%s/%s.hprof", dumpDir.getAbsoluteFile(), i), ManagementFactory.getRuntimeMXBean().getName().split("@")[0]);
    LOGGER.info(commandLine.describe());
    int exitCode = commandLine.run(outputStreamConsumer, "thread" + i);
    LOGGER.info(outputStreamConsumer.getAllOutput());
    assertThat(exitCode, is(0));
    LOGGER.info("Heap dump available at " + dumpDir.getAbsolutePath());
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer)

Example 29 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class P4Material method getP4.

protected P4Client getP4(File baseDir) {
    InMemoryStreamConsumer outputConsumer = inMemoryConsumer();
    P4Client p4 = null;
    try {
        p4 = p4(baseDir, outputConsumer);
    } catch (Exception e) {
        bomb(e.getMessage() + " " + outputConsumer.getStdError(), e);
    }
    return p4;
}
Also used : P4Client(com.thoughtworks.go.domain.materials.perforce.P4Client) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) IOException(java.io.IOException)

Example 30 with InMemoryStreamConsumer

use of com.thoughtworks.go.util.command.InMemoryStreamConsumer in project gocd by gocd.

the class P4MaterialTest method shouldGenerateTheSameP4ClientValueForCommandAndEnvironment.

@Test
void shouldGenerateTheSameP4ClientValueForCommandAndEnvironment() throws Exception {
    P4Material p4Material = new P4Material("server:10", "out-of-the-window");
    ReflectionUtil.setField(p4Material, "folder", "crapy_dir");
    P4Client p4Client = p4Material._p4(workingDir, new InMemoryStreamConsumer(), false);
    assertThat(p4Client).isNotNull();
    String client = (String) ReflectionUtil.getField(p4Client, "p4ClientName");
    assertThat(client).isEqualTo(p4Material.clientName(workingDir));
}
Also used : P4Client(com.thoughtworks.go.domain.materials.perforce.P4Client) InMemoryStreamConsumer(com.thoughtworks.go.util.command.InMemoryStreamConsumer) Test(org.junit.jupiter.api.Test)

Aggregations

InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)31 Test (org.junit.Test)17 GitSubmoduleRepos (com.thoughtworks.go.helper.GitSubmoduleRepos)8 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)7 File (java.io.File)7 StringContains.containsString (org.hamcrest.core.StringContains.containsString)7 Test (org.junit.jupiter.api.Test)5 ModifiedFile (com.thoughtworks.go.domain.materials.ModifiedFile)4 CommandLine (com.thoughtworks.go.util.command.CommandLine)4 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)3 Modification (com.thoughtworks.go.domain.materials.Modification)3 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)2 P4Client (com.thoughtworks.go.domain.materials.perforce.P4Client)2 IOException (java.io.IOException)2 SubprocessExecutionContext (com.thoughtworks.go.config.materials.SubprocessExecutionContext)1 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)1 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)1 PluggableSCMMaterialAgent (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialAgent)1