Search in sources :

Example 41 with TimeProvider

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

the class InstanceFactoryTest method should_MaintainRerunOfReferences_InCaseOfMultipleCopyForRerunOperations.

@Test
public void should_MaintainRerunOfReferences_InCaseOfMultipleCopyForRerunOperations() {
    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);
    stage.setCounter(2);
    Stage newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails"), new DefaultSchedulingContext("loser", new Agents()), StageConfigMother.custom("dev", "rails", "java"), new TimeProvider(), "md5");
    newStage.setCounter(3);
    assertThat(newStage.getId(), CoreMatchers.is(-1l));
    assertThat(newStage.getJobInstances().size(), CoreMatchers.is(2));
    assertThat(newStage.isLatestRun(), CoreMatchers.is(true));
    assertThat(newStage.getRerunOfCounter(), CoreMatchers.is(2));
    JobInstance newJava = newStage.getJobInstances().getByName("java");
    assertCopiedJob(newJava, 12l);
    // set id, to assert if original ends up pointing to copied job's id
    newJava.setId(18l);
    newStage = instanceFactory.createStageForRerunOfJobs(newStage, a("rails"), new DefaultSchedulingContext("loser", new Agents()), StageConfigMother.custom("dev", "rails", "java"), new TimeProvider(), "md5");
    newStage.setCounter(4);
    assertThat(newStage.getId(), CoreMatchers.is(-1l));
    assertThat(newStage.getJobInstances().size(), CoreMatchers.is(2));
    assertThat(newStage.isLatestRun(), CoreMatchers.is(true));
    assertThat(newStage.getRerunOfCounter(), CoreMatchers.is(2));
    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 42 with TimeProvider

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

the class InstanceFactoryTest method shouldBomb_ForRerun_OfASingleInstanceJobType_WhichWasEarlierRunOnAll_WithTwoRunOnAllInstancesSelectedForRerun.

@Test
public void shouldBomb_ForRerun_OfASingleInstanceJobType_WhichWasEarlierRunOnAll_WithTwoRunOnAllInstancesSelectedForRerun() {
    Date old = new DateTime().minusDays(2).toDate();
    StageConfig stageConfig = StageConfigMother.custom("dev", "rails", "java");
    JobConfig railsConfig = stageConfig.getJobs().getJob(new CaseInsensitiveString("rails"));
    railsConfig.setRunOnAllAgents(true);
    railsConfig.addResourceConfig("foobar");
    DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("loser", new Agents(new AgentConfig("abcd1234", "host", "127.0.0.2", new ResourceConfigs(new ResourceConfig("foobar"))), new AgentConfig("1234abcd", "ghost", "192.168.1.2", new ResourceConfigs(new ResourceConfig("baz"), new ResourceConfig("foobar"))), new AgentConfig("7890abdc", "lost", "10.4.3.55", new ResourceConfigs(new ResourceConfig("crapyagent")))));
    RunOnAllAgents.CounterBasedJobNameGenerator jobNameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(railsConfig.name()));
    JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("dev"), railsConfig, schedulingContext, new TimeProvider(), jobNameGenerator);
    Stage stage = createStageInstance(old, jobs);
    railsConfig.setRunOnAllAgents(false);
    try {
        instanceFactory.createStageForRerunOfJobs(stage, a("rails-runOnAll-1", "rails-runOnAll-2"), schedulingContext, stageConfig, new TimeProvider(), "md5");
        fail("should have failed when multiple run on all agents jobs are selected when job-config does not have run on all flag anymore");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), CoreMatchers.is("Cannot schedule multiple instances of job named 'rails'."));
    }
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 43 with TimeProvider

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

the class InstanceFactoryTest method should_NOT_ClearAgentAssignment_ForRerun_OfASingleInstanceJobType_WhichWasEarlierRunOnAll.

@Test
public void should_NOT_ClearAgentAssignment_ForRerun_OfASingleInstanceJobType_WhichWasEarlierRunOnAll() {
    Date old = new DateTime().minusDays(2).toDate();
    StageConfig stageConfig = StageConfigMother.custom("dev", "rails", "java");
    JobConfig railsConfig = stageConfig.getJobs().getJob(new CaseInsensitiveString("rails"));
    railsConfig.setRunOnAllAgents(true);
    railsConfig.addResourceConfig("foobar");
    DefaultSchedulingContext schedulingContext = new DefaultSchedulingContext("loser", new Agents(new AgentConfig("abcd1234", "host", "127.0.0.2", new ResourceConfigs(new ResourceConfig("foobar"))), new AgentConfig("1234abcd", "ghost", "192.168.1.2", new ResourceConfigs(new ResourceConfig("baz"), new ResourceConfig("foobar"))), new AgentConfig("7890abdc", "lost", "10.4.3.55", new ResourceConfigs(new ResourceConfig("crapyagent")))));
    RunOnAllAgents.CounterBasedJobNameGenerator jobNameGenerator = new RunOnAllAgents.CounterBasedJobNameGenerator(CaseInsensitiveString.str(railsConfig.name()));
    JobInstances jobs = instanceFactory.createJobInstance(new CaseInsensitiveString("dev"), railsConfig, schedulingContext, new TimeProvider(), jobNameGenerator);
    Stage stage = createStageInstance(old, jobs);
    railsConfig.setRunOnAllAgents(false);
    Stage newStage = instanceFactory.createStageForRerunOfJobs(stage, a("rails-runOnAll-1"), schedulingContext, stageConfig, new TimeProvider(), "md5");
    assertThat(newStage.getJobInstances().size(), CoreMatchers.is(3));
    JobInstance newRailsJob = newStage.getJobInstances().getByName("rails");
    assertNewJob(old, newRailsJob);
    assertThat(newRailsJob.getAgentUuid(), CoreMatchers.is("abcd1234"));
    JobInstance copiedRailsJob = newStage.getJobInstances().getByName("rails-runOnAll-2");
    assertCopiedJob(copiedRailsJob, 102l);
    assertThat(copiedRailsJob.getAgentUuid(), CoreMatchers.is("1234abcd"));
    JobInstance copiedJavaJob = newStage.getJobInstances().getByName("java");
    assertCopiedJob(copiedJavaJob, 12l);
    assertThat(copiedJavaJob.getAgentUuid(), CoreMatchers.is(not(nullValue())));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 44 with TimeProvider

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

the class GoConfigRevisionTest method shouldUnderstandEquality.

@Test
public void shouldUnderstandEquality() {
    GoConfigRevision rev1 = new GoConfigRevision("blah", "md5", "loser", "2.2.2", new TimeProvider());
    GoConfigRevision rev2 = new GoConfigRevision("blah blah", "md5", "loser 2", "2.2.3", new TimeProvider());
    assertThat(rev1, is(rev2));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 45 with TimeProvider

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

the class GoConfigAdministrationControllerTest method shouldLoadSpecificConfigVersionWhenHistoricalVersionIsRequested.

@Test
public void shouldLoadSpecificConfigVersionWhenHistoricalVersionIsRequested() throws Exception {
    MockHttpServletResponse response = new MockHttpServletResponse();
    String configXml = "config-content";
    when(goConfigService.getConfigAtVersion("some-md5")).thenReturn(new GoConfigRevision(configXml, "some-md5", "loser", "100.9.3.1", new TimeProvider()));
    controller.getConfigRevision("some-md5", response);
    assertThat(response.getContentAsString(), is(configXml));
    assertThat(response.getHeader(XmlAction.X_CRUISE_CONFIG_MD5).toString(), is("some-md5"));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) 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