Search in sources :

Example 61 with Clock

use of java.time.Clock in project java8-tutorial by winterbe.

the class LocalTime1 method main.

public static void main(String[] args) {
    // get the current time
    Clock clock = Clock.systemDefaultZone();
    long t0 = clock.millis();
    System.out.println(t0);
    Instant instant = clock.instant();
    Date legacyDate = Date.from(instant);
    ZoneId zone1 = ZoneId.of("Europe/Berlin");
    ZoneId zone2 = ZoneId.of("Brazil/East");
    System.out.println(zone1.getRules());
    System.out.println(zone2.getRules());
    // time
    LocalTime now1 = LocalTime.now(zone1);
    LocalTime now2 = LocalTime.now(zone2);
    System.out.println(now1);
    System.out.println(now2);
    // false
    System.out.println(now1.isBefore(now2));
    long hoursBetween = ChronoUnit.HOURS.between(now1, now2);
    long minutesBetween = ChronoUnit.MINUTES.between(now1, now2);
    System.out.println(hoursBetween);
    System.out.println(minutesBetween);
    // create time
    LocalTime now = LocalTime.now();
    System.out.println(now);
    LocalTime late = LocalTime.of(23, 59, 59);
    System.out.println(late);
    DateTimeFormatter germanFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(Locale.GERMAN);
    LocalTime leetTime = LocalTime.parse("13:37", germanFormatter);
    System.out.println(leetTime);
// to legacy date
}
Also used : ZoneId(java.time.ZoneId) LocalTime(java.time.LocalTime) Instant(java.time.Instant) Clock(java.time.Clock) DateTimeFormatter(java.time.format.DateTimeFormatter) Date(java.util.Date)

Example 62 with Clock

use of java.time.Clock in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method shouldIncludeBasicMetadata.

@Test
void shouldIncludeBasicMetadata() throws Throwable {
    // Given
    QueryStatistics queryStatistics = mock(QueryStatistics.class);
    when(queryStatistics.containsUpdates()).thenReturn(true);
    when(queryStatistics.getNodesCreated()).thenReturn(1);
    when(queryStatistics.getNodesDeleted()).thenReturn(2);
    when(queryStatistics.getRelationshipsCreated()).thenReturn(3);
    when(queryStatistics.getRelationshipsDeleted()).thenReturn(4);
    when(queryStatistics.getPropertiesSet()).thenReturn(5);
    when(queryStatistics.getIndexesAdded()).thenReturn(6);
    when(queryStatistics.getIndexesRemoved()).thenReturn(7);
    when(queryStatistics.getConstraintsAdded()).thenReturn(8);
    when(queryStatistics.getConstraintsRemoved()).thenReturn(9);
    when(queryStatistics.getLabelsAdded()).thenReturn(10);
    when(queryStatistics.getLabelsRemoved()).thenReturn(11);
    QueryExecution result = mock(QueryExecution.class);
    BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
    when(result.fieldNames()).thenReturn(new String[0]);
    when(result.executionType()).thenReturn(query(READ_WRITE));
    subscriber.onResultCompleted(queryStatistics);
    when(result.getNotifications()).thenReturn(Collections.emptyList());
    Clock clock = mock(Clock.class);
    when(clock.millis()).thenReturn(0L, 1337L);
    var stream = new TestAbstractCypherAdapterStream(result, subscriber, clock);
    // When
    MapValue meta = metadataOf(stream);
    // Then
    assertThat(meta.get("type")).isEqualTo(stringValue("rw"));
    assertThat(meta.get("stats")).isEqualTo(mapValues("nodes-created", intValue(1), "nodes-deleted", intValue(2), "relationships-created", intValue(3), "relationships-deleted", intValue(4), "properties-set", intValue(5), "indexes-added", intValue(6), "indexes-removed", intValue(7), "constraints-added", intValue(8), "constraints-removed", intValue(9), "labels-added", intValue(10), "labels-removed", intValue(11)));
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) MapValue(org.neo4j.values.virtual.MapValue) Clock(java.time.Clock) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 63 with Clock

use of java.time.Clock in project neo4j by neo4j.

the class AbstractCypherAdapterStreamTest method shouldPullAll.

