Search in sources :

Example 1 with SchedulingPerformanceLogger

use of com.thoughtworks.go.server.perf.SchedulingPerformanceLogger in project gocd by gocd.

the class ScheduleServiceStageTriggerTest method shouldNotNotifyListenersForWhenCancelStageTransactionRollsback.

@Test
public void shouldNotNotifyListenersForWhenCancelStageTransactionRollsback() throws Exception {
    Pipeline oldest = preCondition.createPipelineWithFirstStagePassedAndSecondStageRunning();
    preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    final Stage stage = oldest.getStages().byName(preCondition.ftStage);
    final StageIdentifier identifier = stage.getIdentifier();
    StageStatusTopic stageStatusTopic = mock(StageStatusTopic.class);
    JobResultTopic jobResultTopic = mock(JobResultTopic.class);
    StageStatusListener stageStatusListener = mock(StageStatusListener.class);
    JobInstanceService jobInstanceService = jobInstanceService(jobResultTopic);
    StageService stageService = new StageService(stageDao, jobInstanceService, stageStatusTopic, stageStatusCache, securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache, stageStatusListener);
    SchedulingPerformanceLogger schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    scheduleService = new ScheduleService(goConfigService, pipelineService, stageService, schedulingCheckerService, pipelineScheduledTopic, pipelineDao, stageDao, stageOrderService, securityService, pipelineScheduleQueue, this.jobInstanceService, jobInstanceDao, agentAssignment, environmentConfigService, pipelineLockService, serverHealthService, transactionTemplate, null, transactionSynchronizationManager, null, null, null, null, schedulingPerformanceLogger, null);
    try {
        transactionTemplate.executeWithExceptionHandling(new TransactionCallback() {

            @Override
            public Object doInTransaction(TransactionStatus status) throws Exception {
                scheduleService.cancelAndTriggerRelevantStages(stage.getId(), null, null);
                throw new GoUnauthorizedException();
            }
        });
    } catch (Exception e) {
    //ignore
    }
    verify(stageStatusTopic, never()).post(any(StageStatusMessage.class));
    verify(jobResultTopic, never()).post(any(JobResultMessage.class));
    verify(stageStatusListener, never()).stageStatusChanged(any(Stage.class));
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) JobResultTopic(com.thoughtworks.go.server.messaging.JobResultTopic) TransactionStatus(org.springframework.transaction.TransactionStatus) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) CannotScheduleException(com.thoughtworks.go.domain.CannotScheduleException) Pipeline(com.thoughtworks.go.domain.Pipeline) StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) TransactionCallback(com.thoughtworks.go.server.transaction.TransactionCallback) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) Stage(com.thoughtworks.go.domain.Stage) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) Test(org.junit.Test)

Example 2 with SchedulingPerformanceLogger

use of com.thoughtworks.go.server.perf.SchedulingPerformanceLogger in project gocd by gocd.

the class ScheduleServiceTest method setup.

@Before
public void setup() {
    jobInstanceService = mock(JobInstanceService.class);
    goConfigService = mock(GoConfigService.class);
    environmentConfigService = mock(EnvironmentConfigService.class);
    serverHealthService = mock(ServerHealthService.class);
    final TestTransactionSynchronizationManager synchronizationManager = new TestTransactionSynchronizationManager();
    schedulingChecker = mock(SchedulingCheckerService.class);
    pipelineScheduleQueue = mock(PipelineScheduleQueue.class);
    consoleActivityMonitor = mock(ConsoleActivityMonitor.class);
    pipelinePauseService = mock(PipelinePauseService.class);
    stageService = mock(StageService.class);
    securityService = mock(SecurityService.class);
    pipelineService = mock(PipelineService.class);
    localizer = mock(Localizer.class);
    timeProvider = new TimeProvider();
    schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    elasticProfileService = mock(ElasticProfileService.class);
    service = new ScheduleService(goConfigService, pipelineService, stageService, schedulingChecker, mock(PipelineScheduledTopic.class), mock(PipelineDao.class), mock(StageDao.class), mock(StageOrderService.class), securityService, pipelineScheduleQueue, jobInstanceService, mock(JobInstanceDao.class), mock(AgentAssignment.class), environmentConfigService, mock(PipelineLockService.class), serverHealthService, new TestTransactionTemplate(synchronizationManager), mock(AgentService.class), synchronizationManager, timeProvider, consoleActivityMonitor, pipelinePauseService, instanceFactory, schedulingPerformanceLogger, elasticProfileService);
}
Also used : TestTransactionTemplate(com.thoughtworks.go.server.transaction.TestTransactionTemplate) TimeProvider(com.thoughtworks.go.util.TimeProvider) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) Localizer(com.thoughtworks.go.i18n.Localizer) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) Before(org.junit.Before)

Example 3 with SchedulingPerformanceLogger

use of com.thoughtworks.go.server.perf.SchedulingPerformanceLogger in project gocd by gocd.

the class JobRerunScheduleServiceTest method setup.

