Search in sources :

Example 1 with StageStatusCache

use of com.thoughtworks.go.domain.activity.StageStatusCache in project gocd by gocd.

the class StageServiceTest method shouldNotSendStageStatusMessageAfterStageIsCancelledAndAnyOfTheJobIsAssigned.

@Test
public void shouldNotSendStageStatusMessageAfterStageIsCancelledAndAnyOfTheJobIsAssigned() throws SQLException {
    StageStatusTopic topic = mock(StageStatusTopic.class);
    final Stage cancelledStage = StageMother.cancelledStage("stage", "job");
    cancelledStage.setIdentifier(new StageIdentifier("pipeline/1/stage/1"));
    cancelledStage.getJobInstances().first().setAgentUuid("soem-agent");
    final StageService service = new StageService(stageDao, jobInstanceService, topic, new StageStatusCache(stageDao), null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, mock(GoCache.class));
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            service.cancelStage(cancelledStage, null);
        }
    });
    verifyNoInteractions(topic);
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) GoCache(com.thoughtworks.go.server.cache.GoCache) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.jupiter.api.Test)

Example 2 with StageStatusCache

use of com.thoughtworks.go.domain.activity.StageStatusCache in project gocd by gocd.

the class StageServiceTest method shouldFindLatestStageFromCache.

@Test
public void shouldFindLatestStageFromCache() throws SQLException {
    Stage expectedStage = StageMother.custom("pipeline", "stage", null);
    StageStatusCache cache = new StageStatusCache(stageDao);
    cache.stageStatusChanged(expectedStage);
    TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
    StageService service = new StageService(stageDao, jobInstanceService, null, cache, null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
    Stage actualStage = service.findLatestStage("pipeline", "stage");
    assertThat(actualStage).isEqualTo(expectedStage);
}
Also used : StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) Test(org.junit.jupiter.api.Test)

Example 3 with StageStatusCache

use of com.thoughtworks.go.domain.activity.StageStatusCache in project gocd by gocd.

the class StageServiceTest method shouldSendStageStatusMessageAfterStageIsCancelled.

@Test
public void shouldSendStageStatusMessageAfterStageIsCancelled() throws SQLException {
    StageStatusTopic topic = mock(StageStatusTopic.class);
    final Stage cancelledStage = StageMother.cancelledStage("stage", "job");
    cancelledStage.setIdentifier(new StageIdentifier("pipeline/1/stage/1"));
    final StageService service = new StageService(stageDao, jobInstanceService, topic, new StageStatusCache(stageDao), null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, mock(GoCache.class));
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            service.cancelStage(cancelledStage, null);
        }
    });
    verify(topic).post(new StageStatusMessage(cancelledStage.getIdentifier(), StageState.Cancelled, StageResult.Cancelled, Username.ANONYMOUS));
    verifyNoMoreInteractions(topic);
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) StageStatusCache(com.thoughtworks.go.domain.activity.StageStatusCache) GoCache(com.thoughtworks.go.server.cache.GoCache) TransactionStatus(org.springframework.transaction.TransactionStatus) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.jupiter.api.Test)

Aggregations

StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)3 Test (org.junit.jupiter.api.Test)3 GoCache (com.thoughtworks.go.server.cache.GoCache)2 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 StageStatusMessage (com.thoughtworks.go.server.messaging.StageStatusMessage)1 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)1 TransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TransactionSynchronizationManager)1