use of com.thoughtworks.go.listener.TimelineUpdateListener 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.listener.TimelineUpdateListener in project gocd by gocd.
the class PipelineTimeline method notifyListeners.
// --------------------------------------------------------
private void notifyListeners(List<PipelineTimelineEntry> newEntries) {
Map<CaseInsensitiveString, PipelineTimelineEntry> pipelineToOldestEntry = new HashMap<>();
for (PipelineTimelineEntry challenger : newEntries) {
CaseInsensitiveString pipelineName = new CaseInsensitiveString(challenger.getPipelineName());
PipelineTimelineEntry champion = pipelineToOldestEntry.get(pipelineName);
if (champion == null || challenger.compareTo(champion) < 0) {
pipelineToOldestEntry.put(pipelineName, challenger);
}
}
for (TimelineUpdateListener listener : listeners) {
for (Map.Entry<CaseInsensitiveString, PipelineTimelineEntry> entry : pipelineToOldestEntry.entrySet()) {
try {
listener.added(entry.getValue(), naturalOrderPmm.get(entry.getKey()));
} catch (Exception e) {
LOGGER.warn("Ignoring exception when notifying listener: " + listener, e);
}
}
}
}
use of com.thoughtworks.go.listener.TimelineUpdateListener in project gocd by gocd.
the class PipelineTimelineTest method updateShouldIgnoreExceptionThrownByListenersDuringNotifications.
@Test
public void updateShouldIgnoreExceptionThrownByListenersDuringNotifications() throws Exception {
stubTransactionSynchronization();
setupTransactionTemplateStub(TransactionSynchronization.STATUS_COMMITTED, true);
TimelineUpdateListener anotherListener = mock(TimelineUpdateListener.class);
final PipelineTimeline timeline = new PipelineTimeline(pipelineRepository, transactionTemplate, transactionSynchronizationManager, new TimelineUpdateListener() {
public void added(PipelineTimelineEntry newlyAddedEntry, TreeSet<PipelineTimelineEntry> timeline) {
throw new RuntimeException();
}
}, anotherListener);
stubPipelineRepository(timeline, true, new PipelineTimelineEntry[] { first, second });
try {
timeline.update();
} catch (Exception e) {
fail("should not have failed because of exception thrown by listener");
}
verify(anotherListener).added(eq(first), any(TreeSet.class));
}
Aggregations