Search in sources :

Example 6 with PipelineTimelineEntry

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

the class PipelineHistoryService method populatePreviousStageState.

private void populatePreviousStageState(PipelineInstanceModel activePipeline) {
    if (activePipeline.isAnyStageActive()) {
        StageInstanceModel activeStage = activePipeline.activeStage();
        StageInstanceModel latestActive = null;
        long id = activePipeline.getId();
        do {
            PipelineTimelineEntry timelineEntry = pipelineTimeline.runBefore(id, new CaseInsensitiveString(activePipeline.getName()));
            if (timelineEntry == null) {
                break;
            }
            id = timelineEntry.getId();
            PipelineInstanceModel instanceModel = pipelineDao.loadHistory(id);
            if (instanceModel != null && instanceModel.hasStageBeenRun(activeStage.getName())) {
                latestActive = instanceModel.getStageHistory().byName(activeStage.getName());
            }
        } while (latestActive == null);
        activeStage.setPreviousStage(latestActive);
    }
}
Also used : PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry)

Example 7 with PipelineTimelineEntry

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

the class PipelineMaterialModificationTest method shouldReturn0IfComparedToItself.

@Test
public void shouldReturn0IfComparedToItself() throws Exception {
    DateTime now = new DateTime();
    PipelineTimelineEntry self = modification(Arrays.asList("flyweight"), 1, "123", now);
    assertThat(self.compareTo(self), is(0));
    PipelineTimelineEntry another = modification(Arrays.asList("flyweight"), 1, "123", now);
    assertThat(self.compareTo(another), is(0));
    assertThat(another.compareTo(self), is(0));
}
Also used : PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 8 with PipelineTimelineEntry

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

the class PipelineTimelineTest method assertBeforeAfter.

private void assertBeforeAfter(PipelineTimeline mods, PipelineTimelineEntry actual, PipelineTimelineEntry before, PipelineTimelineEntry after) {
    PipelineTimelineEntry actualBefore = mods.runBefore(actual.getId(), new CaseInsensitiveString(pipelineName));
    PipelineTimelineEntry actualAfter = mods.runAfter(actual.getId(), new CaseInsensitiveString(pipelineName));
    assertEquals("Expected " + before + " to be before " + actual + ". Got " + actualBefore, actualBefore, before);
    assertEquals("Expected " + after + " to be after " + actual + ". Got " + actualAfter, actualAfter, after);
}
Also used : PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 9 with PipelineTimelineEntry

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

the class PipelineTimelineTest method updateShouldNotifyListenersOnAddition.

@Test
public void updateShouldNotifyListenersOnAddition() throws Exception {
    stubTransactionSynchronization();
    setupTransactionTemplateStub(TransactionSynchronization.STATUS_COMMITTED, true);
    final List<PipelineTimelineEntry>[] entries = new List[1];
    entries[0] = new ArrayList<>();
    final PipelineTimeline timeline = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager, new TimelineUpdateListener() {

        public void added(PipelineTimelineEntry newlyAddedEntry, TreeSet<PipelineTimelineEntry> timeline) {
            assertThat(timeline.contains(newlyAddedEntry), is(true));
            assertThat(timeline.containsAll(entries[0]), is(true));
            entries[0].add(newlyAddedEntry);
        }
    });
    stubPipelineRepository(timeline, true, new PipelineTimelineEntry[] { first, second });
    timeline.update();
    assertThat(entries[0].size(), is(1));
    assertThat(entries[0].contains(first), is(true));
}
Also used : TimelineUpdateListener(com.thoughtworks.go.listener.TimelineUpdateListener) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry) Test(org.junit.Test)

Example 10 with PipelineTimelineEntry

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

the class PipelineRepositoryIntegrationTest method shouldConsider_firstRevision_forAFlyweight_asInDb_whilePickingFromMultipleDeclarations.

