ApplicationMasterRestClient implements Closeable { public Map<String, Map<String, Object>> getMetrics() throws IOException { String jsonString = getEntityAsJson("/metrics", "metrics"); return jsonMapper.readValue(jsonString, new TypeReference<Map<String, Map<String, Object>>>() { }); } ApplicationMasterRestClient(CloseableHttpClient client, String amHostName, int amRpcPort); Map<String, Map<String, Object>> getMetrics(); Map<String, Object> getTaskContext(); Map<String, Object> getAmState(); Map<String, Object> getConfig(); @Override void close(); @Override String toString();  }
@Test public void testGetMetricsSuccess() throws IOException { SamzaApplicationState samzaAppState = createSamzaApplicationState(); MetricsRegistryMap registry = new MetricsRegistryMap(); assignMetricValues(samzaAppState, registry); String response = ApplicationMasterRestServlet.getMetrics(jsonMapper, registry); setupMockClientResponse(HttpStatus.SC_OK, "Success", response); ApplicationMasterRestClient client = new ApplicationMasterRestClient(mockClient, AM_HOST_NAME, AM_RPC_PORT); Map<String, Map<String, Object>> metricsResult = client.getMetrics(); String group = SamzaAppMasterMetrics.class.getCanonicalName(); assertEquals(1, metricsResult.size()); assertTrue(metricsResult.containsKey(group)); Map<String, Object> amMetricsGroup = metricsResult.get(group); assertEquals(7, amMetricsGroup.size()); assertEquals(samzaAppState.runningProcessors.size(), amMetricsGroup.get("running-containers")); assertEquals(samzaAppState.neededProcessors.get(), amMetricsGroup.get("needed-containers")); assertEquals(samzaAppState.completedProcessors.get(), amMetricsGroup.get("completed-containers")); assertEquals(samzaAppState.failedContainers.get(), amMetricsGroup.get("failed-containers")); assertEquals(samzaAppState.releasedContainers.get(), amMetricsGroup.get("released-containers")); assertEquals(samzaAppState.processorCount.get(), amMetricsGroup.get("container-count")); assertEquals(samzaAppState.jobHealthy.get() ? 1 : 0, amMetricsGroup.get("job-healthy")); }
@Test public void testGetMetricsError() throws IOException { setupErrorTest("metrics"); ApplicationMasterRestClient client = new ApplicationMasterRestClient(mockClient, AM_HOST_NAME, AM_RPC_PORT); client.getMetrics(); }