aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@verizonmedia.com>2019-03-05 15:52:54 +0100
committerValerij Fredriksen <valerijf@verizonmedia.com>2019-03-06 12:35:16 +0100
commitb601044040bb3526e5dfaf3688bac48c1b83b625 (patch)
treeb057562ed61119123ba9e114572de997257a267e /container-core/src/test/java
parentb7264e3244c183bb9c266d5d6ad243ab594b93fd (diff)
Make LogHandler configurable
Diffstat (limited to 'container-core/src/test/java')
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/LogHandlerTest.java11
-rw-r--r--container-core/src/test/java/com/yahoo/container/handler/LogReaderTest.java33
2 files changed, 26 insertions, 18 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 365b0313cf8..d578a745c9e 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
@@ -9,9 +9,10 @@ import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.time.Instant;
import java.util.concurrent.Executor;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
public class LogHandlerTest {
@@ -43,9 +44,13 @@ public class LogHandlerTest {
}
class MockLogReader extends LogReader {
+ MockLogReader() {
+ super("", "");
+ }
+
@Override
- protected JSONObject readLogs(String logDirectory, long earliestLogThreshold, long latestLogThreshold) throws JSONException {
- if(latestLogThreshold > 1000) {
+ protected JSONObject readLogs(Instant earliestLogThreshold, Instant latestLogThreshold) throws JSONException {
+ if (latestLogThreshold.isAfter(Instant.ofEpochMilli(1000))) {
return new JSONObject("{\"one\":\"newer_log\"}");
} else {
return new JSONObject("{\"two\":\"older_log\"}");
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 d7c802faa3b..647dc571e75 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
@@ -2,28 +2,23 @@
package com.yahoo.container.handler;
import org.json.JSONObject;
-import org.junit.Before;
import org.junit.Test;
-import java.io.ByteArrayOutputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.time.Instant;
+import java.util.regex.Pattern;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
public class LogReaderTest {
- ByteArrayOutputStream outputStream;
-
- @Before
- public void setup() {
- outputStream = new ByteArrayOutputStream();
- }
+ private final Path logDirectory = Paths.get("src/test/resources/logfolder/");
@Test
public void testThatFilesAreWrittenCorrectlyToOutputStream() throws Exception{
- String logDirectory = "src/test/resources/logfolder/";
- LogReader logReader = new LogReader();
- JSONObject json = logReader.readLogs(logDirectory, 21, Instant.now().toEpochMilli());
+ LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*"));
+ JSONObject json = logReader.readLogs(Instant.ofEpochMilli(21), Instant.now());
String expected = "{\"subfolder-log2.log\":\"VGhpcyBpcyBhbm90aGVyIGxvZyBmaWxl\",\"log1.log\":\"VGhpcyBpcyBvbmUgbG9nIGZpbGU=\"}";
String actual = json.toString();
assertEquals(expected, actual);
@@ -31,11 +26,19 @@ public class LogReaderTest {
@Test
public void testThatLogsOutsideRangeAreExcluded() throws Exception {
- String logDirectory = "src/test/resources/logfolder/";
- LogReader logReader = new LogReader();
- JSONObject json = logReader.readLogs(logDirectory, Long.MAX_VALUE, Long.MIN_VALUE);
+ LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*"));
+ JSONObject json = logReader.readLogs(Instant.MAX, Instant.MIN);
String expected = "{}";
String actual = json.toString();
assertEquals(expected, actual);
}
+
+ @Test
+ public void testThatLogsNotMatchingRegexAreExcluded() throws Exception {
+ LogReader logReader = new LogReader(logDirectory, Pattern.compile(".*2\\.log"));
+ JSONObject json = logReader.readLogs(Instant.ofEpochMilli(21), Instant.now());
+ String expected = "{\"subfolder-log2.log\":\"VGhpcyBpcyBhbm90aGVyIGxvZyBmaWxl\"}";
+ String actual = json.toString();
+ assertEquals(expected, actual);
+ }
}