Search in sources :

Example 51 with Clock

use of java.time.Clock in project incubator-pulsar by apache.

the class BackoffTest method firstBackoffTimerTest.

@Test
public void firstBackoffTimerTest() {
    Clock mockClock = Mockito.mock(Clock.class);
    Mockito.when(mockClock.millis()).thenReturn(0L).thenReturn(300L);
    Backoff backoff = new Backoff(100, TimeUnit.MILLISECONDS, 60, TimeUnit.SECONDS, 1900, TimeUnit.MILLISECONDS, mockClock);
    assertEquals(backoff.next(), 100);
    long firstBackOffTime = backoff.getFirstBackoffTimeInMillis();
    backoff.reset();
    assertEquals(backoff.next(), 100);
    long diffBackOffTime = backoff.getFirstBackoffTimeInMillis() - firstBackOffTime;
    assertTrue(diffBackOffTime == 300);
}
Also used : Clock(java.time.Clock) Test(org.testng.annotations.Test)

Example 52 with Clock

use of java.time.Clock in project incubator-pulsar by apache.

the class BackoffTest method basicTest.

@Test
public void basicTest() {
    Clock mockClock = Clock.fixed(Instant.EPOCH, ZoneId.systemDefault());
    Backoff backoff = new Backoff(5, TimeUnit.MILLISECONDS, 60, TimeUnit.SECONDS, 60, TimeUnit.SECONDS, mockClock);
    assertTrue(checkExactAndDecrementTimer(backoff, 5));
    assertTrue(withinTenPercentAndDecrementTimer(backoff, 10));
    backoff.reset();
    assertTrue(checkExactAndDecrementTimer(backoff, 5));
}
Also used : Clock(java.time.Clock) Test(org.testng.annotations.Test)

Example 53 with Clock

use of java.time.Clock in project Java8 by huhuhuHR.

the class ClockTest method main.

public static void main(String[] args) {
    Clock clock = Clock.systemDefaultZone();
    long mills = clock.millis();
    System.out.println(mills);
    Instant instant = clock.instant();
    Date legacyDate = Date.from(instant);
    System.out.println(legacyDate.getTime());
}
Also used : Instant(java.time.Instant) Clock(java.time.Clock) Date(java.util.Date)

Example 54 with Clock

use of java.time.Clock in project vespa by vespa-engine.

the class Trace method fromSlime.

public static Trace fromSlime(Inspector inspector) {
    int traceLevel = deserializeTraceLevel(inspector);
    Clock clock = Clock.systemUTC();
    SlimeTraceDeserializer deserializer = new SlimeTraceDeserializer(inspector.field(TRACE_TRACELOG));
    return new Trace(traceLevel, deserializer.deserialize(), clock);
}
Also used : Clock(java.time.Clock)

Example 55 with Clock

use of java.time.Clock in project vespa by vespa-engine.

the class ApplicationHandlerTest method testDelete.

@Test
public void testDelete() throws Exception {
    Clock clock = Clock.systemUTC();
    ApplicationId defaultId = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
    assertApplicationExists(mytenantName, null, Zone.defaultZone());
    long sessionId = 1;
    {
        // This block is a real test of the interplay of (most of) the components of the config server
        // TODO: Extract it to ApplicationRepositoryTest, rewrite to bypass the HTTP layer and extend
        // as login is moved from the HTTP layer into ApplicationRepository
        Tenants tenants = addApplication(defaultId, sessionId);
        ApplicationHandler handler = createApplicationHandler(tenants);
        Tenant mytenant = tenants.getTenant(defaultId.tenant());
        LocalSession applicationData = mytenant.getLocalSessionRepo().getSession(sessionId);
        assertNotNull(applicationData);
        assertNotNull(applicationData.getApplicationId());
        assertFalse(provisioner.removed);
        deleteAndAssertOKResponse(handler, mytenant, defaultId);
        assertTrue(provisioner.removed);
        assertThat(provisioner.lastApplicationId.tenant(), is(mytenantName));
        assertThat(provisioner.lastApplicationId, is(defaultId));
        assertNull(mytenant.getLocalSessionRepo().getSession(sessionId));
        assertNull(mytenant.getRemoteSessionRepo().getSession(sessionId));
    }
    sessionId++;
    {
        addMockApplication(tenants.getTenant(mytenantName), defaultId, sessionId, clock);
        deleteAndAssertOKResponseMocked(defaultId, true);
        ApplicationId fooId = new ApplicationId.Builder().tenant(mytenantName).applicationName("foo").instanceName("quux").build();
        sessionId++;
        addMockApplication(tenants.getTenant(mytenantName), fooId, sessionId, clock);
        addMockApplication(tenants.getTenant(foobar), fooId, sessionId, clock);
        assertApplicationExists(mytenantName, fooId, Zone.defaultZone());
        assertApplicationExists(foobar, fooId, Zone.defaultZone());
        deleteAndAssertOKResponseMocked(fooId, true);
        assertThat(provisioner.lastApplicationId.tenant(), is(mytenantName));
        assertThat(provisioner.lastApplicationId, is(fooId));
        assertApplicationExists(mytenantName, null, Zone.defaultZone());
        assertApplicationExists(foobar, fooId, Zone.defaultZone());
    }
    sessionId++;
    {
        ApplicationId baliId = new ApplicationId.Builder().tenant(mytenantName).applicationName("bali").instanceName("quux").build();
        addMockApplication(tenants.getTenant(mytenantName), baliId, sessionId, clock);
        deleteAndAssertOKResponseMocked(baliId, true);
        assertApplicationExists(mytenantName, null, Zone.defaultZone());
    }
}
Also used : Tenant(com.yahoo.vespa.config.server.tenant.Tenant) LocalSession(com.yahoo.vespa.config.server.session.LocalSession) Tenants(com.yahoo.vespa.config.server.tenant.Tenants) Clock(java.time.Clock) ApplicationId(com.yahoo.config.provision.ApplicationId) HandlerTest(com.yahoo.vespa.config.server.http.HandlerTest) SessionHandlerTest(com.yahoo.vespa.config.server.http.SessionHandlerTest) Test(org.junit.Test)

Aggregations

Clock (java.time.Clock)209 Test (org.junit.Test)62 Instant (java.time.Instant)51 Test (org.testng.annotations.Test)43 LocalTime (java.time.LocalTime)15 ZonedDateTime (java.time.ZonedDateTime)12 LocalDateTime (java.time.LocalDateTime)11 ZoneId (java.time.ZoneId)11 LocalDate (java.time.LocalDate)10 OffsetDateTime (java.time.OffsetDateTime)8 Test (org.junit.jupiter.api.Test)7 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)6 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)6 IOException (java.io.IOException)6 SessionTest (com.yahoo.vespa.config.server.session.SessionTest)5 OffsetTime (java.time.OffsetTime)5 ZoneOffset (java.time.ZoneOffset)5 Chronology (java.time.chrono.Chronology)5 IsoChronology (java.time.chrono.IsoChronology)5 Date (java.util.Date)4