summaryrefslogtreecommitdiffstats
path: root/container-core/src/test
diff options
context:
space:
mode:
authorValerij Fredriksen <freva@users.noreply.github.com>2022-09-22 09:50:13 +0200
committerGitHub <noreply@github.com>2022-09-22 09:50:13 +0200
commitefb808cff3a51f8eba15fb6bc43e8b53ae17143c (patch)
tree92047a30199c596a75a489deae80316ac74e2586 /container-core/src/test
parent1957bf2e63c2ad903bd1f6ccbde48de1141dca11 (diff)
Revert "Revert "Make it possible to limit number of log lines returned" (#24168)"
This reverts commit d058fe597d6ba98f27c146cf725752aab1405772.
Diffstat (limited to 'container-core/src/test')
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java2
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java30
2 files changed, 16 insertions, 16 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java
index 3d9a2360e77..8b698b25ab2 100644
--- a/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java
+++ b/container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java
@@ -51,7 +51,7 @@ public class LogHandlerTest {
}
@Override
- protected void writeLogs(OutputStream out, Instant from, Instant to, Optional<String> hostname) {
+ protected void writeLogs(OutputStream out, Instant from, Instant to, long maxLines, Optional<String> hostname) {
try {
if (to.isAfter(Instant.ofEpochMilli(1000))) {
out.write("newer log".getBytes());
diff --git a/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java b/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java
index 106b8cef35f..e98f8cac276 100644
--- a/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java
+++ b/container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java
@@ -37,7 +37,7 @@ public class LogReaderTest {
@BeforeEach
public void setup() throws IOException {
- logDirectory = newFolder(folder, "opt/vespa/logs").toPath();
+ logDirectory = Files.createDirectories(folder.toPath().resolve("opt/vespa/logs"));
// Log archive paths and file names indicate what hour they contain logs for, with the start of that hour.
// Multiple entries may exist for each hour.
Files.createDirectories(logDirectory.resolve("1970/01/01"));
@@ -59,7 +59,7 @@ public class LogReaderTest {
void testThatLogsOutsideRangeAreExcluded() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*"));
- logReader.writeLogs(baos, Instant.ofEpochMilli(150), Instant.ofEpochMilli(3601050), Optional.empty());
+ logReader.writeLogs(baos, Instant.ofEpochMilli(150), Instant.ofEpochMilli(3601050), 100, Optional.empty());
assertEquals(log100 + logv11 + log110, baos.toString(UTF_8));
}
@@ -68,7 +68,7 @@ public class LogReaderTest {
void testThatLogsNotMatchingRegexAreExcluded() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*-1.*"));
- logReader.writeLogs(baos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2)), Optional.empty());
+ logReader.writeLogs(baos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2)), 100, Optional.empty());
assertEquals(log101 + logv11, baos.toString(UTF_8));
}
@@ -78,7 +78,7 @@ public class LogReaderTest {
void testZippedStreaming() {
ByteArrayOutputStream zippedBaos = new ByteArrayOutputStream();
LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*"));
- logReader.writeLogs(zippedBaos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2)), Optional.empty());
+ logReader.writeLogs(zippedBaos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2)), 100, Optional.empty());
assertEquals(log101 + log100 + logv11 + log110 + log200 + logv, zippedBaos.toString(UTF_8));
}
@@ -87,11 +87,20 @@ public class LogReaderTest {
void logsForSingeNodeIsRetrieved() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*"));
- logReader.writeLogs(baos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2)), Optional.of("node2.com"));
+ logReader.writeLogs(baos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2)), 100, Optional.of("node2.com"));
assertEquals(log101 + log100 + log200, baos.toString(UTF_8));
}
+ @Test
+ void logsLimitedToMaxLines() {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*"));
+ logReader.writeLogs(baos, Instant.EPOCH, Instant.EPOCH.plus(Duration.ofDays(2)), 2, Optional.of("node2.com"));
+
+ assertEquals(log101 + log100, baos.toString(UTF_8));
+ }
+
private byte[] compress1(String input) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream zip = new GZIPOutputStream(baos);
@@ -100,18 +109,9 @@ public class LogReaderTest {
return baos.toByteArray();
}
- private byte[] compress2(String input) throws IOException {
+ private byte[] compress2(String input) {
byte[] data = input.getBytes();
return new ZstdCompressor().compress(data, 0, data.length);
}
- private static File newFolder(File root, String... subDirs) throws IOException {
- String subFolder = String.join("/", subDirs);
- File result = new File(root, subFolder);
- if (!result.mkdirs()) {
- throw new IOException("Couldn't create folders " + root);
- }
- return result;
- }
-
}