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