@Before
public void setup() {
    jobInstanceService = mock(JobInstanceService.class);
    goConfigService = mock(GoConfigService.class);
    environmentConfigService = mock(EnvironmentConfigService.class);
    serverHealthService = mock(ServerHealthService.class);
    final TestTransactionSynchronizationManager synchronizationManager = new TestTransactionSynchronizationManager();
    schedulingChecker = mock(SchedulingCheckerService.class);
    pipelineScheduleQueue = mock(PipelineScheduleQueue.class);
    pipelineService = mock(PipelineService.class);
    stageService = mock(StageService.class);
    securityService = mock(SecurityService.class);
    lockService = mock(PipelineLockService.class);
    txnTemplate = new TestTransactionTemplate(synchronizationManager);
    timeProvider = new TimeProvider();
    instanceFactory = mock(InstanceFactory.class);
    schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    elasticProfileService = mock(ElasticProfileService.class);
    service = new ScheduleService(goConfigService, pipelineService, stageService, schedulingChecker, mock(PipelineScheduledTopic.class), mock(PipelineDao.class), mock(StageDao.class), mock(StageOrderService.class), securityService, pipelineScheduleQueue, jobInstanceService, mock(JobInstanceDao.class), mock(AgentAssignment.class), environmentConfigService, lockService, serverHealthService, txnTemplate, mock(AgentService.class), synchronizationManager, timeProvider, null, null, instanceFactory, schedulingPerformanceLogger, elasticProfileService);
}
Also used : TestTransactionTemplate(com.thoughtworks.go.server.transaction.TestTransactionTemplate) TimeProvider(com.thoughtworks.go.util.TimeProvider) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) Before(org.junit.Before)

Example 4 with SchedulingPerformanceLogger

use of com.thoughtworks.go.server.perf.SchedulingPerformanceLogger in project gocd by gocd.

the class PipelineSchedulerTest method setUp.

@Before
public void setUp() {
    queue = mock(ScheduleCheckQueue.class);
    configService = mock(GoConfigService.class);
    ServerHealthService serverHealthService = mock(ServerHealthService.class);
    SchedulingCheckerService schedulingCheckerService = mock(SchedulingCheckerService.class);
    buildCauseProducerService = mock(BuildCauseProducerService.class);
    topic = mock(ScheduleCheckCompletedTopic.class);
    schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    scheduler = new PipelineScheduler(configService, serverHealthService, schedulingCheckerService, buildCauseProducerService, queue, topic, schedulingPerformanceLogger);
}
Also used : ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) Before(org.junit.Before)

Example 5 with SchedulingPerformanceLogger

use of com.thoughtworks.go.server.perf.SchedulingPerformanceLogger in project gocd by gocd.

the class ScheduleServiceStageTriggerTest method shouldDoCancellationInTransaction.

@Test
public void shouldDoCancellationInTransaction() throws Exception {
    Pipeline oldest = preCondition.createPipelineWithFirstStagePassedAndSecondStageRunning();
    preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    preCondition.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    Stage stage = oldest.getStages().byName(preCondition.ftStage);
    StageStatusTopic stageStatusTopic = mock(StageStatusTopic.class);
    JobResultTopic jobResultTopic = mock(JobResultTopic.class);
    StageStatusListener stageStatusListener = mock(StageStatusListener.class);
    StageService stageService = mock(StageService.class);
    when(stageService.stageById(stage.getId())).thenReturn(stage);
    Mockito.doAnswer(new Answer() {

        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            throw new RuntimeException();
        }
    }).when(stageService).cancelStage(stage);
    StageOrderService stageOrderService = mock(StageOrderService.class);
    SchedulingPerformanceLogger schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    scheduleService = new ScheduleService(goConfigService, pipelineService, stageService, schedulingCheckerService, pipelineScheduledTopic, pipelineDao, stageDao, stageOrderService, securityService, pipelineScheduleQueue, this.jobInstanceService, jobInstanceDao, agentAssignment, environmentConfigService, pipelineLockService, serverHealthService, transactionTemplate, null, transactionSynchronizationManager, null, null, null, null, schedulingPerformanceLogger, null);
    try {
        scheduleService.cancelAndTriggerRelevantStages(stage.getId(), null, null);
    } catch (RuntimeException e) {
    //ignore
    }
    verify(stageStatusTopic, never()).post(any(StageStatusMessage.class));
    verify(jobResultTopic, never()).post(any(JobResultMessage.class));
    verify(stageStatusListener, never()).stageStatusChanged(any(Stage.class));
}
Also used : StageStatusTopic(com.thoughtworks.go.server.messaging.StageStatusTopic) JobResultTopic(com.thoughtworks.go.server.messaging.JobResultTopic) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) Pipeline(com.thoughtworks.go.domain.Pipeline) StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JobResultMessage(com.thoughtworks.go.server.messaging.JobResultMessage) Stage(com.thoughtworks.go.domain.Stage) StageStatusMessage(com.thoughtworks.go.server.messaging.StageStatusMessage) Test(org.junit.Test)

Aggregations

SchedulingPerformanceLogger (com.thoughtworks.go.server.perf.SchedulingPerformanceLogger)7 Before (org.junit.Before)4 Pipeline (com.thoughtworks.go.domain.Pipeline)3 Stage (com.thoughtworks.go.domain.Stage)3 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)3 Test (org.junit.Test)3 StageStatusListener (com.thoughtworks.go.server.domain.StageStatusListener)2 JobResultMessage (com.thoughtworks.go.server.messaging.JobResultMessage)2 JobResultTopic (com.thoughtworks.go.server.messaging.JobResultTopic)2 StageStatusMessage (com.thoughtworks.go.server.messaging.StageStatusMessage)2 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)2 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)2 TestTransactionTemplate (com.thoughtworks.go.server.transaction.TestTransactionTemplate)2 TimeProvider (com.thoughtworks.go.util.TimeProvider)2 CannotScheduleException (com.thoughtworks.go.domain.CannotScheduleException)1 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)1 Localizer (com.thoughtworks.go.i18n.Localizer)1 GoUnauthorizedException (com.thoughtworks.go.server.GoUnauthorizedException)1 StageDao (com.thoughtworks.go.server.dao.StageDao)1 TransactionCallback (com.thoughtworks.go.server.transaction.TransactionCallback)1