aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/container/jdisc
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@verizonmedia.com>2019-10-25 12:14:54 +0200
committerOla Aunrønning <olaa@verizonmedia.com>2019-10-25 12:20:41 +0200
commit57fc9b631319ab522971c9272ecc6c84a9045343 (patch)
tree80f4308c27ca36ecf4976925b115c31e58de78b2 /container-core/src/test/java/com/yahoo/container/jdisc
parentcce1d7872328f95c32567da873b061d974b5c862 (diff)
Reuse same coredump/host-life gatherers
Diffstat (limited to 'container-core/src/test/java/com/yahoo/container/jdisc')
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/state/CoredumpGathererTest.java43
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/state/HostLifeGathererTest.java38
2 files changed, 81 insertions, 0 deletions
diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/state/CoredumpGathererTest.java b/container-core/src/test/java/com/yahoo/container/jdisc/state/CoredumpGathererTest.java
new file mode 100644
index 00000000000..c1f7d790fa5
--- /dev/null
+++ b/container-core/src/test/java/com/yahoo/container/jdisc/state/CoredumpGathererTest.java
@@ -0,0 +1,43 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.jdisc.state;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.Test;
+
+import java.nio.file.Path;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * @author olaa
+ */
+public class CoredumpGathererTest {
+
+ @Test
+ public void finds_one_coredump() throws JSONException {
+ JSONObject packet = CoredumpGatherer.gatherCoredumpMetrics(new MockFileWrapper());
+
+ assertEquals("system-coredumps-processing", packet.getString("application"));
+ assertEquals(1, packet.getInt("status_code"));
+ assertEquals("Found 1 coredump(s)", packet.getString("status_msg"));
+
+ }
+
+ static class MockFileWrapper extends FileWrapper {
+
+
+ @Override
+ Stream<Path> walkTree(Path path) {
+ return Stream.of(Path.of("dummy-path"));
+ }
+
+ @Override
+ boolean isRegularFile(Path path) {
+ return true;
+ }
+ }
+
+}
diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/state/HostLifeGathererTest.java b/container-core/src/test/java/com/yahoo/container/jdisc/state/HostLifeGathererTest.java
new file mode 100644
index 00000000000..d025b9662d2
--- /dev/null
+++ b/container-core/src/test/java/com/yahoo/container/jdisc/state/HostLifeGathererTest.java
@@ -0,0 +1,38 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.jdisc.state;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.Test;
+
+import java.nio.file.Path;
+
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * @author olaa
+ */
+public class HostLifeGathererTest {
+
+ @Test
+ public void host_is_alive() throws JSONException {
+ JSONObject packet = HostLifeGatherer.getHostLifePacket(new MockFileWrapper());
+ JSONObject metrics = packet.getJSONObject("metrics");
+ assertEquals("host_life", packet.getString("application"));
+ assertEquals(0, packet.getInt("status_code"));
+ assertEquals("OK", packet.getString("status_msg"));
+
+ assertEquals(123l, metrics.getLong("uptime"));
+ assertEquals(1, metrics.getInt("alive"));
+
+ }
+
+ static class MockFileWrapper extends FileWrapper {
+
+ @Override
+ long getFileAgeInSeconds(Path path) {
+ return 123;
+ }
+ }
+}