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));
}
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"));
}
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());
}
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));
}
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));
}
Aggregations