summaryrefslogtreecommitdiffstats
path: root/orchestrator
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-02-22 10:13:33 +0100
committerJon Marius Venstad <venstad@gmail.com>2021-02-22 10:13:33 +0100
commit046dbbf99f17b2c50abab59edbc614391f9f3160 (patch)
tree84b8639edbb5fbe3e2625c827ab1ed9719230fe7 /orchestrator
parenteaaeaf82d016ed8edd081bc63faafaa756aa35fe (diff)
Avoid sleeping for 10s during unit test
Diffstat (limited to 'orchestrator')
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkStatusService.java2
-rw-r--r--orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZkStatusServiceTest.java35
2 files changed, 20 insertions, 17 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkStatusService.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkStatusService.java
index a67991a4bf6..daafc81e0f3 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkStatusService.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkStatusService.java
@@ -127,7 +127,7 @@ public class ZkStatusService implements StatusService {
Runnable onRegistryClose;
// A multi-application operation, aka batch suspension, will first issue a probe
- // then a non-probe. With "large locks", the lock is not release in between -
+ // then a non-probe. With "large locks", the lock is not released in between -
// no lock is taken on the non-probe. Instead, the release is done on the multi-application
// context close.
if (context.hasLock(reference)) {
diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZkStatusServiceTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZkStatusServiceTest.java
index 9a79828bc7b..fa53ff7f996 100644
--- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZkStatusServiceTest.java
+++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZkStatusServiceTest.java
@@ -70,7 +70,6 @@ public class ZkStatusServiceTest {
private final Timer timer = mock(Timer.class);
private final Metric metric = mock(Metric.class);
private final OrchestratorContext context = mock(OrchestratorContext.class);
- private final InMemoryFlagSource flagSource = new InMemoryFlagSource();
private final CriticalRegion criticalRegion = mock(CriticalRegion.class);
private final AntiServiceMonitor antiServiceMonitor = mock(AntiServiceMonitor.class);
@@ -163,24 +162,26 @@ public class ZkStatusServiceTest {
}
@Test
- public void failing_to_get_lock_closes_SessionFailRetryLoop() throws Exception {
+ public void failing_to_get_lock_closes_SessionFailRetryLoop() {
+ when(context.getTimeLeft()).thenReturn(Duration.ofMillis(100));
ZkStatusService zkStatusService2 =
new ZkStatusService(curator, mock(Metric.class), new TestTimer(), antiServiceMonitor);
try (ApplicationLock lock = statusService
.lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) {
- //must run in separate thread, since having 2 locks in the same thread fails
+ // must run in separate thread, since having 2 locks in the same thread fails
CompletableFuture<Void> resultOfZkOperationAfterLockFailure = CompletableFuture.runAsync(() -> {
try {
zkStatusService2.lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE);
fail("Both zookeeper host status services locked simultaneously for the same application instance");
- } catch (RuntimeException e) {
+ }
+ catch (RuntimeException expected) { }
+ finally {
+ killSession(curator.framework(), testingServer);
}
- killSession(curator.framework(), testingServer);
-
- //Throws SessionFailedException if the SessionFailRetryLoop has not been closed.
+ // Throws SessionFailedException if the SessionFailRetryLoop has not been closed.
lock.getHostInfos().getOrNoRemarks(TestIds.HOST_NAME1);
});
@@ -192,19 +193,21 @@ public class ZkStatusServiceTest {
//https://code.google.com/p/hamcrest/issues/detail?id=107 Confusing failure description when using negation
//Creating not(holdsException) directly instead.
private Matcher<Future<?>> notHoldsException() {
- return new TypeSafeMatcher<Future<?>>() {
+ return new TypeSafeMatcher<>() {
@Override
protected boolean matchesSafely(Future<?> item) {
- return !getException(item).isPresent();
+ return getException(item).isEmpty();
}
private Optional<Throwable> getException(Future<?> item) {
try {
item.get();
return Optional.empty();
- } catch (ExecutionException e) {
+ }
+ catch (ExecutionException e) {
return Optional.of(e.getCause());
- } catch (InterruptedException e) {
+ }
+ catch (InterruptedException e) {
return Optional.of(e);
}
}
@@ -216,11 +219,11 @@ public class ZkStatusServiceTest {
@Override
protected void describeMismatchSafely(Future<?> item, Description mismatchDescription) {
- getException(item).ifPresent( throwable ->
- mismatchDescription
- .appendText("Got exception: ")
- .appendText(Exceptions.toMessageString(throwable))
- .appendText(ExceptionUtils.getStackTraceRecursivelyAsString(throwable)));
+ getException(item).ifPresent(throwable ->
+ mismatchDescription
+ .appendText("Got exception: ")
+ .appendText(Exceptions.toMessageString(throwable))
+ .appendText(ExceptionUtils.getStackTraceRecursivelyAsString(throwable)));
}
};
}