Search in sources :

Example 41 with JobInstance

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

the class CcTrayJobStatusChangeHandlerTest method shouldUpdateValueInCacheWhenJobHasChanged.

@Test
public void shouldUpdateValueInCacheWhenJobHasChanged() throws Exception {
    String jobName = "job1";
    ProjectStatus existingStatusInCache = new ProjectStatus(projectNameFor(jobName), "OldActivity", "OldStatus", "OldLabel", new Date(), webUrlFor(jobName));
    when(cache.get(projectNameFor(jobName))).thenReturn(existingStatusInCache);
    CcTrayJobStatusChangeHandler handler = new CcTrayJobStatusChangeHandler(cache);
    JobInstance completedJob = JobInstanceMother.completed(jobName);
    handler.call(completedJob);
    verify(cache).put(statusCaptor.capture());
    ProjectStatus newStatusInCache = statusCaptor.getValue();
    assertThat(newStatusInCache.name(), is(projectNameFor(jobName)));
    assertThat(newStatusInCache.getLastBuildStatus(), is("Success"));
    assertThat(newStatusInCache.getLastBuildLabel(), is("label-1"));
    assertThat(newStatusInCache.getLastBuildTime(), is(completedJob.getCompletedDate()));
    assertThat(newStatusInCache.getBreakers(), is(Collections.<String>emptySet()));
    assertThat(activityOf(newStatusInCache), is("Sleeping"));
    assertThat(webUrlOf(newStatusInCache), is(webUrlFor(jobName)));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) JobInstance(com.thoughtworks.go.domain.JobInstance) Date(java.util.Date) Test(org.junit.Test)

Example 42 with JobInstance

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

the class JobStatusListenerTest method setUp.

@Before
public void setUp() throws Exception {
    goCache.clear();
    dbHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao);
    configHelper.onSetUp();
    PipelineConfig pipelineConfig = withSingleStageWithMaterials(PIPELINE_NAME, STAGE_NAME, withBuildPlans(JOB_NAME));
    configHelper.addPipeline(PIPELINE_NAME, STAGE_NAME);
    savedPipeline = scheduleHelper.schedule(pipelineConfig, BuildCause.createWithModifications(modifyOneFile(pipelineConfig), ""), GoConstants.DEFAULT_APPROVED_BY);
    JobInstance job = savedPipeline.getStages().first().getJobInstances().first();
    job.setAgentUuid(UUID);
    mockery = new ClassMockery();
    stageStatusTopic = mockery.mock(StageStatusTopic.class);
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) JobInstance(com.thoughtworks.go.domain.JobInstance) ClassMockery(com.thoughtworks.go.util.ClassMockery) Before(org.junit.Before)

Example 43 with JobInstance

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

the class JobStatusCacheTest method shouldExcludeJobFromOtherPipelines.

@Test
public void shouldExcludeJobFromOtherPipelines() {
    JobInstance job1 = JobInstanceMother.instanceForRunOnAllAgents("cruise", "dev", "linux-firefox", "1", 1);
    JobInstance job2 = JobInstanceMother.instanceForRunOnAllAgents("cruise", "dev", "linux-firefox", "1", 2);
    jobStatusCache.jobStatusChanged(job1);
    jobStatusCache.jobStatusChanged(job2);
    JobInstance otherPipeline = JobInstanceMother.buildingInstance("different-pipeline", "dev", "linux-firefox", "1");
    jobStatusCache.jobStatusChanged(otherPipeline);
    JobConfigIdentifier config = new JobConfigIdentifier("cruise", "dev", "linux-firefox");
    List<JobInstance> list = jobStatusCache.currentJobs(config);
    assertThat(list, not(hasItem(otherPipeline)));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobConfigIdentifier(com.thoughtworks.go.domain.JobConfigIdentifier) Test(org.junit.Test)

Example 44 with JobInstance

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

the class JobStatusCacheTest method shouldRefreshCurrentJobWhenNewJobComes.

@Test
public void shouldRefreshCurrentJobWhenNewJobComes() {
    JobInstance job = JobInstanceMother.buildingInstance("cruise", "dev", "linux-firefox", "1");
    jobStatusCache.jobStatusChanged(job);
    assertThat(jobStatusCache.currentJob(job.getIdentifier().jobConfigIdentifier()).getState(), is(JobState.Building));
    JobInstance passing = job.clone();
    passing.changeState(JobState.Completed);
    jobStatusCache.jobStatusChanged(passing);
    assertThat(jobStatusCache.currentJob(passing.getIdentifier().jobConfigIdentifier()).getState(), is(JobState.Completed));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) Test(org.junit.Test)

Example 45 with JobInstance

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

the class PipelineWithTwoStages method createPipelineWithFirstStageAssigned.

public Pipeline createPipelineWithFirstStageAssigned(String agentId) {
    Pipeline pipeline = createPipelineWithFirstStageScheduled();
    JobInstances instances = pipeline.getStages().byName(devStage).getJobInstances();
    for (JobInstance instance : instances) {
        dbHelper.assignToAgent(instance, agentId);
    }
    return dbHelper.getPipelineDao().loadPipeline(pipeline.getId());
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) Pipeline(com.thoughtworks.go.domain.Pipeline) JobInstances(com.thoughtworks.go.domain.JobInstances)

Aggregations

JobInstance (com.thoughtworks.go.domain.JobInstance)82 Test (org.junit.Test)56 Stage (com.thoughtworks.go.domain.Stage)16 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)15 Pipeline (com.thoughtworks.go.domain.Pipeline)15 JobInstances (com.thoughtworks.go.domain.JobInstances)12 JobConfigIdentifier (com.thoughtworks.go.domain.JobConfigIdentifier)7 Agent (com.thoughtworks.go.server.domain.Agent)6 Gson (com.google.gson.Gson)5 Stages (com.thoughtworks.go.domain.Stages)5 Map (java.util.Map)5 DurationBean (com.thoughtworks.go.dto.DurationBean)4 DateTime (org.joda.time.DateTime)4 ArtifactPropertiesGenerator (com.thoughtworks.go.config.ArtifactPropertiesGenerator)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)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 JobInstanceModel (com.thoughtworks.go.server.ui.JobInstanceModel)3