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