GraphiteClient { public List<GraphiteResult> getData(long from, long until, int intervalLength, String target) { notNull(from, "from can't be null"); notNull(until, "until can't be null"); notNull(target, "target can't be null"); val maxDataPoints = calculateMaxDataPointsPerDay(from, until, intervalLength); val uri = String.format(baseUri + FETCH_METRICS_PATH, from, until, maxDataPoints, target); log.debug("Sending query to Graphite target: {}", uri); val headers = Collections.singletonMap("x-org-id", "1"); Content content; try { content = httpClient.get(uri, headers); } catch (IOException e) { val message = String.format("Encountered IOException while querying Metrictank target '%s': httpMethod=GET, uri=%s, message=%s", target, uri, e.getMessage()); throw new GraphiteClientException(message, e); } List<GraphiteResult> results; try { results = Arrays.asList(objectMapper.readValue(content.asBytes(), GraphiteResult[].class)); } catch (IOException e) { throw new GraphiteClientException(String.format("IOException while parsing response from Metrictank target: %s", target), e); } return results; }  List<GraphiteResult> getData(long from, long until, int intervalLength, String target); static final String FETCH_METRICS_PATH; }
@Test public void testGetMetricData() { assertEquals(1580901895, UNTIL_TIME_IN_SECONDS); clientUnderTest.getData(FROM_TIME_IN_SECONDS, UNTIL_TIME_IN_SECONDS, INTERVAL_LENGTH, "metricName"); }
@Test(expected = GraphiteClientException.class) public void testGetMetricData_cant_get() { clientUnderTest.getData(FROM_TIME_IN_SECONDS, UNTIL_TIME_IN_SECONDS, INTERVAL_LENGTH, "metricNameCantGet"); }
@Test(expected = GraphiteClientException.class) public void testGetMetricData_cant_read() { clientUnderTest.getData(FROM_TIME_IN_SECONDS, UNTIL_TIME_IN_SECONDS, INTERVAL_LENGTH, "metricNameCantRead"); }