Search in sources :

Example 1 with Duration

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));
    }
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) FakeClock(org.neo4j.time.FakeClock) Duration(java.time.Duration) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) ExecutionException(java.util.concurrent.ExecutionException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) Test(org.junit.Test)

Example 2 with Duration

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;
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration)

Example 3 with Duration

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);
}
Also used : Duration(java.time.Duration) Test(org.testng.annotations.Test)

Example 4 with Duration

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);
}
Also used : Duration(java.time.Duration) Test(org.testng.annotations.Test)

Example 5 with Duration

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));
}
Also used : Duration(java.time.Duration) Test(org.testng.annotations.Test)

Aggregations

Duration (java.time.Duration)1205 Test (org.junit.Test)418 Test (org.testng.annotations.Test)139 Instant (java.time.Instant)128 Test (org.junit.jupiter.api.Test)83 List (java.util.List)82 ArrayList (java.util.ArrayList)81 CompletableFuture (java.util.concurrent.CompletableFuture)81 Collectors (java.util.stream.Collectors)73 Collections (java.util.Collections)62 Preconditions (com.google.common.base.Preconditions)61 Map (java.util.Map)60 Slf4j (lombok.extern.slf4j.Slf4j)59 lombok.val (lombok.val)55 HashMap (java.util.HashMap)54 Arrays (java.util.Arrays)52 Function (java.util.function.Function)51 IOException (java.io.IOException)49 HashSet (java.util.HashSet)47 TimeUnit (java.util.concurrent.TimeUnit)47