blob: 725501aacaac2652f9df95ac3b6cf1cce685d9b3 (
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
62
63
64
65
66
67
68
|
/*
* 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 ai.vespa.metricsproxy.metric.Metric;
import org.json.JSONException;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static ai.vespa.metricsproxy.TestUtil.getFileContents;
import static ai.vespa.metricsproxy.metric.model.DimensionId.toDimensionId;
import static ai.vespa.metricsproxy.service.RemoteMetricsFetcher.METRICS_PATH;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* @author Unknown
*/
public class ContainerServiceTest {
private MockHttpServer service;
private int csPort;
@BeforeClass
public static void init() {
HttpMetricFetcher.CONNECTION_TIMEOUT = 60000; // 60 secs in unit tests
}
@Before
public void setupHTTPServer() {
csPort = 18637; // see factory/doc/port-ranges.txt
try {
String response = getFileContents("metrics-container-state-multi-chain.json");
service = new MockHttpServer(csPort, response, METRICS_PATH);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void testMultipleQueryDimensions() throws JSONException {
int count = 0;
VespaService service = VespaService.create("service1", "id", csPort);
for (Metric m : service.getMetrics().getMetrics()) {
if (m.getName().equals("queries.rate")) {
count++;
System.out.println("Name: " + m.getName() + " value: " + m.getValue());
if (m.getDimensions().get(toDimensionId("chain")).equals("asvBlendingResult")) {
assertThat((Double)m.getValue(), is(26.4));
} else if (m.getDimensions().get(toDimensionId("chain")).equals("blendingResult")) {
assertThat((Double)m.getValue(), is(0.36666666666666664));
} else {
assertThat("Unknown unknown chain", false, is(true));
}
}
}
assertThat(count, is(2));
}
@After
public void shutdown() {
this.service.close();
}
}
|