@Test
void shouldPullAll() throws Throwable {
    // Given
    QueryExecution queryExecution = mock(QueryExecution.class);
    when(queryExecution.fieldNames()).thenReturn(new String[0]);
    when(queryExecution.executionType()).thenReturn(query(READ_WRITE));
    when(queryExecution.getNotifications()).thenReturn(Collections.emptyList());
    when(queryExecution.await()).thenReturn(true).thenReturn(false);
    BoltAdapterSubscriber subscriber = new BoltAdapterSubscriber();
    QueryStatistics queryStatistics = mock(QueryStatistics.class);
    when(queryStatistics.containsUpdates()).thenReturn(false);
    when(queryStatistics.getNodesCreated()).thenReturn(0);
    when(queryStatistics.getNodesDeleted()).thenReturn(0);
    when(queryStatistics.getRelationshipsCreated()).thenReturn(0);
    when(queryStatistics.getRelationshipsDeleted()).thenReturn(0);
    when(queryStatistics.getPropertiesSet()).thenReturn(0);
    when(queryStatistics.getIndexesAdded()).thenReturn(0);
    when(queryStatistics.getIndexesRemoved()).thenReturn(0);
    when(queryStatistics.getConstraintsAdded()).thenReturn(0);
    when(queryStatistics.getConstraintsRemoved()).thenReturn(0);
    when(queryStatistics.getLabelsAdded()).thenReturn(0);
    when(queryStatistics.getLabelsRemoved()).thenReturn(0);
    subscriber.onResultCompleted(queryStatistics);
    Clock clock = mock(Clock.class);
    var stream = new TestAbstractCypherAdapterStream(queryExecution, subscriber, clock);
    // When
    stream.handleRecords(mock(BoltResult.RecordConsumer.class), STREAM_LIMIT_UNLIMITED);
    // Then
    verify(queryExecution, times(2)).request(Long.MAX_VALUE);
    verify(queryExecution, times(2)).await();
}
Also used : QueryStatistics(org.neo4j.graphdb.QueryStatistics) BoltAdapterSubscriber(org.neo4j.bolt.runtime.statemachine.impl.BoltAdapterSubscriber) Clock(java.time.Clock) QueryExecution(org.neo4j.kernel.impl.query.QueryExecution) Test(org.junit.jupiter.api.Test)

Example 64 with Clock

use of java.time.Clock in project neo4j by neo4j.

the class HttpTransactionManager method scheduleTransactionTimeout.

private void scheduleTransactionTimeout(Duration timeout) {
    Clock clock = Clocks.systemClock();
    long timeoutMillis = timeout.toMillis();
    long runEvery = round(timeoutMillis / 2.0);
    jobScheduler.scheduleRecurring(Group.SERVER_TRANSACTION_TIMEOUT, systemJob("Timeout of HTTP transactions"), () -> {
        long maxAge = clock.millis() - timeoutMillis;
        transactionRegistry.rollbackSuspendedTransactionsIdleSince(maxAge);
    }, runEvery, MILLISECONDS);
}
Also used : Clock(java.time.Clock)

Example 65 with Clock

use of java.time.Clock in project beam by apache.

the class SqsUnboundedReaderTest method testExtendDeletedMessage.

@Test
public void testExtendDeletedMessage() throws IOException {
    setupMessages(DATA);
    Clock clock = mock(Clock.class);
    when(clock.millis()).thenReturn(currentTimeMillis());
    SqsUnboundedReader reader = new SqsUnboundedReader(mockSource, null, options, clock);
    // Read one message
    assertTrue(reader.start());
    assertEquals(DATA, reader.getCurrent().getBody());
    // Simulate already ACKed message after re-delivery to different reader
    String receiptHandle = reader.getCurrent().getReceiptHandle();
    testCase.getClient().deleteMessage(b -> b.queueUrl(testCase.getQueueUrl()).receiptHandle(receiptHandle));
    // Forward time to force extension of visibility
    when(clock.millis()).thenReturn(currentTimeMillis() + reader.getVisibilityTimeoutMs() * 8 / 10);
    // Advancing the reader will attempt extending the visibility of the only message received and
    // succeeds despite the invalid receipt handle, but there's no further message.
    assertFalse(reader.advance());
    reader.close();
}
Also used : Clock(java.time.Clock) 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