Search in sources :

Example 81 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class PipelineHistoryMother method stageHistory.

public static StageInstanceModels stageHistory(PipelineConfig pipelineConfig, Date modificationDate) {
    StageInstanceModels history = new StageInstanceModels();
    for (StageConfig stageConfig : pipelineConfig) {
        StageInstanceModel item = new StageInstanceModel(CaseInsensitiveString.str(stageConfig.name()), "1", buildHistory(stageConfig, modificationDate));
        item.setCounter("1");
        item.setApprovalType(new InstanceFactory().createStageInstance(stageConfig, new DefaultSchedulingContext("anyone"), md5, new TimeProvider()).getApprovalType());
        if (stageConfig.requiresApproval()) {
            item.setApprovedBy(APPROVED_BY);
        } else {
            item.setApprovedBy(GoConstants.DEFAULT_APPROVED_BY);
        }
        history.add(item);
    }
    return history;
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) InstanceFactory(com.thoughtworks.go.server.service.InstanceFactory) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel) StageConfig(com.thoughtworks.go.config.StageConfig) DefaultSchedulingContext(com.thoughtworks.go.domain.DefaultSchedulingContext)

Example 82 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class BuildWork method initialize.

private void initialize(BuildRepositoryRemote remoteBuildRepository, GoArtifactsManipulator goArtifactsManipulator, AgentRuntimeInfo agentRuntimeInfo, TaskExtension taskExtension) {
    timeProvider = new TimeProvider();
    plan = assignment.getPlan();
    agentRuntimeInfo.busy(new AgentBuildingInfo(plan.getIdentifier().buildLocatorForDisplay(), plan.getIdentifier().buildLocator()));
    workingDirectory = assignment.getWorkingDirectory();
    materialRevisions = assignment.materialRevisions();
    buildLog = new GoControlLog(this.workingDirectory + "/cruise-output");
    goPublisher = new DefaultGoPublisher(goArtifactsManipulator, plan.getIdentifier(), remoteBuildRepository, agentRuntimeInfo);
    builders = new Builders(assignment.getBuilders(), goPublisher, buildLog, taskExtension);
}
Also used : AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) TimeProvider(com.thoughtworks.go.util.TimeProvider) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher)

Example 83 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class PipelineSqlMapDaoCachingTest method lockPipeline_shouldEnsureOnlyOneThreadCanLockAPipelineSuccessfully.

@Test(timeout = 10 * 1000)
public void lockPipeline_shouldEnsureOnlyOneThreadCanLockAPipelineSuccessfully() throws Exception {
    pipelineDao = new PipelineSqlMapDao(null, null, goCache, null, transactionTemplate, sqlMapClient, transactionSynchronizationManager, systemEnvironment, configFileDao, databaseStrategy) {

        @Override
        public StageIdentifier lockedPipeline(String pipelineName) {
            StageIdentifier result = super.lockedPipeline(pipelineName);
            // simulate multiple threads trying to lock a pipeline
            TestUtils.sleepQuietly(20);
            return result;
        }
    };
    List<Thread> threads = new ArrayList<>();
    final int[] errors = new int[1];
    for (int i = 0; i < 10; i++) {
        JobInstances jobInstances = new JobInstances(JobInstanceMother.completed("job"));
        Stage stage = new Stage("stage-1", jobInstances, "shilpa", "auto", new TimeProvider());
        final Pipeline pipeline = PipelineMother.pipeline("mingle", stage);
        pipeline.setCounter(i + 1);
        dbHelper.savePipelineWithStagesAndMaterials(pipeline);
        Thread thread = new Thread(new Runnable() {

            public void run() {
                try {
                    pipelineDao.lockPipeline(pipeline);
                } catch (Exception e) {
                    errors[0]++;
                }
            }
        }, "thread-" + i);
        threads.add(thread);
        thread.start();
    }
    for (Thread thread : threads) {
        thread.join();
    }
    assertThat(errors[0], is(9));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 84 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class GoConfigRevisionTest method setup.

@Before
public void setup() {
    timeProvider = mock(TimeProvider.class);
    date = new Date();
    when(timeProvider.currentTime()).thenReturn(date);
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) Before(org.junit.Before)

Example 85 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class PipelineSqlMapDaoCachingTest method shouldRemovePipelineIdFromCacheWhenStageFinishesForNonLatestPipeline.

@Test
public void shouldRemovePipelineIdFromCacheWhenStageFinishesForNonLatestPipeline() {
    final String pipelineName = "pipeline";
    CruiseConfig mockCruiseConfig = mock(BasicCruiseConfig.class);
    GoConfigDao mockconfigFileDao = mock(GoConfigDao.class);
    when(mockconfigFileDao.load()).thenReturn(mockCruiseConfig);
    when(mockCruiseConfig.getAllPipelineNames()).thenReturn(Arrays.asList(new CaseInsensitiveString(pipelineName)));
    // need to mock configfileDao for this test
    pipelineDao = new PipelineSqlMapDao(null, repository, goCache, environmentVariableDao, transactionTemplate, null, transactionSynchronizationManager, null, mockconfigFileDao, null, mock(SessionFactory.class));
    pipelineDao.setSqlMapClientTemplate(mockTemplate);
    PipelineInstanceModel first = model(1, JobState.Building, JobResult.Unknown);
    PipelineInstanceModel second = model(2, JobState.Building, JobResult.Unknown);
    PipelineInstanceModels pims = PipelineInstanceModels.createPipelineInstanceModels(first, second);
    when(mockTemplate.queryForList("allActivePipelines")).thenReturn(pims);
    when(mockTemplate.queryForObject("getPipelineHistoryById", arguments("id", 1L).asMap())).thenReturn(first);
    when(mockTemplate.queryForObject("getPipelineHistoryById", arguments("id", 2L).asMap())).thenReturn(second);
    // ensure cache is initialized
    pipelineDao.loadActivePipelines();
    Stage stage = new Stage("first", new JobInstances(JobInstanceMother.assigned("job")), "me", "whatever", new TimeProvider());
    stage.fail();
    stage.calculateResult();
    changeStageStatus(stage, 1);
    // notifying latest id should not remove it from the cache
    stage.setPipelineId(2l);
    pipelineDao.stageStatusChanged(stage);
    PipelineInstanceModels models = pipelineDao.loadActivePipelines();
    assertThat(models.size(), is(1));
    assertThat(models.get(0).getId(), is(2L));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) 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