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