Search in sources :

Example 6 with TestingClock

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

Example 7 with 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();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) TestingClock(com.thoughtworks.go.util.TestingClock) Test(org.junit.Test)

Example 8 with TestingClock

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);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) TestingClock(com.thoughtworks.go.util.TestingClock) Test(org.junit.Test)

Example 9 with TestingClock

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));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobDurationStrategy(com.thoughtworks.go.server.domain.JobDurationStrategy) TestingClock(com.thoughtworks.go.util.TestingClock)

Aggregations

TestingClock (com.thoughtworks.go.util.TestingClock)9 Before (org.junit.Before)5 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 PipedInputStream (java.io.PipedInputStream)2 PipedOutputStream (java.io.PipedOutputStream)2 JobInstance (com.thoughtworks.go.domain.JobInstance)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 JobDurationStrategy (com.thoughtworks.go.server.domain.JobDurationStrategy)1 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)1 TransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TransactionSynchronizationManager)1 URLService (com.thoughtworks.go.util.URLService)1 ZipUtil (com.thoughtworks.go.util.ZipUtil)1 File (java.io.File)1 Date (java.util.Date)1