diff options
author | Harald Musum <musum@oath.com> | 2018-06-21 20:37:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-21 20:37:42 +0200 |
commit | 12aa9c3f161790b665259910a7c8f41706ba6682 (patch) | |
tree | bfaccaef6f0f4cf8052f573656bb57a844eb6cb9 /jdisc_core/src/test | |
parent | 18b49613b7f2a62281b3275563d8e0b8b284b201 (diff) |
Revert "Move TimeBudget to vespajlib and use Clock"
Diffstat (limited to 'jdisc_core/src/test')
-rw-r--r-- | jdisc_core/src/test/java/com/yahoo/jdisc/TimeBudgetTestCase.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/TimeBudgetTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/TimeBudgetTestCase.java new file mode 100644 index 00000000000..5afc205beb3 --- /dev/null +++ b/jdisc_core/src/test/java/com/yahoo/jdisc/TimeBudgetTestCase.java @@ -0,0 +1,29 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.jdisc; + +import org.junit.Test; + +import java.time.Duration; +import java.time.Instant; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class TimeBudgetTestCase { + private final Timer timer = mock(Timer.class); + + @Test + public void testBasics() { + when(timer.currentTime()).thenReturn(Instant.ofEpochSecond(0)); + TimeBudget timeBudget = TimeBudget.fromNow(timer, Duration.ofSeconds(10)); + + when(timer.currentTime()).thenReturn(Instant.ofEpochSecond(7)); + assertEquals(Duration.ofSeconds(3), timeBudget.timeBeforeDeadline(Duration.ofSeconds(0))); + assertEquals(Duration.ofSeconds(1), timeBudget.timeBeforeDeadline(Duration.ofSeconds(2))); + assertEquals(Duration.ofSeconds(0), timeBudget.timeBeforeDeadline(Duration.ofSeconds(5))); + + when(timer.currentTime()).thenReturn(Instant.ofEpochSecond(11)); + assertEquals(Duration.ofSeconds(0), timeBudget.timeBeforeDeadline(Duration.ofSeconds(0))); + } +}
\ No newline at end of file |