summaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/SystemPollerTest.java
blob: a42d52b7ea6ac33756324e985b251c2969abe641 (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
39
40
41
42
43
44
45
/*
 * Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
 */

package ai.vespa.metricsproxy.service;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

/**
 * @author Unknown
 */
public class SystemPollerTest {

    @Test
    public void testSystemPoller() {
        DummyService s = new DummyService(0, "id");
        List<VespaService> services = new ArrayList<>();
        services.add(s);

        SystemPoller poller = new SystemPoller(services, 60*5);
        assertThat(s.isAlive(), is(false));
        services.remove(0);
        poller.setServices(services);
        long n = poller.getPidJiffies(s);
        assertThat(n, is(0L));
        long[] memusage = poller.getMemoryUsage(s);
        assertThat(memusage[0], is(0L));
        assertThat(memusage[1], is(0L));
    }

    @Test
    public void testCPUJiffies() {
        String line = "cpu1  102180864 789 56766899 12800020140 1654757 0 0";
        CpuJiffies n = new CpuJiffies(line);
        assertThat(n.getCpuId(), is(1));
        assertThat(n.getTotalJiffies(), is(12960623449L));
    }

}