Search in sources :

Example 1 with PipelineLockStatusChangeListener

use of com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener in project gocd by gocd.

the class PipelineLockServiceTest method shouldNotifyListenersAfterPipelineIsLocked.

@Test
public void shouldNotifyListenersAfterPipelineIsLocked() throws Exception {
    when(goConfigService.isLockable("pipeline1")).thenReturn(true);
    PipelineLockStatusChangeListener lockStatusChangeListener = mock(PipelineLockStatusChangeListener.class);
    Pipeline pipeline = PipelineMother.firstStageBuildingAndSecondStageScheduled("pipeline1", asList("stage1", "stage2"), asList("job1"));
    pipelineLockService.registerListener(lockStatusChangeListener);
    pipelineLockService.lockIfNeeded(pipeline);
    verify(lockStatusChangeListener).lockStatusChanged(Event.lock("pipeline1"));
}
Also used : PipelineLockStatusChangeListener(com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 2 with PipelineLockStatusChangeListener

use of com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener in project gocd by gocd.

the class PipelineLockServiceTest method shouldLogAndIgnoreAnyExceptionsWhileNotifyingListeners.

@Test
public void shouldLogAndIgnoreAnyExceptionsWhileNotifyingListeners() throws Exception {
    PipelineLockStatusChangeListener listener1 = mock(PipelineLockStatusChangeListener.class);
    PipelineLockStatusChangeListener listener2 = mock(PipelineLockStatusChangeListener.class, "ListenerWhichFails");
    doThrow(new RuntimeException("Ouch.")).when(listener2).lockStatusChanged(org.mockito.Matchers.<Event>anyObject());
    PipelineLockStatusChangeListener listener3 = mock(PipelineLockStatusChangeListener.class);
    try (LogFixture logFixture = logFixtureFor(PipelineLockService.class, Level.WARN)) {
        pipelineLockService.registerListener(listener1);
        pipelineLockService.registerListener(listener2);
        pipelineLockService.registerListener(listener3);
        pipelineLockService.unlock("pipeline1");
        synchronized (logFixture) {
            assertTrue(logFixture.getLog(), logFixture.contains(Level.WARN, "Failed to notify listener (ListenerWhichFails)"));
        }
    }
    verify(listener1).lockStatusChanged(Event.unLock("pipeline1"));
    verify(listener2).lockStatusChanged(Event.unLock("pipeline1"));
    verify(listener3).lockStatusChanged(Event.unLock("pipeline1"));
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) PipelineLockStatusChangeListener(com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener) Test(org.junit.Test)

Example 3 with PipelineLockStatusChangeListener

use of com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener in project gocd by gocd.

the class PipelineLockServiceTest method shouldNotifyListenersAfterPipelineIsUnlockedUponConfigChange.

@Test
public void shouldNotifyListenersAfterPipelineIsUnlockedUponConfigChange() throws Exception {
    PipelineLockStatusChangeListener lockStatusChangeListener = mock(PipelineLockStatusChangeListener.class);
    CruiseConfig cruiseConfig = mock(BasicCruiseConfig.class);
    when(pipelineStateDao.lockedPipelines()).thenReturn(asList("pipeline1"));
    when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipeline1"))).thenReturn(false);
    when(cruiseConfig.isPipelineLockable("pipeline1")).thenThrow(new PipelineNotFoundException("pipeline1 not found"));
    pipelineLockService.registerListener(lockStatusChangeListener);
    pipelineLockService.onConfigChange(cruiseConfig);
    verify(lockStatusChangeListener).lockStatusChanged(Event.unLock("pipeline1"));
}
Also used : PipelineLockStatusChangeListener(com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener) Test(org.junit.Test)

Example 4 with PipelineLockStatusChangeListener

use of com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener in project gocd by gocd.

the class PipelineLockService method notifyListeners.

private void notifyListeners(PipelineLockStatusChangeListener.Event event) {
    for (PipelineLockStatusChangeListener listener : listeners) {
        try {
            LOGGER.debug("START  Notifying listener ({}) of event: {}", listener, event);
            listener.lockStatusChanged(event);
            LOGGER.debug("FINISH Notifying listener ({}) of event: {}", listener, event);
        } catch (Exception e) {
            LOGGER.warn("Failed to notify listener ({}) of event: {}", listener, event);
        }
    }
}
Also used : PipelineLockStatusChangeListener(com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener)

Example 5 with PipelineLockStatusChangeListener

use of com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener in project gocd by gocd.

the class PipelineLockServiceTest method shouldNotifyListenersAfterPipelineIsUnlocked.

@Test
public void shouldNotifyListenersAfterPipelineIsUnlocked() throws Exception {
    PipelineLockStatusChangeListener lockStatusChangeListener = mock(PipelineLockStatusChangeListener.class);
    pipelineLockService.registerListener(lockStatusChangeListener);
    pipelineLockService.unlock("pipeline1");
    verify(lockStatusChangeListener).lockStatusChanged(Event.unLock("pipeline1"));
}
Also used : PipelineLockStatusChangeListener(com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener) Test(org.junit.Test)

Aggregations

PipelineLockStatusChangeListener (com.thoughtworks.go.server.domain.PipelineLockStatusChangeListener)5 Test (org.junit.Test)4 Pipeline (com.thoughtworks.go.domain.Pipeline)1 LogFixture (com.thoughtworks.go.util.LogFixture)1