Search in sources :

Example 26 with TimeProvider

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

the class StageMother method createStageWithFakeDuration.

private static Stage createStageWithFakeDuration(String pipelineName, int pipelineCounter, String stageName, int stageCounter, String jobName, final DateTime scheduleTime, DateTime completedTime, JobResult jobResult) {
    TimeProvider timeProvider = new TimeProvider() {

        @Override
        public Date currentTime() {
            return scheduleTime.toDate();
        }

        public DateTime currentDateTime() {
            throw new UnsupportedOperationException("Not implemented");
        }

        public DateTime timeoutTime(Timeout timeout) {
            throw new UnsupportedOperationException("Not implemented");
        }
    };
    JobInstance firstJob = new JobInstance(jobName, timeProvider);
    JobInstances jobInstances = new JobInstances(firstJob);
    Stage stage = StageMother.custom(pipelineName, stageName, jobInstances);
    firstJob.assign("AGENT-1", completedTime.toDate());
    firstJob.completing(jobResult, completedTime.toDate());
    firstJob.completed(completedTime.toDate());
    stage.calculateResult();
    stage.setCreatedTime(new Timestamp(timeProvider.currentTime().getTime()));
    stage.setLastTransitionedTime(new Timestamp(completedTime.toDate().getTime()));
    stage.setIdentifier(new StageIdentifier(pipelineName, pipelineCounter, "LABEL-" + pipelineCounter, stageName, String.valueOf(stageCounter)));
    return stage;
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Timeout(com.thoughtworks.go.utils.Timeout) Timestamp(java.sql.Timestamp)

Example 27 with TimeProvider

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

the class StageMother method custom.

public static Stage custom(String pipelineName, String stageName, JobInstances instances) {
    Stage stage = new Stage(stageName, instances, DEFAULT_APPROVED_BY, GoConstants.APPROVAL_SUCCESS, new TimeProvider());
    stage.setIdentifier(new StageIdentifier(pipelineName, 1, "1", stageName, "1"));
    stage.building();
    return stage;
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider)

Example 28 with TimeProvider

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

the class StageNotificationServiceTest method stubPipelineAndStage.

private void stubPipelineAndStage(Date date) {
    final PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("go", "dev", "compile", "test", "twist");
    final Modification svnModification = new Modification("lgao", "Fixing the not checked in files", "jez@cruise.com", date, "123");
    svnModification.createModifiedFile("build.xml", "some_dir", ModifiedAction.added);
    svnModification.createModifiedFile("some.xml", "other_dir", ModifiedAction.deleted);
    Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, new ManualBuild(new Username(new CaseInsensitiveString("loser"))).onModifications(new MaterialRevisions(new MaterialRevision(new MaterialConfigConverter().toMaterials(pipelineConfig.materialConfigs()).get(0), svnModification)), false, null), new DefaultSchedulingContext("loser"), "md5-test", new TimeProvider());
    Stage stage = pipeline.getStages().get(0);
    when(stageService.findStageWithIdentifier(stageIdentifier)).thenReturn(stage);
    stage.setPipelineId(100L);
    when(pipelineService.fullPipelineById(100)).thenReturn(pipeline);
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimeProvider(com.thoughtworks.go.util.TimeProvider) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 29 with TimeProvider

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

the class PipelineBuilder method addJob.

public void addJob(String jobName) {
    JobInstance instance = new JobInstance(jobName, new TimeProvider());
    currentStage().getJobInstances().add(instance);
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) JobInstance(com.thoughtworks.go.domain.JobInstance)

Example 30 with TimeProvider

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

the class JobRerunScheduleServiceTest method setup.

@Before
public void setup() {
    jobInstanceService = mock(JobInstanceService.class);
    goConfigService = mock(GoConfigService.class);
    environmentConfigService = mock(EnvironmentConfigService.class);
    serverHealthService = mock(ServerHealthService.class);
    final TestTransactionSynchronizationManager synchronizationManager = new TestTransactionSynchronizationManager();
    schedulingChecker = mock(SchedulingCheckerService.class);
    pipelineScheduleQueue = mock(PipelineScheduleQueue.class);
    pipelineService = mock(PipelineService.class);
    stageService = mock(StageService.class);
    securityService = mock(SecurityService.class);
    lockService = mock(PipelineLockService.class);
    txnTemplate = new TestTransactionTemplate(synchronizationManager);
    timeProvider = new TimeProvider();
    instanceFactory = mock(InstanceFactory.class);
    schedulingPerformanceLogger = mock(SchedulingPerformanceLogger.class);
    elasticProfileService = mock(ElasticProfileService.class);
    service = new ScheduleService(goConfigService, pipelineService, stageService, schedulingChecker, mock(PipelineDao.class), mock(StageDao.class), mock(StageOrderService.class), securityService, pipelineScheduleQueue, jobInstanceService, mock(JobInstanceDao.class), mock(AgentAssignment.class), environmentConfigService, lockService, serverHealthService, txnTemplate, mock(AgentService.class), synchronizationManager, timeProvider, null, null, instanceFactory, schedulingPerformanceLogger, elasticProfileService);
}
Also used : TestTransactionTemplate(com.thoughtworks.go.server.transaction.TestTransactionTemplate) TimeProvider(com.thoughtworks.go.util.TimeProvider) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) SchedulingPerformanceLogger(com.thoughtworks.go.server.perf.SchedulingPerformanceLogger) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) Before(org.junit.Before)

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