Search in sources :

Example 6 with OperationResult

use of com.thoughtworks.go.server.service.result.OperationResult in project gocd by gocd.

the class BuildCauseProducerServiceIntegrationTest method manualSchedulePipeline_canProduceShouldNotgetIntoCyclicLoopWithTriggerMonitor.

@Test
public void manualSchedulePipeline_canProduceShouldNotgetIntoCyclicLoopWithTriggerMonitor() throws Exception {
    OperationResult operationResult = new ServerHealthStateOperationResult();
    buildCauseProducer.manualProduceBuildCauseAndSave(MINGLE_PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(), operationResult);
    scheduleHelper.waitForAnyScheduled(5);
    assertThat(operationResult.canContinue(), is(true));
}
Also used : ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) OperationResult(com.thoughtworks.go.server.service.result.OperationResult) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) Test(org.junit.Test)

Example 7 with OperationResult

use of com.thoughtworks.go.server.service.result.OperationResult in project gocd by gocd.

the class JobRerunScheduleServiceTest method shouldSynchronizeAroundRerunJobsFlow.

@Test
public void shouldSynchronizeAroundRerunJobsFlow() throws InterruptedException {
    PipelineConfig mingleConfig = PipelineConfigMother.createPipelineConfig("mingle", "build", "unit", "functional");
    Pipeline pipeline = PipelineMother.passedPipelineInstance("mingle", "build", "unit");
    final Stage firstStage = pipeline.getFirstStage();
    stub(mingleConfig, pipeline, firstStage);
    stubConfigMd5Cal("latest-md5");
    final Semaphore sem = new Semaphore(1);
    sem.acquire();
    final ThreadLocal<Integer> requestNumber = new ThreadLocal<>();
    final boolean[] firstRequestFinished = new boolean[] { false };
    final boolean[] secondReqGotInAfterFirstFinished = new boolean[] { false };
    schedulingChecker = new SchedulingCheckerService(null, null, null, null, null, null, null, null, null, null) {

        @Override
        public boolean canSchedule(OperationResult result) {
            if (requestNumber.get() == 0) {
                //is first request, and has lock
                //now we are in the locked section, so let the other request try
                sem.release();
            }
            if (requestNumber.get() == 1) {
                //this is the second req
                //was the first thread done with last bit of useful work before second came in?
                secondReqGotInAfterFirstFinished[0] = firstRequestFinished[0];
            }
            return true;
        }

        @Override
        public boolean canRerunStage(PipelineIdentifier pipelineIdentifier, String stageName, String username, OperationResult result) {
            return true;
        }
    };
    TestTransactionTemplate template = new TestTransactionTemplate(new TestTransactionSynchronizationManager()) {

        @Override
        public Object execute(TransactionCallback action) {
            if (requestNumber.get() == 0) {
                try {
                    //let the other thread try for 5 seconds
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    throw new RuntimeException();
                }
            }
            return super.execute(action);
        }
    };
    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, template, mock(AgentService.class), null, timeProvider, null, null, mock(InstanceFactory.class), schedulingPerformanceLogger, elasticProfileService) {

        @Override
        public Stage scheduleStage(Pipeline pipeline, String stageName, String username, StageInstanceCreator creator, ErrorConditionHandler errorHandler) {
            Stage stage = super.scheduleStage(pipeline, stageName, username, creator, errorHandler);
            if (requestNumber.get() == 0) {
                firstRequestFinished[0] = true;
            }
            return stage;
        }
    };
    Thread firstReq = new Thread(new Runnable() {

        public void run() {
            requestNumber.set(0);
            service.rerunJobs(firstStage, a("unit"), new HttpOperationResult());
        }
    });
    Thread secondReq = new Thread(new Runnable() {

        public void run() {
            try {
                requestNumber.set(1);
                sem.acquire();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            service.rerunJobs(firstStage, a("unit"), new HttpOperationResult());
        }
    });
    firstReq.start();
    secondReq.start();
    firstReq.join();
    secondReq.join();
    assertThat("second request should have gone-in only after first is out", secondReqGotInAfterFirstFinished[0], is(true));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TestTransactionTemplate(com.thoughtworks.go.server.transaction.TestTransactionTemplate) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) OperationResult(com.thoughtworks.go.server.service.result.OperationResult) Semaphore(java.util.concurrent.Semaphore) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) TransactionCallback(org.springframework.transaction.support.TransactionCallback) Test(org.junit.Test)

Example 8 with OperationResult

use of com.thoughtworks.go.server.service.result.OperationResult in project gocd by gocd.

the class PipelineSchedulerTest method shouldReturn404WhenVariableIsNotInConfigScope.

