diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2018-07-04 11:45:23 +0200 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2018-07-04 11:45:23 +0200 |
commit | 7b10c6fab21895ddd635c9a221f3da23b99a21bc (patch) | |
tree | f611acb68878a50f3ac84cd0479f60f03ed790c3 /controller-api | |
parent | 18df18885a485d337f828c1b585932b0a6041ed3 (diff) |
Append, rather than set, logs, and fix unstable unit test
Diffstat (limited to 'controller-api')
2 files changed, 16 insertions, 13 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogStore.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogStore.java index ef2d9077892..23da48b4aad 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogStore.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogStore.java @@ -11,12 +11,12 @@ import java.util.Optional; public interface LogStore { /** @return the log of the given step of the given deployment job, or an empty byte array if non-existent. */ - byte[] getLog(RunId id, String step); + byte[] get(RunId id, String step); /** Stores the given log for the given step of the given deployment job. */ - void setLog(RunId id, String step, byte[] log); + void append(RunId id, String step, byte[] log); /** Deletes all data associated with the given deployment job */ - void deleteTestData(RunId id); + void delete(RunId id); } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockLogStore.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockLogStore.java index 61e6ac1004b..330b967c1b5 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockLogStore.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockLogStore.java @@ -4,6 +4,7 @@ package com.yahoo.vespa.hosted.controller.api.integration.stubs; import com.yahoo.vespa.hosted.controller.api.integration.LogStore; import com.yahoo.vespa.hosted.controller.api.integration.deployment.RunId; +import java.util.Collections; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -12,24 +13,26 @@ import java.util.concurrent.ConcurrentHashMap; */ public class MockLogStore implements LogStore { - private final Map<RunId, Map<String, byte[]>> storage = new ConcurrentHashMap<>(); + private final Map<RunId, Map<String, byte[]>> logs = new ConcurrentHashMap<>(); @Override - public byte[] getLog(RunId id, String step) { - return storage.containsKey(id) && storage.get(id).containsKey(step) - ? storage.get(id).get(step) - : new byte[0]; + public byte[] get(RunId id, String step) { + return logs.getOrDefault(id, Collections.emptyMap()).getOrDefault(step, new byte[0]); } @Override - public void setLog(RunId id, String step, byte[] log) { - storage.putIfAbsent(id, new ConcurrentHashMap<>()); - storage.get(id).put(step, log); + public void append(RunId id, String step, byte[] log) { + logs.putIfAbsent(id, new ConcurrentHashMap<>()); + byte[] old = get(id, step); + byte[] union = new byte[old.length + log.length]; + System.arraycopy(old, 0, union, 0, old.length); + System.arraycopy(log, 0, union, old.length, log.length); + logs.get(id).put(step, union); } @Override - public void deleteTestData(RunId id) { - storage.remove(id); + public void delete(RunId id) { + logs.remove(id); } } |