@Test
public void shouldConsider_firstRevision_forAFlyweight_asInDb_whilePickingFromMultipleDeclarations() {
    ScheduleTestUtil u = new ScheduleTestUtil(transactionTemplate, materialRepository, dbHelper, configHelper);
    int i = 1;
    GitMaterial git1 = u.wf(new GitMaterial("git"), "folder1");
    u.checkinInOrder(git1, "g1");
    GitMaterial git2 = u.wf(new GitMaterial("git"), "folder2");
    ScheduleTestUtil.AddedPipeline p = u.saveConfigWith("P", u.m(git1), u.m(git2));
    CruiseConfig cruiseConfig = goConfigDao.load();
    u.checkinInOrder(git1, u.d(i++), "g2");
    u.runAndPass(p, "g1", "g2");
    u.runAndPass(p, "g2", "g1");
    PipelineTimeline timeline = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
    timeline.updateTimelineOnInit();
    List<PipelineTimelineEntry> timelineEntries = new ArrayList<>(timeline.getEntriesFor("P"));
    assertThat(timelineEntries.get(0).getPipelineLocator().getCounter(), is(1));
    assertThat(timelineEntries.get(0).naturalOrder(), is(1.0));
    List<PipelineTimelineEntry.Revision> flyweightsRevs = new ArrayList<>(timelineEntries.get(0).revisions().values()).get(0);
    assertThat(flyweightsRevs.get(0).revision, is("g1"));
    assertThat(flyweightsRevs.get(1).revision, is("g2"));
    assertThat(timelineEntries.get(1).getPipelineLocator().getCounter(), is(2));
    assertThat(timelineEntries.get(1).naturalOrder(), is(2.0));
    flyweightsRevs = new ArrayList<>(timelineEntries.get(1).revisions().values()).get(0);
    assertThat(flyweightsRevs.get(0).revision, is("g2"));
    assertThat(flyweightsRevs.get(1).revision, is("g1"));
    MaterialConfigs materials = CLONER.deepClone(p.config.materialConfigs());
    Collections.reverse(materials);
    configHelper.setMaterialConfigForPipeline("P", materials.toArray(new MaterialConfig[0]));
    goConfigDao.load();
    timeline = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager);
    timeline.updateTimelineOnInit();
    timelineEntries = new ArrayList<>(timeline.getEntriesFor("P"));
    assertThat(timelineEntries.get(0).getPipelineLocator().getCounter(), is(1));
    assertThat(timelineEntries.get(0).naturalOrder(), is(1.0));
    flyweightsRevs = new ArrayList<>(timelineEntries.get(0).revisions().values()).get(0);
    assertThat(flyweightsRevs.get(0).revision, is("g1"));
    assertThat(flyweightsRevs.get(1).revision, is("g2"));
    assertThat(timelineEntries.get(1).getPipelineLocator().getCounter(), is(2));
    assertThat(timelineEntries.get(1).naturalOrder(), is(2.0));
    flyweightsRevs = new ArrayList<>(timelineEntries.get(1).revisions().values()).get(0);
    assertThat(flyweightsRevs.get(0).revision, is("g2"));
    assertThat(flyweightsRevs.get(1).revision, is("g1"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) ArrayList(java.util.ArrayList) PipelineTimeline(com.thoughtworks.go.server.domain.PipelineTimeline) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) ScheduleTestUtil(com.thoughtworks.go.server.service.ScheduleTestUtil) Test(org.junit.Test)

Aggregations

PipelineTimelineEntry (com.thoughtworks.go.domain.PipelineTimelineEntry)31 Test (org.junit.Test)18 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 ArrayList (java.util.ArrayList)11 DateTime (org.joda.time.DateTime)11 PipelineTimeline (com.thoughtworks.go.server.domain.PipelineTimeline)9 List (java.util.List)6 Date (java.util.Date)5 BigInteger (java.math.BigInteger)4 Map (java.util.Map)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)3 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)3 TimelineUpdateListener (com.thoughtworks.go.listener.TimelineUpdateListener)3 HashMap (java.util.HashMap)3 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)2 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)2 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)2 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)2 DependencyMaterialRevision (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialRevision)2 PipelineConfigMother.createPipelineConfig (com.thoughtworks.go.helper.PipelineConfigMother.createPipelineConfig)2