aboutsummaryrefslogtreecommitdiffstats
path: root/metrics/src/test/java/ai/vespa/metrics/MetricTest.java
blob: 7a0b85f82cc30c11b9e685dea5e094acca0030a0 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metrics;

import ai.vespa.metrics.set.Metric;
import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.Test;

import java.util.Map;

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

/**
 * @author gjoranv
 */
public class MetricTest {

    @Test
    void this_metric_takes_precedence_when_combined_with_another_metric() {
        String COMMON_DIMENSION_KEY = "commonKey";

        Map<String, String> thisDimensions = ImmutableMap.<String, String>builder()
                .put(COMMON_DIMENSION_KEY, "thisCommonVal")
                .put("thisKey", "thisVal")
                .build();
        Metric thisMetric = new Metric("thisMetric", "this-output-name", "this-description", thisDimensions);

        Map<String, String> thatDimensions = ImmutableMap.<String, String>builder()
                .put(COMMON_DIMENSION_KEY, "thatCommonVal")
                .put("thatKey", "thatVal")
                .build();
        Metric thatMetric = new Metric("thatMetric", "that-output-name", "that-description", thatDimensions);

        Metric combinedMetric = thisMetric.addDimensionsFrom(thatMetric);
        assertEquals("this-output-name", combinedMetric.outputName);
        assertEquals("this-description", combinedMetric.description);
        assertEquals(3, combinedMetric.dimensions.size());
        assertEquals("thisCommonVal", combinedMetric.dimensions.get(COMMON_DIMENSION_KEY));
    }
}