use of com.thoughtworks.go.domain.PipelineState in project gocd by gocd.
the class PipelineLockServiceTest method shouldAllowStageFromCurrentPipelineToBeScheduled.
@Test
public void shouldAllowStageFromCurrentPipelineToBeScheduled() throws Exception {
Pipeline pipeline = PipelineMother.firstStageBuildingAndSecondStageScheduled("mingle", asList("dev", "ft"), asList("test"));
when(pipelineStateDao.pipelineStateFor("mingle")).thenReturn(new PipelineState(pipeline.getName(), pipeline.getStages().get(0).getIdentifier()));
when(goConfigService.isLockable(pipeline.getName())).thenReturn(true);
pipelineLockService.lockIfNeeded(pipeline);
assertThat(pipelineLockService.canScheduleStageInPipeline(pipeline.getIdentifier()), is(true));
}
use of com.thoughtworks.go.domain.PipelineState in project gocd by gocd.
the class PipelineLockServiceTest method shouldAllowStageFromAnotherPipelineIfThePipelineIsNotLockabler.
@Test
public void shouldAllowStageFromAnotherPipelineIfThePipelineIsNotLockabler() throws Exception {
Pipeline pipeline = PipelineMother.firstStageBuildingAndSecondStageScheduled("mingle", asList("dev", "ft"), asList("test"));
when(pipelineStateDao.pipelineStateFor("mingle")).thenReturn(new PipelineState(pipeline.getName(), new StageIdentifier(pipeline.getName(), 9999, "1.2.9999", "stage", "1")));
when(goConfigService.isLockable(pipeline.getName())).thenReturn(false);
pipelineLockService.lockIfNeeded(pipeline);
assertThat(pipelineLockService.canScheduleStageInPipeline(pipeline.getIdentifier()), is(true));
}
use of com.thoughtworks.go.domain.PipelineState in project gocd by gocd.
the class PipelineLockServiceTest method shouldKnowIfPipelineIsLocked.
@Test
public void shouldKnowIfPipelineIsLocked() throws Exception {
String pipelineName = "mingle";
PipelineState pipelineState = new PipelineState(pipelineName, new StageIdentifier(pipelineName, 1, "1", "stage", "1"));
pipelineState.lock(1);
when(pipelineStateDao.pipelineStateFor(pipelineName)).thenReturn(pipelineState);
assertThat(pipelineLockService.isLocked(pipelineName), is(true));
assertThat(pipelineLockService.isLocked("twist"), is(false));
}
use of com.thoughtworks.go.domain.PipelineState in project gocd by gocd.
the class PipelineStateDaoCachingTest method lockedPipeline_shouldReturnNullIfPipelineIsNotLocked.
@Test
public void lockedPipeline_shouldReturnNullIfPipelineIsNotLocked() throws Exception {
String pipelineName = UUID.randomUUID().toString();
pipelineStateDao.pipelineStateFor(pipelineName);
PipelineState actual = pipelineStateDao.pipelineStateFor(pipelineName);
assertNull("got " + actual, actual);
assertThat(goCache.get(pipelineStateDao.pipelineLockStateCacheKey(pipelineName)), is(NOT_LOCKED));
verify(transactionTemplate, times(1)).execute(any(org.springframework.transaction.support.TransactionCallback.class));
}
use of com.thoughtworks.go.domain.PipelineState in project gocd by gocd.
the class PipelineStateDaoCachingTest method lockPipeline_ShouldSavePipelineStateAndInvalidateCache.
@Test
public void lockPipeline_ShouldSavePipelineStateAndInvalidateCache() throws Exception {
final TransactionSynchronizationAdapter[] transactionSynchronizationAdapter = { null };
when(transactionTemplate.execute(any(org.springframework.transaction.support.TransactionCallbackWithoutResult.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
org.springframework.transaction.support.TransactionCallbackWithoutResult callback = (org.springframework.transaction.support.TransactionCallbackWithoutResult) invocation.getArguments()[0];
callback.doInTransaction(new SimpleTransactionStatus());
transactionSynchronizationAdapter[0].afterCommit();
return null;
}
});
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
TransactionSynchronizationAdapter adapter = (TransactionSynchronizationAdapter) invocation.getArguments()[0];
transactionSynchronizationAdapter[0] = adapter;
return null;
}
}).when(transactionSynchronizationManager).registerSynchronization(any(TransactionSynchronization.class));
final Pipeline pipeline = PipelineMother.pipeline("mingle");
PipelineState pipelineState = new PipelineState(pipeline.getName(), pipeline.getFirstStage().getIdentifier());
when(session.load(PipelineState.class, pipeline.getId())).thenReturn(pipelineState);
goCache.put(pipelineStateDao.pipelineLockStateCacheKey(pipeline.getName()), pipelineState);
pipelineStateDao.lockPipeline(pipeline);
assertThat(goCache.get(pipelineStateDao.pipelineLockStateCacheKey(pipeline.getName())), is(nullValue()));
ArgumentCaptor<PipelineState> pipelineStateArgumentCaptor = ArgumentCaptor.forClass(PipelineState.class);
verify(session).saveOrUpdate(pipelineStateArgumentCaptor.capture());
PipelineState savedPipelineState = pipelineStateArgumentCaptor.getValue();
assertThat(savedPipelineState.isLocked(), is(true));
assertThat(savedPipelineState.getLockedByPipelineId(), is(pipeline.getId()));
}
Aggregations