Search in sources :

Example 31 with Builder

use of com.thoughtworks.go.domain.builder.Builder in project gocd by gocd.

the class BuildAssignmentServiceIntegrationTest method shouldCreateWork_withAncestorFetchArtifactCalls_resolvedToRelevantStage.

/**
 * (uppest/2/uppest-stage/1)
 * |------------------> upper-peer -------
 * |  ...................................|...............................................
 * |  .                                  |                                              .
 * [ uppest-stage ............................|......................    {bar.zip uppest/upper-peer/downer}
 * V                     .
 * uppest  uppest-stage-2  ------> upper ------> downer ------> downest {foo.zip uppest/upper/downer}
 * (uppest/1/uppest-stage-2/1)
 * uppest-stage-3 ]
 * <p/>
 * .... :: fetch artifact call
 * ---> :: material dependency
 */
@Test
public void shouldCreateWork_withAncestorFetchArtifactCalls_resolvedToRelevantStage() throws Exception {
    configHelper.addPipeline("uppest", "uppest-stage");
    configHelper.addStageToPipeline("uppest", "uppest-stage-2");
    PipelineConfig uppest = configHelper.addStageToPipeline("uppest", "uppest-stage-3");
    configHelper.addPipeline("upper", "upper-stage");
    DependencyMaterial upper_sMaterial = new DependencyMaterial(new CaseInsensitiveString("uppest"), new CaseInsensitiveString("uppest-stage-2"));
    PipelineConfig upper = configHelper.setMaterialConfigForPipeline("upper", upper_sMaterial.config());
    configHelper.addPipeline("upper-peer", "upper-peer-stage");
    DependencyMaterial upperPeer_sMaterial = new DependencyMaterial(new CaseInsensitiveString("uppest"), new CaseInsensitiveString("uppest-stage"));
    PipelineConfig upperPeer = configHelper.setMaterialConfigForPipeline("upper-peer", upperPeer_sMaterial.config());
    configHelper.addPipeline("downer", "downer-stage");
    DependencyMaterial downer_sUpperMaterial = new DependencyMaterial(new CaseInsensitiveString("upper"), new CaseInsensitiveString("upper-stage"));
    configHelper.setMaterialConfigForPipeline("downer", downer_sUpperMaterial.config());
    DependencyMaterial downer_sUpperPeerMaterial = new DependencyMaterial(new CaseInsensitiveString("upper-peer"), new CaseInsensitiveString("upper-peer-stage"));
    PipelineConfig downer = configHelper.addMaterialToPipeline("downer", downer_sUpperPeerMaterial.config());
    configHelper.addPipeline("downest", "downest-stage");
    DependencyMaterial downest_sMaterial = new DependencyMaterial(new CaseInsensitiveString("downer"), new CaseInsensitiveString("downer-stage"));
    configHelper.setMaterialConfigForPipeline("downest", downest_sMaterial.config());
    Tasks allFetchTasks = new Tasks();
    allFetchTasks.add(new FetchTask(new CaseInsensitiveString("uppest/upper/downer"), new CaseInsensitiveString("uppest-stage"), new CaseInsensitiveString("unit"), "foo.zip", "bar"));
    allFetchTasks.add(new FetchTask(new CaseInsensitiveString("uppest/upper-peer/downer"), new CaseInsensitiveString("uppest-stage"), new CaseInsensitiveString("unit"), "bar.zip", "baz"));
    configHelper.replaceAllJobsInStage("downest", "downest-stage", new JobConfig(new CaseInsensitiveString("fetcher"), new ResourceConfigs("fetcher"), new ArtifactConfigs(), allFetchTasks));
    PipelineConfig downest = goConfigService.getCurrentConfig().pipelineConfigByName(new CaseInsensitiveString("downest"));
    DefaultSchedulingContext defaultSchedulingCtx = new DefaultSchedulingContext(DEFAULT_APPROVED_BY);
    Pipeline uppestInstanceForUpper = instanceFactory.createPipelineInstance(uppest, modifySomeFiles(uppest), defaultSchedulingCtx, md5, new TimeProvider());
    dbHelper.savePipelineWithStagesAndMaterials(uppestInstanceForUpper);
    dbHelper.passStage(uppestInstanceForUpper.findStage("uppest-stage"));
    Stage upper_sMaterialStage = dbHelper.scheduleStage(uppestInstanceForUpper, uppest.getStage(new CaseInsensitiveString("uppest-stage-2")));
    dbHelper.passStage(upper_sMaterialStage);
    Pipeline uppestInstanceForUpperPeer = instanceFactory.createPipelineInstance(uppest, modifySomeFiles(uppest), new DefaultSchedulingContext("super-hero"), md5, new TimeProvider());
    dbHelper.savePipelineWithStagesAndMaterials(uppestInstanceForUpperPeer);
    Stage upperPeer_sMaterialStage = uppestInstanceForUpperPeer.findStage("uppest-stage");
    dbHelper.passStage(upperPeer_sMaterialStage);
    Pipeline upperInstance = instanceFactory.createPipelineInstance(upper, buildCauseForDependency(upper_sMaterial, upper_sMaterialStage), defaultSchedulingCtx, md5, new TimeProvider());
    dbHelper.savePipelineWithStagesAndMaterials(upperInstance);
    Stage downer_sUpperMaterialStage = upperInstance.findStage("upper-stage");
    dbHelper.passStage(downer_sUpperMaterialStage);
    Pipeline upperPeerInstance = instanceFactory.createPipelineInstance(upperPeer, buildCauseForDependency(upperPeer_sMaterial, upperPeer_sMaterialStage), defaultSchedulingCtx, md5, new TimeProvider());
    dbHelper.savePipelineWithStagesAndMaterials(upperPeerInstance);
    Stage downer_sUpperPeerMaterialStage = upperPeerInstance.findStage("upper-peer-stage");
    dbHelper.passStage(downer_sUpperPeerMaterialStage);
    MaterialRevisions downer_sMaterialRevisions = new MaterialRevisions(materialRevisionForDownstream(downer_sUpperMaterial, downer_sUpperMaterialStage), materialRevisionForDownstream(downer_sUpperPeerMaterial, downer_sUpperPeerMaterialStage));
    Pipeline downerInstance = instanceFactory.createPipelineInstance(downer, BuildCause.createManualForced(downer_sMaterialRevisions, loserUser), defaultSchedulingCtx, md5, new TimeProvider());
    dbHelper.savePipelineWithStagesAndMaterials(downerInstance);
    Stage downest_sMaterialStage = downerInstance.findStage("downer-stage");
    dbHelper.passStage(downest_sMaterialStage);
    Pipeline downestInstance = instanceFactory.createPipelineInstance(downest, buildCauseForDependency(downest_sMaterial, downest_sMaterialStage), defaultSchedulingCtx, md5, new TimeProvider());
    dbHelper.savePipelineWithStagesAndMaterials(downestInstance);
    buildAssignmentService.onTimer();
    AgentConfig agentConfig = AgentMother.localAgent();
    agentConfig.addResourceConfig(new ResourceConfig("fetcher"));
    BuildWork work = (BuildWork) buildAssignmentService.assignWorkToAgent(agent(agentConfig));
    List<Builder> builders = work.getAssignment().getBuilders();
    FetchArtifactBuilder fooZipFetch = (FetchArtifactBuilder) builders.get(0);
    assertThat(fooZipFetch.artifactLocator(), is("uppest/1/uppest-stage/latest/unit/foo.zip"));
    FetchArtifactBuilder barZipFetch = (FetchArtifactBuilder) builders.get(1);
    assertThat(barZipFetch.artifactLocator(), is("uppest/2/uppest-stage/1/unit/bar.zip"));
}
Also used : FetchArtifactBuilder(com.thoughtworks.go.domain.builder.FetchArtifactBuilder) Builder(com.thoughtworks.go.domain.builder.Builder) FetchArtifactBuilder(com.thoughtworks.go.domain.builder.FetchArtifactBuilder) BuildWork(com.thoughtworks.go.remote.work.BuildWork) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial)

