use of com.thoughtworks.go.util.TestingClock in project gocd by gocd.
the class ServerHealthServiceTest method setUp.
@Before
public void setUp() throws Exception {
serverHealthService = new ServerHealthService();
globalId = HealthStateType.general(GLOBAL);
pipelineId = HealthStateType.general(forPipeline(PIPELINE_NAME));
groupId = HealthStateType.invalidLicense(forGroup("group"));
testingClock = new TestingClock();
ServerHealthState.clock = testingClock;
}
use of com.thoughtworks.go.util.TestingClock in project gocd by gocd.
the class StreamPumperTest method shouldKnowIfPumperExpired.
@Test
public void shouldKnowIfPumperExpired() throws Exception {
PipedOutputStream output = new PipedOutputStream();
InputStream inputStream = new PipedInputStream(output);
try {
TestingClock clock = new TestingClock();
StreamPumper pumper = new StreamPumper(inputStream, new TestConsumer(), "", null, clock);
new Thread(pumper).start();
output.write("line1\n".getBytes());
output.flush();
long timeoutDuration = 2L;
assertThat(pumper.didTimeout(timeoutDuration, TimeUnit.SECONDS), is(false));
clock.addSeconds(5);
assertThat(pumper.didTimeout(timeoutDuration, TimeUnit.SECONDS), is(true));
} finally {
output.close();
}
}
use of com.thoughtworks.go.util.TestingClock in project gocd by gocd.
the class StageServiceTest method shouldBeAbleToGetAJobsDuration.
@Test
public void shouldBeAbleToGetAJobsDuration() throws Exception {
TestingClock clock = new TestingClock();
JobInstance theJob = JobInstanceMother.building("job", clock.currentTime());
theJob.setClock(clock);
clock.addSeconds(9);
theJob.completing(JobResult.Passed, clock.currentTime());
theJob.completed(clock.currentTime());
StageIdentifier stageId = new StageIdentifier(theJob.getPipelineName(), 1, "1.0.1", "1");
Stages stages = new Stages(StageMother.custom(theJob.getStageName(), theJob));
TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
StageService service = new StageService(stageDao, null, null, null, alwaysAllow(), null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
when(stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName())).thenReturn(stages);
when(stageDao.getExpectedDurationMillis(theJob.getPipelineName(), theJob.getStageName(), theJob)).thenReturn(10 * 1000L);
StageSummaryModel stageForView = service.findStageSummaryByIdentifier(stageId, ALWAYS_ALLOW_USER, new HttpLocalizedOperationResult());
JobInstanceModel job = stageForView.passedJobs().get(0);
assertThat(job.getElapsedTime(), is(theJob.getElapsedTime()));
assertThat(job.getPercentComplete(), is(90));
verify(stageDao).getExpectedDurationMillis(theJob.getPipelineName(), theJob.getStageName(), theJob);
}
use of com.thoughtworks.go.util.TestingClock in project gocd by gocd.
the class JobInstanceModelTest method job.
private JobInstanceModel job(int elapsedSeconds, int etaSeconds) {
TestingClock clock = new TestingClock();
JobInstance instance = JobInstanceMother.building("job", clock.currentTime());
instance.setClock(clock);
clock.addSeconds(elapsedSeconds);
return new JobInstanceModel(instance, new JobDurationStrategy.ConstantJobDuration(etaSeconds * 1000));
}
Aggregations