use of java.time.Duration in project neo4j by neo4j.
the class TransactionStateMachineSPITest method throwsWhenTxAwaitDurationExpires.
@Test
public void throwsWhenTxAwaitDurationExpires() throws Exception {
long lastClosedTransactionId = 100;
TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
Duration txAwaitDuration = Duration.ofSeconds(42);
FakeClock clock = new FakeClock();
AvailabilityGuard availabilityGuard = spy(new AvailabilityGuard(clock, NullLog.getInstance()));
when(availabilityGuard.isAvailable()).then(invocation -> {
boolean available = (boolean) invocation.callRealMethod();
clock.forward(txAwaitDuration.getSeconds() + 1, SECONDS);
return available;
});
TransactionStateMachineSPI txSpi = createTxSpi(txIdStore, txAwaitDuration, availabilityGuard, clock);
Future<Void> result = otherThread.execute(state -> {
txSpi.awaitUpToDate(lastClosedTransactionId + 42);
return null;
});
try {
result.get(20, SECONDS);
} catch (Exception e) {
assertThat(e, instanceOf(ExecutionException.class));
assertThat(e.getCause(), instanceOf(TransactionFailureException.class));
}
}
use of java.time.Duration in project VocabHunter by VocabHunter.
the class SessionWordsToolImpl method timedCollect.
private static <T extends List<?>> T timedCollect(final String type, final Supplier<T> s, final Path file) {
Instant start = Instant.now();
T words = s.get();
Instant end = Instant.now();
Duration duration = Duration.between(start, end);
String filename = FileNameTool.filename(file);
LOG.info("Read filter file and found {} words marked as {} in {}ms ({})", words.size(), type, duration.toMillis(), filename);
return words;
}
use of java.time.Duration in project jdk8u_jdk by JetBrains.
the class TCKDuration method factory_parse_comma.
@Test(dataProvider = "parseSuccess")
public void factory_parse_comma(String text, long expectedSeconds, int expectedNanoOfSecond) {
text = text.replace('.', ',');
Duration test = Duration.parse(text);
assertEquals(test.getSeconds(), expectedSeconds);
assertEquals(test.getNano(), expectedNanoOfSecond);
}
use of java.time.Duration in project jdk8u_jdk by JetBrains.
the class TCKDuration method minusHours_long.
@Test(dataProvider = "MinusHours")
public void minusHours_long(long hours, long amount, long expectedHours) {
Duration t = Duration.ofHours(hours);
t = t.minusHours(amount);
assertEquals(t.toHours(), expectedHours);
}
use of java.time.Duration in project jdk8u_jdk by JetBrains.
the class TCKDuration method plusOverflowTooBig.
@Test(expectedExceptions = ArithmeticException.class)
public void plusOverflowTooBig() {
Duration t = Duration.ofSeconds(Long.MAX_VALUE, 999999999);
t.plus(Duration.ofSeconds(0, 1));
}
Aggregations