Search in sources :

Example 46 with TimeProvider

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());
        }
    });
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Agents(com.thoughtworks.go.config.Agents) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Pipeline(com.thoughtworks.go.domain.Pipeline) DefaultSchedulingContext(com.thoughtworks.go.domain.DefaultSchedulingContext)

Example 47 with TimeProvider

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));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 48 with TimeProvider

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));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 49 with TimeProvider

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));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 50 with TimeProvider

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);
    }
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) TimeProvider(com.thoughtworks.go.util.TimeProvider) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

TimeProvider (com.thoughtworks.go.util.TimeProvider)177 Test (org.junit.Test)122 Date (java.util.Date)29 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)28 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)25 DateTime (org.joda.time.DateTime)18 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)16 GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)13 Username (com.thoughtworks.go.server.domain.Username)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 Before (org.junit.Before)13 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)11 Materials (com.thoughtworks.go.config.materials.Materials)10 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 TransactionStatus (org.springframework.transaction.TransactionStatus)9 Material (com.thoughtworks.go.domain.materials.Material)7 Modification (com.thoughtworks.go.domain.materials.Modification)7 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)6