use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class BuildCauseProducerServiceWithFlipModificationTest method consume.
private void consume(final BuildCause buildCause) throws SQLException {
dbHelper.saveRevs(buildCause.getMaterialRevisions());
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
Pipeline latestPipeline = pipelineScheduleQueue.createPipeline(buildCause, mingleConfig, new DefaultSchedulingContext(buildCause.getApprover(), new Agents()), "md5", new TimeProvider());
// Pipeline latestPipeline = PipelineMother.schedule(mingleConfig, buildCause);
pipelineDao.saveWithStages(latestPipeline);
dbHelper.passStage(latestPipeline.getStages().first());
}
});
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class StageServiceIntegrationTest method shouldLoadPageOfOldestStagesHavingArtifacts.
@Test
public void shouldLoadPageOfOldestStagesHavingArtifacts() {
CruiseConfig cruiseConfig = configFileHelper.currentConfig();
PipelineConfig mingleConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(PIPELINE_NAME));
ReflectionUtil.setField(mingleConfig.get(0), "artifactCleanupProhibited", true);
configFileHelper.writeConfigFile(cruiseConfig);
configDbStateRepository.flushConfigState();
Pipeline[] pipelines = new Pipeline[101];
for (int i = 0; i < 101; i++) {
PipelineConfig pipelineCfg = configFileHelper.addPipeline("pipeline-" + i, "stage", "job");
Pipeline pipeline = dbHelper.schedulePipeline(pipelineCfg, new TimeProvider());
dbHelper.pass(pipeline);
pipelines[i] = pipeline;
}
List<Stage> stages = stageService.oldestStagesWithDeletableArtifacts();
for (int i = 0; i < 100; i++) {
Stage stage = stages.get(i);
assertThat(stage.getIdentifier(), is(pipelines[i].getFirstStage().getIdentifier()));
stageService.markArtifactsDeletedFor(stage);
}
assertThat(stages.size(), is(100));
stages = stageService.oldestStagesWithDeletableArtifacts();
assertThat(stages.size(), is(1));
Stage stage = stages.get(0);
assertThat(stage.getIdentifier(), is(pipelines[100].getFirstStage().getIdentifier()));
stageService.markArtifactsDeletedFor(stage);
assertThat(stageService.oldestStagesWithDeletableArtifacts().size(), is(0));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class StageServiceIntegrationTest method shouldReturnStageWithSpecificCounter.
@Test
public void shouldReturnStageWithSpecificCounter() throws Exception {
Stage firstStage = savedPipeline.getStages().first();
Stage newInstance = instanceFactory.createStageInstance(pipelineConfig.first(), new DefaultSchedulingContext("anonymous"), md5, new TimeProvider());
Stage newSavedStage = stageService.save(savedPipeline, newInstance);
Stage latestStage = stageService.findStageWithIdentifier(new StageIdentifier(CaseInsensitiveString.str(pipelineConfig.name()), null, savedPipeline.getLabel(), firstStage.getName(), String.valueOf(newSavedStage.getCounter())));
assertThat(latestStage, is(newSavedStage));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class StageServiceIntegrationTest method shouldSaveStageWithStateBuilding.
@Test
public void shouldSaveStageWithStateBuilding() throws Exception {
Stage stage = instanceFactory.createStageInstance(pipelineConfig.first(), new DefaultSchedulingContext("anonumous"), md5, new TimeProvider());
stageService.save(savedPipeline, stage);
Stage latestStage = stageService.findLatestStage(CaseInsensitiveString.str(pipelineConfig.name()), CaseInsensitiveString.str(pipelineConfig.first().name()));
assertThat(latestStage.getState(), is(StageState.Building));
}
use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.
the class StageServiceIntegrationTest method shouldIgnoreErrorsWhenNotifyingListenersDuringSave.
@Test
public void shouldIgnoreErrorsWhenNotifyingListenersDuringSave() throws Exception {
List<StageStatusListener> original = new ArrayList<>(stageService.getStageStatusListeners());
try {
stageService.getStageStatusListeners().clear();
StageStatusListener failingListener = mock(StageStatusListener.class);
doThrow(new RuntimeException("Should not be rethrown by save")).when(failingListener).stageStatusChanged(any(Stage.class));
StageStatusListener passingListener = mock(StageStatusListener.class);
stageService.getStageStatusListeners().add(failingListener);
stageService.getStageStatusListeners().add(passingListener);
Stage newInstance = instanceFactory.createStageInstance(pipelineConfig.first(), new DefaultSchedulingContext("anonumous"), md5, new TimeProvider());
Stage savedStage = stageService.save(savedPipeline, newInstance);
assertThat("Got: " + savedStage.getId(), savedStage.getId() > 0L, is(true));
verify(passingListener).stageStatusChanged(any(Stage.class));
} finally {
stageService.getStageStatusListeners().clear();
stageService.getStageStatusListeners().addAll(original);
}
}
Aggregations