diff options
author | Håkon Hallingstad <hakon@oath.com> | 2018-06-21 14:17:50 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@oath.com> | 2018-06-21 14:17:50 +0200 |
commit | 3b3920201ae893730e78fb1211f292233014d4df (patch) | |
tree | cf4c1b662e7e5f5ac717bcbaee96668b2c6438d6 | |
parent | bf4d047056ead5b91a8eb8c185a107e1c48aa5ad (diff) |
Use ManualClock and remove Unchecked prefix
-rw-r--r-- | orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorContext.java | 2 | ||||
-rw-r--r-- | orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClient.java | 6 | ||||
-rw-r--r-- | vespajlib/pom.xml | 6 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/time/TimeBudget.java | 4 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/time/TimeoutException.java (renamed from vespajlib/src/main/java/com/yahoo/time/UncheckedTimeoutException.java) | 8 | ||||
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/time/TimeBudgetTestCase.java | 13 |
6 files changed, 23 insertions, 16 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorContext.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorContext.java index 695fd51e8e4..8c9e624c8ff 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorContext.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorContext.java @@ -28,7 +28,7 @@ public class OrchestratorContext { /** * Get number of seconds until the deadline, or empty if there's no deadline, or throw - * an UncheckedTimeoutException if timed out. + * an TimeoutException if timed out. */ public Optional<Float> getSuboperationTimeoutInSeconds() { return Optional.of((float) (timeBudget.timeLeftOrThrow().toMillis() / 1000.0)); diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClient.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClient.java index 87907df4db2..45d258241cf 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClient.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClient.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.orchestrator.controller; -import com.yahoo.time.UncheckedTimeoutException; +import com.yahoo.time.TimeoutException; import com.yahoo.vespa.orchestrator.OrchestratorContext; import java.io.IOException; @@ -15,7 +15,7 @@ public interface ClusterControllerClient { * Requests that a cluster controller sets the requested node to the requested state. * * @throws IOException if there was a problem communicating with the cluster controller - * @throws UncheckedTimeoutException if operation times out + * @throws TimeoutException if operation times out */ ClusterControllerStateResponse setNodeState(OrchestratorContext context, int storageNodeIndex, ClusterControllerNodeState wantedState) throws IOException; @@ -23,7 +23,7 @@ public interface ClusterControllerClient { * Requests that a cluster controller sets all nodes in the cluster to the requested state. * * @throws IOException if there was a problem communicating with the cluster controller - * @throws UncheckedTimeoutException if operation times out + * @throws TimeoutException if operation times out */ ClusterControllerStateResponse setApplicationState(OrchestratorContext context, ClusterControllerNodeState wantedState) throws IOException; diff --git a/vespajlib/pom.xml b/vespajlib/pom.xml index 81c385c96ab..880d039bc54 100644 --- a/vespajlib/pom.xml +++ b/vespajlib/pom.xml @@ -71,6 +71,12 @@ <groupId>org.apache.commons</groupId> <artifactId>commons-exec</artifactId> </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>testutil</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> </dependencies> <build> <plugins> diff --git a/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java b/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java index 6f28d5d80e8..fe2657585bc 100644 --- a/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java +++ b/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java @@ -40,13 +40,13 @@ public class TimeBudget { * Returns the time until deadline. * * @return time until deadline. It's toMillis() is guaranteed to be positive. - * @throws UncheckedTimeoutException if the deadline has been reached or passed. + * @throws TimeoutException if the deadline has been reached or passed. */ public Duration timeLeftOrThrow() { Instant now = clock.instant(); Duration left = Duration.between(now, start.plus(timeout)); if (left.toMillis() <= 0) { - throw new UncheckedTimeoutException("Time since start " + nonNegativeBetween(start, now) + + throw new TimeoutException("Time since start " + nonNegativeBetween(start, now) + " exceeds timeout " + timeout); } diff --git a/vespajlib/src/main/java/com/yahoo/time/UncheckedTimeoutException.java b/vespajlib/src/main/java/com/yahoo/time/TimeoutException.java index 3b53ffbdcf6..098d42ddb94 100644 --- a/vespajlib/src/main/java/com/yahoo/time/UncheckedTimeoutException.java +++ b/vespajlib/src/main/java/com/yahoo/time/TimeoutException.java @@ -4,15 +4,15 @@ package com.yahoo.time; /** * Exception thrown when a blocking operation times out. * - * <p>Mirrors {@link java.util.concurrent.TimeoutException} + * <p>Unchecked variant of {@link java.util.concurrent.TimeoutException} * * @author hakon */ @SuppressWarnings("serial") -public class UncheckedTimeoutException extends RuntimeException { - public UncheckedTimeoutException() { } +public class TimeoutException extends RuntimeException { + public TimeoutException() { } - public UncheckedTimeoutException(String message) { + public TimeoutException(String message) { super(message); } } diff --git a/vespajlib/src/test/java/com/yahoo/time/TimeBudgetTestCase.java b/vespajlib/src/test/java/com/yahoo/time/TimeBudgetTestCase.java index ef664f95d33..7f55272c2ec 100644 --- a/vespajlib/src/test/java/com/yahoo/time/TimeBudgetTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/time/TimeBudgetTestCase.java @@ -1,6 +1,7 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.time; +import com.yahoo.test.ManualClock; import org.junit.Test; import java.time.Clock; @@ -10,28 +11,28 @@ import java.time.Instant; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class TimeBudgetTestCase { private final Clock clock = mock(Clock.class); @Test public void testBasics() { - when(clock.instant()).thenReturn(Instant.ofEpochSecond(0)); + ManualClock clock = new ManualClock(); + clock.setInstant(Instant.ofEpochSecond(0)); TimeBudget timeBudget = TimeBudget.fromNow(clock, Duration.ofSeconds(10)); - when(clock.instant()).thenReturn(Instant.ofEpochSecond(7)); + clock.advance(Duration.ofSeconds(7)); assertEquals(Duration.ofSeconds(3), timeBudget.timeLeftOrThrow()); // Verify that toMillis() of >=1 is fine, but 0 is not. - when(clock.instant()).thenReturn(Instant.ofEpochSecond(9, 999000000)); + clock.setInstant(Instant.ofEpochSecond(9, 999000000)); assertEquals(1, timeBudget.timeLeftOrThrow().toMillis()); - when(clock.instant()).thenReturn(Instant.ofEpochSecond(9, 999000001)); + clock.setInstant(Instant.ofEpochSecond(9, 999000001)); try { timeBudget.timeLeftOrThrow(); fail(); - } catch (UncheckedTimeoutException e) { + } catch (TimeoutException e) { // OK } } |