summaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service
diff options
context:
space:
mode:
Diffstat (limited to 'metrics-proxy/src/test/java/ai/vespa/metricsproxy/service')
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ConfigSentinelClientTest.java104
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ConfigSentinelDummy.java61
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ContainerServiceTest.java67
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/DummyService.java36
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsFetcherTest.java90
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockConfigSentinelClient.java50
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java56
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/SystemPollerTest.java45
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServiceTest.java77
-rw-r--r--metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServicesTest.java42
10 files changed, 0 insertions, 628 deletions
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ConfigSentinelClientTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ConfigSentinelClientTest.java
deleted file mode 100644
index bd61b8443aa..00000000000
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ConfigSentinelClientTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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 org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-/**
- * @author Unknown
- */
-public class ConfigSentinelClientTest {
-
- @Test
- public void testConfigSentinelClient() {
- ConfigSentinelDummy configsentinel = new ConfigSentinelDummy();
- List<VespaService> services = new ArrayList<>();
- VespaService docproc = new VespaService("docprocservice", "docproc/cluster.x.indexing/0");
- VespaService searchnode4 = new VespaService("searchnode4", "search/cluster.x/g0/c1/r1");
- VespaService qrserver = new VespaService("qrserver", "container/qrserver.0");
-
- services.add(searchnode4);
- services.add(qrserver);
- services.add(docproc);
-
- MockConfigSentinelClient client = new MockConfigSentinelClient(configsentinel);
- client.updateServiceStatuses(services);
-
- assertThat(qrserver.getPid(), is(6520));
- assertThat(qrserver.getState(), is("RUNNING"));
- assertThat(qrserver.isAlive(), is(true));
- assertThat(searchnode4.getPid(), is(6534));
- assertThat(searchnode4.getState(), is("RUNNING"));
- assertThat(searchnode4.isAlive(), is(true));
-
- assertThat(docproc.getPid(), is(-1));
- assertThat(docproc.getState(), is("FINISHED"));
- assertThat(docproc.isAlive(), is(false));
-
-
- configsentinel.reConfigure();
-
- client.ping(docproc);
- assertThat(docproc.getPid(), is(100));
- assertThat(docproc.getState(), is("RUNNING"));
- assertThat(docproc.isAlive(), is(true));
-
- //qrserver has yet not been checked
- assertThat(qrserver.isAlive(), is(true));
-
- client.updateServiceStatuses(services);
-
- assertThat(docproc.getPid(), is(100));
- assertThat(docproc.getState(), is("RUNNING"));
- assertThat(docproc.isAlive(), is(true));
- //qrserver is no longer running on this node - so should be false
- assertThat(qrserver.isAlive(), is(false));
- }
-
- @Test
- public void testElastic() throws Exception {
- String response = "container state=RUNNING mode=AUTO pid=14338 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"get/container.0\"\n" +
- "container-clustercontroller state=RUNNING mode=AUTO pid=25020 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"admin/cluster-controllers/0\"\n" +
- "distributor state=RUNNING mode=AUTO pid=25024 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/distributor/0\"\n" +
- "docprocservice state=RUNNING mode=AUTO pid=11973 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"docproc/cluster.search.indexing/0\"\n" +
- "logd state=RUNNING mode=AUTO pid=25016 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"hosts/vespa19.dev.gq1.yahoo.com/logd\"\n" +
- "logserver state=RUNNING mode=AUTO pid=25018 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"admin/logserver\"\n" +
- "metricsproxy state=RUNNING mode=AUTO pid=13107 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"hosts/vespa19.dev.gq1.yahoo.com/metricsproxy\"\n" +
- "searchnode state=RUNNING mode=AUTO pid=25023 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/search/cluster.search/0\"\n" +
- "slobrok state=RUNNING mode=AUTO pid=25019 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"admin/slobrok.0\"\n" +
- "topleveldispatch state=RUNNING mode=AUTO pid=25026 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/search/cluster.search/tlds/tld.0\"\n" +
- "\n";
-
- ConfigSentinelDummy configsentinel = new ConfigSentinelDummy(response);
- List<VespaService> services = new ArrayList<>();
-
- VespaService container = VespaService.create("container", "get/container.0", -1);
-
- VespaService containerClusterController =
- VespaService.create("container-clustercontroller", "get/container.0", -1);
-
- VespaService notPresent = VespaService.create("dummy","fake", -1);
-
- services.add(container);
- services.add(containerClusterController);
- services.add(notPresent);
-
- MockConfigSentinelClient client = new MockConfigSentinelClient(configsentinel);
- client.updateServiceStatuses(services);
- assertThat(container.isAlive(),is(true));
- assertThat(container.getPid(),is(14338));
- assertThat(container.getState(),is("RUNNING"));
-
- assertThat(containerClusterController.isAlive(),is(true));
- assertThat(containerClusterController.getPid(),is(25020));
- assertThat(containerClusterController.getState(),is("RUNNING"));
- }
-}
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ConfigSentinelDummy.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ConfigSentinelDummy.java
deleted file mode 100644
index 108f5c18e1d..00000000000
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ConfigSentinelDummy.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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;
-
-/**
- * @author Eirik Nygaard
- */
-public class ConfigSentinelDummy {
- private String serviceList =
- "docprocservice state=FINISHED mode=MANUAL pid=6555 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"docproc/cluster.x.indexing/0\"\n"
- + "distributor state=RUNNING mode=AUTO pid=6548 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"storage/cluster.storage/distributor/0\"\n"
- + "fleetcontroller state=RUNNING mode=AUTO pid=6543 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"storage/cluster.storage/fleetcontroller/0\"\n"
- + "storagenode state=RUNNING mode=AUTO pid=6539 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"storage/cluster.storage/storage/0\"\n"
- + "searchnode4 state=RUNNING mode=AUTO pid=6534 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/g0/c1/r1\"\n"
- + "qrserver2 state=RUNNING mode=AUTO pid=6521 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"container/qrserver.1\"\n"
- + "logserver state=RUNNING mode=AUTO pid=6518 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"admin/logserver\"\n"
- + "logd state=RUNNING mode=AUTO pid=6517 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"hosts/dell-bl5s7.trondheim.corp.yahoo.com/logd\"\n"
- + "searchnode2 state=RUNNING mode=AUTO pid=6527 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/g0/c0/r1\"\n"
- + "topleveldispatch2 state=RUNNING mode=AUTO pid=6525 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/tlds/tld.1\"\n"
- + "topleveldispatch state=RUNNING mode=AUTO pid=6524 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/tlds/tld.0\"\n"
- + "clustercontroller2 state=RUNNING mode=AUTO pid=6523 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/rtx/1\"\n"
- + "clustercontroller state=RUNNING mode=AUTO pid=6522 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/rtx/0\"\n"
- + "slobrok state=RUNNING mode=AUTO pid=6519 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"admin/slobrok.0\"\n"
- + "searchnode3 state=RUNNING mode=AUTO pid=6529 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/g0/c1/r0\"\n"
- + "searchnode state=RUNNING mode=AUTO pid=6526 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/g0/c0/r0\"\n"
- + "qrserver state=RUNNING mode=AUTO pid=6520 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"container/qrserver.0\"\n"
- + "\n";
-
-
- public ConfigSentinelDummy() {
- }
-
- public ConfigSentinelDummy(String response) {
- serviceList = response;
- }
-
- public void reConfigure() {
- this.serviceList = "docprocservice state=RUNNING mode=AUTO pid=100 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"docproc/cluster.x.indexing/0\"\n"
- + "distributor state=RUNNING mode=AUTO pid=6548 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"storage/cluster.storage/distributor/0\"\n"
- + "fleetcontroller state=RUNNING mode=AUTO pid=6543 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"storage/cluster.storage/fleetcontroller/0\"\n"
- + "storagenode state=RUNNING mode=AUTO pid=6539 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"storage/cluster.storage/storage/0\"\n"
- + "searchnode4 state=RUNNING mode=AUTO pid=6534 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/g0/c1/r1\"\n"
- + "qrserver2 state=RUNNING mode=AUTO pid=6521 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"container/qrserver.1\"\n"
- + "logserver state=RUNNING mode=AUTO pid=6518 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"admin/logserver\"\n"
- + "logd state=RUNNING mode=AUTO pid=6517 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"hosts/dell-bl5s7.trondheim.corp.yahoo.com/logd\"\n"
- + "searchnode2 state=RUNNING mode=AUTO pid=6527 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/g0/c0/r1\"\n"
- + "topleveldispatch2 state=RUNNING mode=AUTO pid=6525 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/tlds/tld.1\"\n"
- + "topleveldispatch state=RUNNING mode=AUTO pid=6524 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/tlds/tld.0\"\n"
- + "clustercontroller2 state=RUNNING mode=AUTO pid=6523 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/rtx/1\"\n"
- + "clustercontroller state=RUNNING mode=AUTO pid=6522 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/rtx/0\"\n"
- + "slobrok state=RUNNING mode=AUTO pid=6519 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"admin/slobrok.0\"\n"
- + "searchnode3 state=RUNNING mode=AUTO pid=6529 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/g0/c1/r0\"\n"
- + "searchnode state=RUNNING mode=AUTO pid=6526 exitstatus=0 autostart=TRUE autorestart=TRUE id=\"search/cluster.x/g0/c0/r0\"\n"
- + "\n";
- }
-
- public String getServiceList() {
- return serviceList;
- }
-}
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ContainerServiceTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ContainerServiceTest.java
deleted file mode 100644
index 4174b18f3a7..00000000000
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/ContainerServiceTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.TestUtil;
-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.metric.model.DimensionId.toDimensionId;
-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 = TestUtil.getContents("metrics-container-state-multi-chain.json");
- service = new MockHttpServer(csPort, response, HttpMetricFetcher.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();
- }
-}
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/DummyService.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/DummyService.java
deleted file mode 100644
index 380a992aead..00000000000
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/DummyService.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 ai.vespa.metricsproxy.metric.Metrics;
-
-/**
- * @author Unknown
- */
-public class DummyService extends VespaService {
- static final String NAME = "dummy";
- public static final String METRIC_1 = "c.test";
- public static final String METRIC_2 = "val";
-
- private final int num;
-
- public DummyService(int num, String configid) {
- super(NAME, NAME + num, configid);
- this.num = num;
- }
-
- @Override
- public Metrics getMetrics() {
- Metrics m = new Metrics();
-
- long timestamp = System.currentTimeMillis() / 1000;
- m.add(new Metric(METRIC_1, 5 * num + 1, timestamp));
- m.add(new Metric(METRIC_2, 1.3 * num + 1.05, timestamp));
-
- return m;
- }
-
-}
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsFetcherTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsFetcherTest.java
deleted file mode 100644
index 27e1bb97943..00000000000
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MetricsFetcherTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.TestUtil;
-import ai.vespa.metricsproxy.metric.Metrics;
-import org.junit.Test;
-
-import java.io.File;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-/**
- * @author Unknowm
- */
-public class MetricsFetcherTest {
- private static int port = 9; //port number is not used in this test
-
- @Test
- public void testStateFormatMetricsParse() {
- String jsonData = TestUtil.getContents("metrics-state.json");
- RemoteMetricsFetcher fetcher = new RemoteMetricsFetcher(new DummyService(0, "dummy/id/0"), port);
- Metrics metrics = fetcher.createMetrics(jsonData, 0);
- assertThat("Wrong number of metrics", metrics.size(), is(10));
- assertThat("Wrong value for metric", metrics.get("query_hits.count").intValue(), is(28));
- assertThat("Wrong value for metric ", metrics.get("queries.rate").doubleValue(), is(0.4667));
- assertThat("Wrong timestamp", metrics.getTimeStamp(), is(1334134700L));
- }
-
- @Test
- public void testEmptyJson() {
- String jsonData = "{}";
- RemoteMetricsFetcher fetcher = new RemoteMetricsFetcher(new DummyService(0, "dummy/id/0"), port);
- Metrics metrics = fetcher.createMetrics(jsonData, 0);
- assertThat("Wrong number of metrics", metrics.size(), is(0));
- }
-
- @Test
- public void testErrors() {
- String jsonData;
- Metrics metrics;
-
- RemoteMetricsFetcher fetcher = new RemoteMetricsFetcher(new DummyService(0, "dummy/id/0"), port);
-
- jsonData = "";
- metrics = fetcher.createMetrics(jsonData, 0);
- assertThat("Wrong number of metrics", metrics.size(), is(0));
-
- jsonData = "{\n" +
- "\"status\" : {\n" +
- " \"code\" : \"up\",\n" +
- " \"message\" : \"Everything ok here\"\n" +
- "}\n" +
- "}";
- metrics = fetcher.createMetrics(jsonData, 0);
- assertThat("Wrong number of metrics", metrics.size(), is(0));
-
- jsonData = "{\n" +
- "\"status\" : {\n" +
- " \"code\" : \"up\",\n" +
- " \"message\" : \"Everything ok here\"\n" +
- "},\n" +
- "\"metrics\" : {\n" +
- " \"snapshot\" : {\n" +
- " \"from\" : 1334134640.089,\n" +
- " \"to\" : 1334134700.088\n" +
- " },\n" +
- " \"values\" : [\n" +
- " {\n" +
- " \"name\" : \"queries\",\n" +
- " \"description\" : \"Number of queries executed during snapshot interval\",\n" +
- " \"values\" : {\n" +
- " \"count\" : null,\n" +
- " \"rate\" : 0.4667\n" +
- " },\n" +
- " \"dimensions\" : {\n" +
- " \"searcherid\" : \"x\"\n" +
- " }\n" +
- " }\n" + "" +
- " ]\n" +
- "}\n" +
- "}";
-
- metrics = fetcher.createMetrics(jsonData, 0);
- assertThat("Wrong number of metrics", metrics.size(), is(0));
- }
-}
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockConfigSentinelClient.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockConfigSentinelClient.java
deleted file mode 100644
index 917c529e63e..00000000000
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockConfigSentinelClient.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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 com.yahoo.log.LogLevel;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Logger;
-
-/**
- * Mock config sentinel
- *
- * @author hmusum
- */
-public class MockConfigSentinelClient extends ConfigSentinelClient {
- private final ConfigSentinelDummy configSentinel;
- private final static Logger log = Logger.getLogger(MockConfigSentinelClient.class.getPackage().getName());
-
- public MockConfigSentinelClient(ConfigSentinelDummy configSentinel) {
- super();
- this.configSentinel = configSentinel;
- }
-
- @Override
- protected synchronized void setStatus(List<VespaService> services) throws Exception {
- List<VespaService> updatedServices = new ArrayList<>();
- String[] lines = configSentinel.getServiceList().split("\n");
- for (String line : lines) {
- if (line.equals("")) {
- break;
- }
-
- VespaService s = parseServiceString(line, services);
- if (s != null) {
- updatedServices.add(s);
- }
- }
-
- //Check if there are services that were not found in
- //from the sentinel
- for (VespaService s : services) {
- if (!updatedServices.contains(s)) {
- log.log(LogLevel.DEBUG, "Service " + s + " is no longer found with sentinel - setting alive = false");
- s.setAlive(false);
- }
- }
- }
-}
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java
deleted file mode 100644
index fdf2fae3081..00000000000
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/MockHttpServer.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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 com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
-import com.sun.net.httpserver.HttpServer;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.InetSocketAddress;
-
-/**
- * @author jobergum
- */
-public class MockHttpServer {
-
- private String response;
- private HttpServer server;
-
- /**
- * Mock http server that will return response as body
- *
- * @param port the port to listen to
- * @param response the response to return along with 200 OK
- * @param path the file path that the server will accept requests for. E.g /state/v1/metrics
- */
- public MockHttpServer(int port, String response, String path) throws IOException {
- this.response = response;
- this.server = HttpServer.create(new InetSocketAddress(port), 10);
- this.server.createContext(path, new MyHandler());
- this.server.setExecutor(null); // creates a default executor
- this.server.start();
- System.out.println("Started web server on port " + port);
- }
-
- public synchronized void setResponse(String r) {
- this.response = r;
- }
-
- public void close() {
- this.server.stop(0);
- }
-
- private class MyHandler implements HttpHandler {
- public void handle(HttpExchange t) throws IOException {
- t.sendResponseHeaders(200, response.length());
- OutputStream os = t.getResponseBody();
- os.write(response.getBytes());
- os.close();
- }
- }
-
-}
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/SystemPollerTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/SystemPollerTest.java
deleted file mode 100644
index a42d52b7ea6..00000000000
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/SystemPollerTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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 org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-/**
- * @author Unknown
- */
-public class SystemPollerTest {
-
- @Test
- public void testSystemPoller() {
- DummyService s = new DummyService(0, "id");
- List<VespaService> services = new ArrayList<>();
- services.add(s);
-
- SystemPoller poller = new SystemPoller(services, 60*5);
- assertThat(s.isAlive(), is(false));
- services.remove(0);
- poller.setServices(services);
- long n = poller.getPidJiffies(s);
- assertThat(n, is(0L));
- long[] memusage = poller.getMemoryUsage(s);
- assertThat(memusage[0], is(0L));
- assertThat(memusage[1], is(0L));
- }
-
- @Test
- public void testCPUJiffies() {
- String line = "cpu1 102180864 789 56766899 12800020140 1654757 0 0";
- CpuJiffies n = new CpuJiffies(line);
- assertThat(n.getCpuId(), is(1));
- assertThat(n.getTotalJiffies(), is(12960623449L));
- }
-
-}
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServiceTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServiceTest.java
deleted file mode 100644
index 13be98db23a..00000000000
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServiceTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.TestUtil;
-import ai.vespa.metricsproxy.metric.Metrics;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.File;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-/**
- * @author Unknown
- */
-public class VespaServiceTest {
- private MockHttpServer service;
- private int csPort;
- private static final String response;
-
- static {
- response = TestUtil.getContents("metrics-state.json");
- HttpMetricFetcher.CONNECTION_TIMEOUT = 60000; // 60 secs in unit tests
- }
-
- @Before
- public void setupHTTPServer() {
- csPort = 18632; // see factory/doc/port-ranges.txt
- try {
- service = new MockHttpServer(csPort, response, HttpMetricFetcher.METRICS_PATH);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testService() {
- VespaService service = new VespaService("qrserver", "container/qrserver.0");
- assertThat(service.getServiceName(), is("qrserver"));
- assertThat(service.getInstanceName(), is("qrserver"));
- assertThat(service.getPid(), is(-1));
- assertThat(service.getConfigId(), is("container/qrserver.0"));
-
-
- service = VespaService.create("qrserver2", "container/qrserver.0", -1);
- assertThat(service.getServiceName(), is("qrserver"));
- assertThat(service.getInstanceName(), is("qrserver2"));
- assertThat(service.getPid(), is(-1));
- assertThat(service.getConfigId(), is("container/qrserver.0"));
- }
-
- @Test
- // TODO: Make it possible to test this without running a HTTP server to create the response
- public void testMetricsFetching() {
- VespaService service = VespaService.create("service1", "id", csPort);
- Metrics metrics = service.getMetrics();
- assertThat(metrics.getMetric("queries.count").getValue().intValue(), is(28));
-
- // Shutdown server and check that no metrics are returned (should use empty metrics
- // when unable to fetch new metrics)
- shutdown();
-
- metrics = service.getMetrics();
- assertThat(metrics.size(), is(0));
- }
-
- @After
- public void shutdown() {
- this.service.close();
- }
-
-}
diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServicesTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServicesTest.java
deleted file mode 100644
index bd0b670ca35..00000000000
--- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServicesTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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 com.google.common.collect.ImmutableList;
-import org.junit.Test;
-
-import java.util.List;
-
-import static ai.vespa.metricsproxy.service.VespaServices.ALL_SERVICES;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-/**
- * TODO: add more tests
- *
- * @author gjoranv
- */
-public class VespaServicesTest {
-
- @Test
- public void services_can_be_retrieved_from_monitoring_name() {
- List<VespaService> dummyServices = ImmutableList.of(
- new DummyService(0, "dummy/id/0"),
- new DummyService(1, "dummy/id/1"));
- VespaServices services = new VespaServices(dummyServices);
-
- assertThat(services.getMonitoringServices("vespa.dummy").size(), is(2));
- }
-
- @Test
- public void all_services_can_be_retrieved_by_using_special_name() {
- List<VespaService> dummyServices = ImmutableList.of(
- new DummyService(0, "dummy/id/0"));
- VespaServices services = new VespaServices(dummyServices);
-
- assertThat(services.getMonitoringServices(ALL_SERVICES).size(), is(1));
- }
-
-}