Search in sources :

Example 86 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobInstanceStatusMonitorTest method shouldSendCancelMessageIfJobIsRescheduled.

@Test
public void shouldSendCancelMessageIfJobIsRescheduled() throws Exception {
    AgentConfig agentConfig = AgentMother.remoteAgent();
    configHelper.addAgent(agentConfig);
    fixture.createPipelineWithFirstStageScheduled();
    AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
    info.setCookie("cookie");
    agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
    buildAssignmentService.onTimer();
    assertThat(agent.messages.size(), is(1));
    assertThat(MessageEncoding.decodeWork(agent.messages.get(0).getData()), instanceOf(BuildWork.class));
    BuildWork work = (BuildWork) MessageEncoding.decodeWork(agent.messages.get(0).getData());
    JobPlan jobPlan = work.getAssignment().getPlan();
    final JobInstance instance = jobInstanceService.buildByIdWithTransitions(jobPlan.getJobId());
    scheduleService.rescheduleJob(instance);
    assertThat(agent.messages.size(), is(2));
    assertThat(agent.messages.get(1).getAction(), is(Action.cancelBuild));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Message(com.thoughtworks.go.websocket.Message) JobPlan(com.thoughtworks.go.domain.JobPlan) JobInstance(com.thoughtworks.go.domain.JobInstance) BuildWork(com.thoughtworks.go.remote.work.BuildWork)

Example 87 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobControllerTest method shouldFindTheLatestJobWhenJobStatusIsRequested.

@Test
public void shouldFindTheLatestJobWhenJobStatusIsRequested() throws Exception {
    JobInstance job = JobInstanceMother.buildEndingWithState(JobState.Rescheduled, JobResult.Unknown, "config");
    job.assign("agent", new Date());
    JobInstance newJob = JobInstanceMother.buildEndingWithState(JobState.Building, JobResult.Unknown, "another_config");
    newJob.setId(2);
    newJob.assign("another_agent", new Date());
    String pipelineName = job.getPipelineName();
    String stageName = job.getStageName();
    when(jobInstanceService.buildByIdWithTransitions(job.getId())).thenReturn(job);
    when(jobDetailService.findMostRecentBuild(job.getIdentifier())).thenReturn(newJob);
    when(stageService.getBuildDuration(pipelineName, stageName, newJob)).thenReturn(new DurationBean(newJob.getId(), 5l));
    ModelAndView modelAndView = jobController.handleRequest(pipelineName, stageName, job.getId(), response);
    verify(jobInstanceService).buildByIdWithTransitions(job.getId());
    verify(jobDetailService).findMostRecentBuild(job.getIdentifier());
    verify(stageService).getBuildDuration(pipelineName, stageName, newJob);
    JsonValue json = from(((List) modelAndView.getModel().get("json")).get(0));
    JsonValue buildingInfo = json.getObject("building_info");
    assertThat(buildingInfo.getString("id"), is("2"));
    assertThat(buildingInfo.getString("last_build_duration"), is("5"));
}
Also used : DurationBean(com.thoughtworks.go.dto.DurationBean) JobInstance(com.thoughtworks.go.domain.JobInstance) ModelAndView(org.springframework.web.servlet.ModelAndView) JsonValue(com.thoughtworks.go.util.JsonValue) Date(java.util.Date) Test(org.junit.Test)

Example 88 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobResourceImporterTest method testArtifactsAreImported.

@Test
public void testArtifactsAreImported() throws Exception {
    Clock.fakeNowUTC(2008, 1, 20, 0, 0, 1);
    JobInstance failedJob = JobInstanceMother.failed("test");
    Document document = docFor(happyJobResourceXML);
    document.selectSingleNode("//link[@rel='self']/@href").setText(new JobXmlViewModel(failedJob).httpUrl(baseUri));
    when(xmlApiService.write(any(JobXmlViewModel.class), eq(baseUri))).thenReturn(document);
    JobResourceImporter rdfImporter = new JobResourceImporter("test/data/cruise/artifacts", new InMemoryTempGraphFactory(), transformerRegistry, xmlApiService, systemEnvironment);
    Graph graph = rdfImporter.importJob(failedJob, baseUri);
    String testCountSelect = "PREFIX xunit: <" + XUnitOntology.URI + "> SELECT ?testcase WHERE { ?testCase a xunit:TestCase }";
    assertEquals(5, graph.select(testCountSelect).size());
}
Also used : Graph(com.thoughtworks.studios.shine.semweb.Graph) JobInstance(com.thoughtworks.go.domain.JobInstance) JobXmlViewModel(com.thoughtworks.go.server.domain.xml.JobXmlViewModel) Document(org.dom4j.Document) InMemoryTempGraphFactory(com.thoughtworks.studios.shine.semweb.sesame.InMemoryTempGraphFactory) Test(org.junit.Test)

Example 89 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobInstanceModelTest method job.

private JobInstanceModel job(int elapsedSeconds, int etaSeconds) {
    TestingClock clock = new TestingClock();
    JobInstance instance = JobInstanceMother.building("job", clock.currentTime());
    instance.setClock(clock);
    clock.addSeconds(elapsedSeconds);
    return new JobInstanceModel(instance, new JobDurationStrategy.ConstantJobDuration(etaSeconds * 1000));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobDurationStrategy(com.thoughtworks.go.server.domain.JobDurationStrategy) TestingClock(com.thoughtworks.go.util.TestingClock)

Example 90 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class StageSummaryModelTest method shouldRetrivePercentCompleteOnJobs.

@Test
public void shouldRetrivePercentCompleteOnJobs() throws Exception {
    JobInstance first = JobInstanceMother.completed("first", JobResult.Failed);
    Stage stage = StageMother.custom("pipeline", "stage", new JobInstances(first));
    StageSummaryModel model = new StageSummaryModel(stage, new Stages(stage), new JobDurationStrategy.ConstantJobDuration(1000 * 1000), null);
    assertThat(model.nonPassedJobs().get(0).getElapsedTime(), is(new Duration(120 * 1000)));
    assertThat(model.nonPassedJobs().get(0).getPercentComplete(), is(12));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) Stages(com.thoughtworks.go.domain.Stages) Stage(com.thoughtworks.go.domain.Stage) JobDurationStrategy(com.thoughtworks.go.server.domain.JobDurationStrategy) Duration(org.joda.time.Duration) JobInstances(com.thoughtworks.go.domain.JobInstances) Test(org.junit.Test)

Aggregations

JobInstance (com.thoughtworks.go.domain.JobInstance)90 Test (org.junit.Test)65 Stage (com.thoughtworks.go.domain.Stage)23 Pipeline (com.thoughtworks.go.domain.Pipeline)22 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)16 JobInstances (com.thoughtworks.go.domain.JobInstances)11 JobConfigIdentifier (com.thoughtworks.go.domain.JobConfigIdentifier)10 Stages (com.thoughtworks.go.domain.Stages)5 JsonTester (com.thoughtworks.go.util.JsonTester)5 Map (java.util.Map)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 AgentConfig (com.thoughtworks.go.config.AgentConfig)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 Date (java.util.Date)4 ArtifactPropertiesGenerator (com.thoughtworks.go.config.ArtifactPropertiesGenerator)3 Resource (com.thoughtworks.go.config.Resource)3 DirectoryEntries (com.thoughtworks.go.domain.DirectoryEntries)3 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)3 ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)3 StageDao (com.thoughtworks.go.server.dao.StageDao)3