blob: d99dc4c40ffb7b3d7923356b2d70d87d706bfcbc (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.metrics.simple;
import static org.junit.Assert.*;
import java.util.Collection;
import java.util.Map.Entry;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.yahoo.metrics.ManagerConfig;
import com.yahoo.metrics.simple.jdisc.JdiscMetricsFactory;
import com.yahoo.metrics.simple.jdisc.SimpleMetricConsumer;
/**
* Functional test for simple metric implementation.
*
* @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
*/
public class MetricsTest extends UnitTestSetup {
SimpleMetricConsumer metricApi;
@Before
public void setUp() throws Exception {
super.init();
metricApi = (SimpleMetricConsumer) new JdiscMetricsFactory(metricManager.get()).newInstance();
}
@After
public void tearDown() throws Exception {
super.fini();
}
@Test
public final void smokeTest() throws InterruptedException {
final String metricName = "testMetric";
metricApi.set(metricName, Double.valueOf(1.0d), null);
updater.gotData.await(10, TimeUnit.SECONDS);
Bucket s = getUpdatedSnapshot();
Collection<Entry<Point, UntypedMetric>> values = s.getValuesForMetric(metricName);
assertEquals(1, values.size());
Entry<Point, UntypedMetric> value = values.iterator().next();
assertEquals(Point.emptyPoint(), value.getKey());
assertEquals(1.0d, value.getValue().getLast(), 0.0d); // using number exactly expressible as doubles
assertEquals(1L, value.getValue().getCount());
}
@Test
public final void testRedefinition() {
MetricReceiver r = metricManager.get();
final String metricName = "gah";
r.addMetricDefinition(metricName, new MetricSettings.Builder().build());
r.addMetricDefinition(metricName, new MetricSettings.Builder().histogram(true).build());
assertTrue(r.getMetricDefinition(metricName).isHistogram());
}
}
|