Search in sources :

Example 1 with TimelineUpdateListener

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));
}
Also used : TimelineUpdateListener(com.thoughtworks.go.listener.TimelineUpdateListener) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry) Test(org.junit.Test)

Example 2 with TimelineUpdateListener

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);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) TimelineUpdateListener(com.thoughtworks.go.listener.TimelineUpdateListener) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 3 with TimelineUpdateListener

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));
}
Also used : TimelineUpdateListener(com.thoughtworks.go.listener.TimelineUpdateListener) PipelineTimelineEntry(com.thoughtworks.go.domain.PipelineTimelineEntry) Test(org.junit.Test)

Aggregations

PipelineTimelineEntry (com.thoughtworks.go.domain.PipelineTimelineEntry)3 TimelineUpdateListener (com.thoughtworks.go.listener.TimelineUpdateListener)3 Test (org.junit.Test)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1