Example 32 with Builder

use of com.thoughtworks.go.domain.builder.Builder in project gocd by gocd.

the class AntTaskBuilderTest method shouldFailWhenTargetDoesNotExist.

@Test
public void shouldFailWhenTargetDoesNotExist() {
    String target = "not-exist-target";
    String buildXml = "./build.xml";
    antTask.setBuildFile(buildXml);
    antTask.setTarget(target);
    Builder builder = antTaskBuilder.createBuilder(builderFactory, antTask, TasksTest.pipelineStub(PIPELINE_LABEL, "."), resolver);
    try {
        builder.build(new StubGoPublisher(), new EnvironmentVariableContext(), taskEntension, null, null, "utf-8");
    } catch (CruiseControlException e) {
        assertThat(e.getMessage(), containsString("Build failed. Command ant reported [BUILD FAILED]."));
    }
}
Also used : StubGoPublisher(com.thoughtworks.go.domain.StubGoPublisher) CruiseControlException(com.thoughtworks.go.util.command.CruiseControlException) CommandBuilder(com.thoughtworks.go.domain.builder.CommandBuilder) Builder(com.thoughtworks.go.domain.builder.Builder) StringContains.containsString(org.hamcrest.core.StringContains.containsString) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test) TasksTest(com.thoughtworks.go.domain.TasksTest)

Example 33 with Builder

