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