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