use of com.thoughtworks.go.domain.builder.Builder in project gocd by gocd.

the class KillAllChildProcessTaskBuilderTest method builderReturnedByThisTaskBuilderShouldBeSerializable.

@Test
public void builderReturnedByThisTaskBuilderShouldBeSerializable() throws Exception {
    KillAllChildProcessTaskBuilder killAllChildProcessTaskBuilder = new KillAllChildProcessTaskBuilder();
    Builder builder = killAllChildProcessTaskBuilder.createBuilder(null, null, null, null);
    new ObjectOutputStream(new StringOutputStream()).writeObject(builder);
}
Also used : StringOutputStream(com.thoughtworks.studios.shine.io.StringOutputStream) Builder(com.thoughtworks.go.domain.builder.Builder) ObjectOutputStream(java.io.ObjectOutputStream) Test(org.junit.Test)

Example 34 with Builder

use of com.thoughtworks.go.domain.builder.Builder in project gocd by gocd.

the class KillAllChildProcessTaskBuilderTest method shouldKillAllChildProcessOnbuild.

// 11 minutes
@Test(timeout = 11 * 60 * 1000)
public void shouldKillAllChildProcessOnbuild() throws Exception {
    ProcessWrapper processWrapper = CommandLine.createCommandLine("sleep").withArg(String.valueOf(10 * 60)).withEncoding("utf-8").execute(ProcessOutputStreamConsumer.inMemoryConsumer(), new EnvironmentVariableContext(), // 60 mins
    null);
    assertThat(processWrapper.isRunning(), is(true));
    DefaultGoPublisher publisher = mock(DefaultGoPublisher.class);
    EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
    long before = getSystemTime();
    Builder builder = new KillAllChildProcessTaskBuilder().createBuilder(builderFactory, new KillAllChildProcessTask(), null, null);
    builder.build(publisher, environmentVariableContext, null, null, null, "utf-8");
    assertThat(processWrapper.waitForExit(), is(greaterThan(0)));
    // min = 10; sec = 60*min; mills = 1000*sec; micro = 1000*mills; nano = 1000*micro;
    assertThat(getSystemTime() - before, is(lessThan(10 * 60 * 1000 * 1000 * 1000L)));
}
Also used : ProcessWrapper(com.thoughtworks.go.util.ProcessWrapper) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) Builder(com.thoughtworks.go.domain.builder.Builder) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) KillAllChildProcessTask(com.thoughtworks.go.domain.KillAllChildProcessTask) Test(org.junit.Test)

Example 35 with Builder

use of com.thoughtworks.go.domain.builder.Builder in project gocd by gocd.

the class PluggableTaskBuilderCreatorTest method shouldCreateBuilderWithAReasonableDescription.

@Test
public void shouldCreateBuilderWithAReasonableDescription() throws Exception {
    Builder builder = pluggableTaskBuilderCreator.createBuilder(builderFactory, pluggableTask, pipeline, resolver);
    assertThat(builder.getDescription(), is("Plugin with ID: test-plugin-id"));
}
Also used : PluggableTaskBuilder(com.thoughtworks.go.domain.builder.pluggableTask.PluggableTaskBuilder) Builder(com.thoughtworks.go.domain.builder.Builder) Test(org.junit.Test) TasksTest(com.thoughtworks.go.domain.TasksTest)

Aggregations

Builder (com.thoughtworks.go.domain.builder.Builder)36 CommandBuilder (com.thoughtworks.go.domain.builder.CommandBuilder)13 Test (org.junit.Test)12 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)9 NullBuilder (com.thoughtworks.go.domain.builder.NullBuilder)8 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)6 File (java.io.File)6 ArrayList (java.util.ArrayList)6 Pipeline (com.thoughtworks.go.domain.Pipeline)5 TasksTest (com.thoughtworks.go.domain.TasksTest)5 FetchArtifactBuilder (com.thoughtworks.go.domain.builder.FetchArtifactBuilder)5 ArtifactStores (com.thoughtworks.go.config.ArtifactStores)4 PluggableTaskBuilder (com.thoughtworks.go.domain.builder.pluggableTask.PluggableTaskBuilder)4 ExecTask (com.thoughtworks.go.config.ExecTask)3 FetchPluggableArtifactBuilder (com.thoughtworks.go.domain.builder.FetchPluggableArtifactBuilder)3 JobResult (com.thoughtworks.go.domain.JobResult)2 RunIfConfigs (com.thoughtworks.go.domain.RunIfConfigs)2 StubGoPublisher (com.thoughtworks.go.domain.StubGoPublisher)2 StubBuilder (com.thoughtworks.go.domain.builder.StubBuilder)2 BuildWork (com.thoughtworks.go.remote.work.BuildWork)2