|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +package org.elasticsearch.telemetry; |
| 11 | + |
| 12 | +import org.elasticsearch.test.ESTestCase; |
| 13 | + |
| 14 | +import java.util.Collections; |
| 15 | +import java.util.List; |
| 16 | +import java.util.Map; |
| 17 | + |
| 18 | +import static org.hamcrest.Matchers.containsInAnyOrder; |
| 19 | + |
| 20 | +public class MeasurementTests extends ESTestCase { |
| 21 | + |
| 22 | + public void testCombineLongs() { |
| 23 | + Measurement m1 = new Measurement(1L, Collections.emptyMap(), false); |
| 24 | + Measurement m2 = new Measurement(2L, Collections.emptyMap(), false); |
| 25 | + Measurement m3 = new Measurement(3L, Map.of("k", "v"), false); |
| 26 | + Measurement m4 = new Measurement(4L, Map.of("k", "v"), false); |
| 27 | + |
| 28 | + List<Measurement> combined = Measurement.combine(List.of(m1, m2, m3, m4)); |
| 29 | + assertThat( |
| 30 | + combined, |
| 31 | + containsInAnyOrder(new Measurement(3L, Collections.emptyMap(), false), new Measurement(7L, Map.of("k", "v"), false)) |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + public void testCombineDoubles() { |
| 36 | + Measurement m1 = new Measurement(1.0, Collections.emptyMap(), true); |
| 37 | + Measurement m2 = new Measurement(2.0, Collections.emptyMap(), true); |
| 38 | + Measurement m3 = new Measurement(3.0, Map.of("k", "v"), true); |
| 39 | + Measurement m4 = new Measurement(4.0, Map.of("k", "v"), true); |
| 40 | + |
| 41 | + List<Measurement> combined = Measurement.combine(List.of(m1, m2, m3, m4)); |
| 42 | + assertThat( |
| 43 | + combined, |
| 44 | + containsInAnyOrder(new Measurement(3.0, Collections.emptyMap(), true), new Measurement(7.0, Map.of("k", "v"), true)) |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | +} |
0 commit comments