summaryrefslogtreecommitdiffstats
path: root/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java')
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java73
1 files changed, 42 insertions, 31 deletions
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java
index 0f7f97d333a..eb5422f5cff 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java
@@ -10,7 +10,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockRunDataStore;
import com.yahoo.vespa.hosted.controller.deployment.DeploymentContext;
import com.yahoo.vespa.hosted.controller.deployment.RunLog;
import com.yahoo.vespa.hosted.controller.deployment.Step;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.util.ArrayList;
@@ -20,21 +20,21 @@ import java.util.Optional;
import java.util.stream.IntStream;
import static java.util.stream.Collectors.toUnmodifiableList;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class BufferedLogStoreTest {
@Test
- public void chunkingAndFlush() {
+ void chunkingAndFlush() {
int chunkSize = 1 << 10;
int maxChunks = 1 << 5;
CuratorDb buffer = new MockCuratorDb(SystemName.main);
RunDataStore store = new MockRunDataStore();
BufferedLogStore logs = new BufferedLogStore(chunkSize, chunkSize * maxChunks, buffer, store);
RunId id = new RunId(ApplicationId.from("tenant", "application", "instance"),
- DeploymentContext.productionUsWest1,
- 123);
+ DeploymentContext.productionUsWest1,
+ 123);
byte[] manyBytes = new byte[chunkSize / 2 + 1]; // One fits, and two (over-)fills.
Arrays.fill(manyBytes, (byte) 'O');
@@ -50,29 +50,29 @@ public class BufferedLogStoreTest {
assertEquals(Optional.empty(), logs.readFinished(id, -1));
assertEquals(RunLog.empty(), logs.readActive(id.application(), id.type(), -1));
- logs.append(id.application(), id.type(), Step.deployReal, List.of(entry));
+ logs.append(id.application(), id.type(), Step.deployReal, List.of(entry), false);
assertEquals(List.of(entry0),
- logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
+ logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
assertEquals(RunLog.empty(), logs.readActive(id.application(), id.type(), 0));
- logs.append(id.application(), id.type(), Step.deployReal, List.of(entry));
+ logs.append(id.application(), id.type(), Step.deployReal, List.of(entry), false);
assertEquals(List.of(entry0, entry1),
- logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
+ logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
assertEquals(List.of(entry1),
- logs.readActive(id.application(), id.type(), 0).get(Step.deployReal));
+ logs.readActive(id.application(), id.type(), 0).get(Step.deployReal));
assertEquals(RunLog.empty(), logs.readActive(id.application(), id.type(), 1));
- logs.append(id.application(), id.type(), Step.deployReal, List.of(entry, entry, entry));
+ logs.append(id.application(), id.type(), Step.deployReal, List.of(entry, entry, entry), false);
assertEquals(List.of(entry0, entry1, entry2, entry3, entry4),
- logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
+ logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
assertEquals(List.of(entry1, entry2, entry3, entry4),
- logs.readActive(id.application(), id.type(), 0).get(Step.deployReal));
+ logs.readActive(id.application(), id.type(), 0).get(Step.deployReal));
assertEquals(List.of(entry2, entry3, entry4),
- logs.readActive(id.application(), id.type(), 1).get(Step.deployReal));
+ logs.readActive(id.application(), id.type(), 1).get(Step.deployReal));
assertEquals(List.of(entry3, entry4),
- logs.readActive(id.application(), id.type(), 2).get(Step.deployReal));
+ logs.readActive(id.application(), id.type(), 2).get(Step.deployReal));
assertEquals(List.of(entry4),
- logs.readActive(id.application(), id.type(), 3).get(Step.deployReal));
+ logs.readActive(id.application(), id.type(), 3).get(Step.deployReal));
assertEquals(RunLog.empty(), logs.readActive(id.application(), id.type(), 4));
// We should now have three chunks, with two, two, and one entries.
@@ -86,40 +86,51 @@ public class BufferedLogStoreTest {
assertEquals(RunLog.empty(), logs.readActive(id.application(), id.type(), -1));
assertEquals(List.of(entry0, entry1, entry2, entry3, entry4),
- logs.readFinished(id, -1).get().get(Step.deployReal));
+ logs.readFinished(id, -1).get().get(Step.deployReal));
assertEquals(List.of(entry1, entry2, entry3, entry4),
- logs.readFinished(id, 0).get().get(Step.deployReal));
+ logs.readFinished(id, 0).get().get(Step.deployReal));
assertEquals(List.of(entry2, entry3, entry4),
- logs.readFinished(id, 1).get().get(Step.deployReal));
+ logs.readFinished(id, 1).get().get(Step.deployReal));
assertEquals(List.of(entry3, entry4),
- logs.readFinished(id, 2).get().get(Step.deployReal));
+ logs.readFinished(id, 2).get().get(Step.deployReal));
assertEquals(List.of(entry4),
- logs.readFinished(id, 3).get().get(Step.deployReal));
+ logs.readFinished(id, 3).get().get(Step.deployReal));
assertEquals(List.of(), logs.readFinished(id, 4).get().get(Step.deployReal));
// Logging a large entry enough times to reach the maximum size causes no further entries to be stored.
List<LogEntry> monsterLog = IntStream.range(0, 2 * maxChunks + 3)
- .mapToObj(i -> new LogEntry(i, entry.at(), entry.type(), entry.message()))
- .collect(toUnmodifiableList());
+ .mapToObj(i -> new LogEntry(i, entry.at(), entry.type(), entry.message()))
+ .collect(toUnmodifiableList());
List<LogEntry> logged = new ArrayList<>(monsterLog);
logged.remove(logged.size() - 1);
logged.remove(logged.size() - 1);
logged.remove(logged.size() - 1);
- logged.add(new LogEntry(2 * maxChunks, entry.at(), LogEntry.Type.warning, "Max log size of " + ((chunkSize * maxChunks) >> 20) + "Mb exceeded; further entries are discarded."));
+ logged.add(new LogEntry(2 * maxChunks, entry.at(), LogEntry.Type.warning, "Max log size of " + ((chunkSize * maxChunks) >> 20) + "Mb exceeded; further user entries are discarded."));
- logs.append(id.application(), id.type(), Step.deployReal, monsterLog);
+ logs.append(id.application(), id.type(), Step.deployReal, monsterLog, false);
assertEquals(logged.size(),
- logs.readActive(id.application(), id.type(), -1).get(Step.deployReal).size());
+ logs.readActive(id.application(), id.type(), -1).get(Step.deployReal).size());
assertEquals(logged,
- logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
+ logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
+ // An additional, forced entry is appended.
+ LogEntry forced = new LogEntry(logged.size(), entry.at(), entry.type(), entry.message());
+ logs.append(id.application(), id.type(), Step.deployReal, List.of(forced), true);
+ logged.add(forced);
+ assertEquals(logged.size(),
+ logs.readActive(id.application(), id.type(), -1).get(Step.deployReal).size());
+ assertEquals(logged,
+ logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
+ logged.remove(logged.size() - 1);
+
+ // Flushing the buffer clears it again, and makes it ready for reuse.
logs.flush(id);
for (int i = 0; i < 2 * maxChunks + 3; i++)
- logs.append(id.application(), id.type(), Step.deployReal, List.of(entry));
+ logs.append(id.application(), id.type(), Step.deployReal, List.of(entry), false);
assertEquals(logged.size(),
- logs.readActive(id.application(), id.type(), -1).get(Step.deployReal).size());
+ logs.readActive(id.application(), id.type(), -1).get(Step.deployReal).size());
assertEquals(logged,
- logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
+ logs.readActive(id.application(), id.type(), -1).get(Step.deployReal));
}
}