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