summaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/container/jdisc/state/HostLifeGathererTest.java
blob: d025b9662d2e41614435aeca1dc97fedfecb21f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
        }
    }
}