aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-apps/src/test/java/com/yahoo/vespa/clustercontroller/apputil/communication/http/JDiscMetricWrapperTest.java
blob: a20b4b744f2335995c85a97308c1d01a3c55d6d8 (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
46
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.apputil.communication.http;

import com.yahoo.jdisc.Metric;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class JDiscMetricWrapperTest {

    static class MetricImpl implements Metric {
        int calls = 0;
        @Override
        public void set(String s, Number number, Context context) { ++calls; }
        @Override
        public void add(String s, Number number, Context context) { ++calls; }
        @Override
        public Context createContext(Map<String, ?> stringMap) {
            ++calls;
            return new Context() {};
        }
    }

    @Test
    void testSimple() {
        MetricImpl impl1 = new MetricImpl();
        MetricImpl impl2 = new MetricImpl();
        JDiscMetricWrapper wrapper = new JDiscMetricWrapper(impl1);
        wrapper.add("foo", 234, null);
        wrapper.set("bar", 234, null);
        assertNotNull(wrapper.createContext(null));
        assertEquals(3, impl1.calls);
        impl1.calls = 0;
        wrapper.updateMetricImplementation(impl2);
        wrapper.add("foo", 234, wrapper.createContext(null));
        wrapper.set("bar", 234, wrapper.createContext(null));
        assertNotNull(wrapper.createContext(null));
        assertEquals(0, impl1.calls);
        assertEquals(5, impl2.calls);

    }

}