Search in sources :

Example 1 with Clock

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

the class TimeStampBasedCounterTest method shouldGetIncrementalTimeStampBasedOnSeed.

@Test
public void shouldGetIncrementalTimeStampBasedOnSeed() {
    Clock clock = mock(Clock.class);
    when(clock.currentTimeMillis()).thenReturn(1000L);
    TimeStampBasedCounter timeStampBasedCounter = new TimeStampBasedCounter(clock);
    assertThat(timeStampBasedCounter.getNext(), is(1001L));
    assertThat(timeStampBasedCounter.getNext(), is(1002L));
}
Also used : Clock(com.thoughtworks.go.util.Clock) Test(org.junit.Test)

Example 2 with Clock

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

the class TimeStampBasedCounterTest method shouldAllow.

@Test
public void shouldAllow() throws InterruptedException {
    ArrayList<Thread> list = new ArrayList<>();
    Clock clock = mock(Clock.class);
    when(clock.currentTimeMillis()).thenReturn(0L);
    TimeStampBasedCounter provider = new TimeStampBasedCounter(clock);
    for (int i = 0; i < 10; i++) {
        int finalI = i;
        Thread thread = new Thread(new Runnable() {

            @Override
            public void run() {
                provider.getNext();
            // System.out.println("provider.getNext() = " + provider.getNext() + " id: " + finalI);
            }
        }, "Thread" + i);
        list.add(thread);
    }
    for (Thread thread : list) {
        thread.start();
    }
    for (Thread thread : list) {
        thread.join();
    }
}
Also used : ArrayList(java.util.ArrayList) Clock(com.thoughtworks.go.util.Clock) Test(org.junit.Test)

Example 3 with Clock

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

the class PipelineSelectionsServiceTest method setup.

@Before
public void setup() throws Exception {
    new SystemEnvironment().setProperty(SystemEnvironment.ENFORCE_SERVER_IMMUTABILITY, "N");
    goConfigDao = mock(GoConfigDao.class);
    pipelineRepository = mock(PipelineRepository.class);
    pipelinePauseService = mock(PipelinePauseService.class);
    systemEnvironment = mock(SystemEnvironment.class);
    cruiseConfig = unchangedConfig();
    expectLoad(cruiseConfig);
    this.clock = mock(Clock.class);
    userDao = mock(UserDao.class);
    stub(systemEnvironment.optimizeFullConfigSave()).toReturn(false);
    ConfigElementImplementationRegistry registry = ConfigElementImplementationRegistryMother.withNoPlugins();
    goConfigService = mock(GoConfigService.class);
    pipelineSelectionsService = new PipelineSelectionsService(pipelineRepository, goConfigService, clock);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) UserDao(com.thoughtworks.go.server.dao.UserDao) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) PipelineRepository(com.thoughtworks.go.server.persistence.PipelineRepository) Clock(com.thoughtworks.go.util.Clock) Before(org.junit.Before)

Aggregations

Clock (com.thoughtworks.go.util.Clock)3 Test (org.junit.Test)2 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)1 UserDao (com.thoughtworks.go.server.dao.UserDao)1 PipelineRepository (com.thoughtworks.go.server.persistence.PipelineRepository)1 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1