Search in sources :

Example 91 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class InstanceFactoryTest method shouldClear_DatabaseIds_State_and_Result_ForJobObjectHierarchy.

@Test
public void shouldClear_DatabaseIds_State_and_Result_ForJobObjectHierarchy() {
    Date old = new DateTime().minusDays(2).toDate();
    JobInstance rails = jobInstance(old, "rails", 7, 10);
    JobInstance java = jobInstance(old, "java", 12, 22);
    Stage stage = stage(9, rails, java);
    assertThat(stage.hasRerunJobs(), CoreMatchers.is(false));
    Stage newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails"), new DefaultSchedulingContext("loser", new Agents()), StageConfigMother.custom("dev", "rails", "java"), new TimeProvider(), "md5");
    assertThat(stage.hasRerunJobs(), CoreMatchers.is(false));
    assertThat(newStage.getId(), CoreMatchers.is(-1l));
    assertThat(newStage.getJobInstances().size(), CoreMatchers.is(2));
    assertThat(newStage.isLatestRun(), CoreMatchers.is(true));
    JobInstance newRails = newStage.getJobInstances().getByName("rails");
    assertNewJob(old, newRails);
    JobInstance newJava = newStage.getJobInstances().getByName("java");
    assertCopiedJob(newJava, 12l);
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 92 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class InstanceFactoryTest method shouldCreatePipelineInstanceWithEnvironmentVariablesOverriddenAccordingToScope.

@Test
public void shouldCreatePipelineInstanceWithEnvironmentVariablesOverriddenAccordingToScope() {
    StageConfig stageConfig = StageConfigMother.custom("stage", "foo", "bar");
    JobConfig fooConfig = stageConfig.jobConfigByConfigName(new CaseInsensitiveString("foo"));
    fooConfig.addVariable("foo", "foo");
    JobConfig barConfig = stageConfig.jobConfigByConfigName(new CaseInsensitiveString("bar"));
    barConfig.addVariable("foo", "bar");
    MaterialConfigs materialConfigs = MaterialConfigsMother.defaultMaterialConfigs();
    PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("pipeline"), materialConfigs, stageConfig);
    DefaultSchedulingContext context = new DefaultSchedulingContext("anonymous");
    Pipeline instance = instanceFactory.createPipelineInstance(pipelineConfig, ModificationsMother.forceBuild(pipelineConfig), context, "some-md5", new TimeProvider());
    assertThat(instance.findStage("stage").findJob("foo").getPlan().getVariables(), is(new EnvironmentVariables(Arrays.asList(new EnvironmentVariable("foo", "foo")))));
    assertThat(instance.findStage("stage").findJob("bar").getPlan().getVariables(), is(new EnvironmentVariables(Arrays.asList(new EnvironmentVariable("foo", "bar")))));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 93 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class InstanceFactoryTest method shouldCreateAJobForEachAgentIfRunOnAllAgentsIsTrue.

/*
	RunOnAllAgents tests
	*/
@Test
public void shouldCreateAJobForEachAgentIfRunOnAllAgentsIsTrue() throws Exception {
    Agents agents = new Agents();
    agents.add(new AgentConfig("uuid1"));
    agents.add(new AgentConfig("uuid2"));
    JobConfig jobConfig = new JobConfig("foo");
    jobConfig.setRunOnAllAgents(true);
    SchedulingContext context = mock(SchedulingContext.class);
    when(context.getApprovedBy()).thenReturn("chris");
    when(context.findAgentsMatching(new ResourceConfigs())).thenReturn(agents);
    when(context.getEnvironmentVariablesConfig()).thenReturn(new EnvironmentVariablesConfig());
    when(context.overrideEnvironmentVariables(any(EnvironmentVariablesConfig.class))).thenReturn(context);
    RunOnAllAgents.CounterBasedJobNameGenerator jobNameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(jobConfig.name()));
    JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("stageName"), jobConfig, context, new TimeProvider(), jobNameGenerator);
    assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is("foo-runOnAll-1"))));
    assertThat(jobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid1"))));
    assertThat(jobs.toArray(), hasItemInArray(hasProperty("runOnAllAgents", is(true))));
    assertThat(jobs.toArray(), hasItemInArray(hasProperty("name", is("foo-runOnAll-1"))));
    assertThat(jobs.toArray(), hasItemInArray(hasProperty("agentUuid", is("uuid2"))));
    assertThat(jobs.toArray(), hasItemInArray(hasProperty("runOnAllAgents", is(true))));
    assertThat(jobs.size(), is(2));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 94 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class InstanceFactoryTest method shouldSetManualApprovalOnStageInstance.

@Test
public void shouldSetManualApprovalOnStageInstance() {
    StageConfig stageConfig = StageConfigMother.custom("test", Approval.manualApproval());
    Stage instance = instanceFactory.createStageInstance(stageConfig, new DefaultSchedulingContext("anyone"), "md5", new TimeProvider());
    assertThat(instance.getApprovalType(), is(GoConstants.APPROVAL_MANUAL));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 95 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class InstanceFactoryTest method shouldNotRerun_WhenJobConfigIsChangedToRunMultipleInstance_ForSingleJobInstance.

@Test
public void shouldNotRerun_WhenJobConfigIsChangedToRunMultipleInstance_ForSingleJobInstance() {
    Date old = new DateTime().minusDays(2).toDate();
    StageConfig stageConfig = StageConfigMother.custom("dev", "rails", "java");
    JobConfig railsConfig = stageConfig.getJobs().getJob(new CaseInsensitiveString("rails"));
    DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("loser", new Agents());
    JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("dev"), railsConfig, schedulingContext, new TimeProvider(), null);
    Stage stage = createStageInstance(old, jobs);
    Stage newStage = null;
    railsConfig.setRunInstanceCount(10);
    CannotRerunJobException exception = null;
    try {
        newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails"), schedulingContext, stageConfig, new TimeProvider(), "md5");
        fail("should not schedule since job config changed to run multiple instance");
    } catch (CannotRerunJobException e) {
        exception = e;
    }
    assertThat(exception.getJobName(), is("rails"));
    assertThat(exception.getInformation(), is("Run configuration for job has been changed to 'run multiple instance'."));
    assertThat(newStage, is(nullValue()));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

TimeProvider (com.thoughtworks.go.util.TimeProvider)177 Test (org.junit.Test)122 Date (java.util.Date)29 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)28 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)25 DateTime (org.joda.time.DateTime)18 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)16 GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)13 Username (com.thoughtworks.go.server.domain.Username)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 Before (org.junit.Before)13 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)11 Materials (com.thoughtworks.go.config.materials.Materials)10 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 TransactionStatus (org.springframework.transaction.TransactionStatus)9 Material (com.thoughtworks.go.domain.materials.Material)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)6