@Test
public void shouldReturn404WhenVariableIsNotInConfigScope() {
    when(configService.hasPipelineNamed(new CaseInsensitiveString("blahPipeline"))).thenReturn(true);
    when(configService.hasVariableInScope("blahPipeline", "blahVariable")).thenReturn(false);
    OperationResult operationResult = mock(OperationResult.class);
    final HashMap<String, String> revisions = new HashMap<>();
    scheduler.manualProduceBuildCauseAndSave("blahPipeline", Username.ANONYMOUS, new ScheduleOptions(revisions, Collections.singletonMap("blahVariable", "blahValue"), new HashMap<>()), operationResult);
    //noinspection unchecked
    verify(buildCauseProducerService, new NoMoreInteractions()).manualSchedulePipeline(any(Username.class), any(CaseInsensitiveString.class), any(ScheduleOptions.class), any(OperationResult.class));
    verify(operationResult).notFound("Variable 'blahVariable' has not been configured for pipeline 'blahPipeline'", "Variable 'blahVariable' has not been configured for pipeline 'blahPipeline'", HealthStateType.general(HealthStateScope.forPipeline("blahPipeline")));
}
Also used : HashMap(java.util.HashMap) Username(com.thoughtworks.go.server.domain.Username) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) OperationResult(com.thoughtworks.go.server.service.result.OperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) NoMoreInteractions(org.mockito.internal.verification.NoMoreInteractions) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 9 with OperationResult

use of com.thoughtworks.go.server.service.result.OperationResult in project gocd by gocd.

the class PipelineSchedulerTest method shouldAddErrorIfPipelineisNotFound.

@Test
public void shouldAddErrorIfPipelineisNotFound() throws Exception {
    when(configService.hasPipelineNamed(new CaseInsensitiveString("invalid"))).thenReturn(false);
    OperationResult operationResult = mock(OperationResult.class);
    final HashMap<String, String> revisions = new HashMap<>();
    final HashMap<String, String> environmentVariables = new HashMap<>();
    scheduler.manualProduceBuildCauseAndSave("invalid", Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), operationResult);
    verify(operationResult).notFound("Pipeline 'invalid' not found", "Pipeline 'invalid' not found", HealthStateType.general(HealthStateScope.forPipeline("invalid")));
}
Also used : HashMap(java.util.HashMap) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) OperationResult(com.thoughtworks.go.server.service.result.OperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 10 with OperationResult

use of com.thoughtworks.go.server.service.result.OperationResult in project gocd by gocd.

the class PipelineSchedulerTest method shouldSchedulePipelineWithEnvironmentVariableOverrides.

@Test
public void shouldSchedulePipelineWithEnvironmentVariableOverrides() {
    PipelineConfig pipelineConfig = configWithPipelines("blahPipeline").pipelineConfigByName(new CaseInsensitiveString("blahPipeline"));
    when(configService.pipelineConfigNamed(new CaseInsensitiveString("blahPipeline"))).thenReturn(pipelineConfig);
    when(configService.hasPipelineNamed(new CaseInsensitiveString("blahPipeline"))).thenReturn(true);
    when(configService.hasVariableInScope("blahPipeline", "blahVariable")).thenReturn(true);
    OperationResult operationResult = mock(OperationResult.class);
    Map<String, String> variables = Collections.singletonMap("blahVariable", "blahValue");
    final HashMap<String, String> revisions = new HashMap<>();
    scheduler.manualProduceBuildCauseAndSave("blahPipeline", Username.ANONYMOUS, new ScheduleOptions(revisions, variables, new HashMap<>()), operationResult);
    //noinspection unchecked
    verify(buildCauseProducerService).manualSchedulePipeline(Username.ANONYMOUS, pipelineConfig.name(), new ScheduleOptions(new HashMap<>(), variables, new HashMap<>()), operationResult);
}
Also used : PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HashMap(java.util.HashMap) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) OperationResult(com.thoughtworks.go.server.service.result.OperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

OperationResult (com.thoughtworks.go.server.service.result.OperationResult)10 Test (org.junit.Test)6 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)4 HashMap (java.util.HashMap)3 DiskSpaceOperationResult (com.thoughtworks.go.server.service.result.DiskSpaceOperationResult)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 Username (com.thoughtworks.go.server.domain.Username)1 ScheduleOptions (com.thoughtworks.go.server.scheduling.ScheduleOptions)1 DiskSpaceChecker (com.thoughtworks.go.server.service.DiskSpaceChecker)1 SystemDiskSpaceChecker (com.thoughtworks.go.server.service.SystemDiskSpaceChecker)1 DefaultLocalizedOperationResult (com.thoughtworks.go.server.service.result.DefaultLocalizedOperationResult)1 LocalizedOperationResult (com.thoughtworks.go.server.service.result.LocalizedOperationResult)1 ServerHealthServiceUpdatingOperationResult (com.thoughtworks.go.server.service.result.ServerHealthServiceUpdatingOperationResult)1 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)1 TestTransactionTemplate (com.thoughtworks.go.server.transaction.TestTransactionTemplate)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 Semaphore (java.util.concurrent.Semaphore)1 NoMoreInteractions (org.mockito.internal.verification.NoMoreInteractions)1