@Test public void testMetricGetting() throws IOException, URISyntaxException { Response responseMock = PowerMockito.mock(Response.class); HttpEntity httpEntityMock = PowerMockito.mock(HttpEntity.class); InputStream is = Thread.currentThread().getContextClassLoader() .getResourceAsStream("metricvalue.json"); Map<String, String> map = new HashMap<>(); map.put("q", "metadata.applicationId:application_1549876136110_0018"); Map<String, Object> value = new HashMap<String, Object>(){{ put("total", 74); put("miss", 0); put("matched", 74); put("matchedFraction", 1); }}; MetricValue expectedMetric = new MetricValue("de_demo_results_comparision", 1549985089648L, Collections.singletonMap("applicationId", "application_1549876136110_0018"), value); given(restClientMock.performRequest(eq("GET"), eq(urlGet), eq(map), anyVararg())).willReturn(responseMock); given(responseMock.getEntity()).willReturn(httpEntityMock); given(httpEntityMock.getContent()).willReturn(is); MetricStoreImpl metricStore = new MetricStoreImpl("localhost", 0, "", "", ""); MetricValue metric = metricStore.getMetric("application_1549876136110_0018"); assertEquals(expectedMetric, metric); }
@Override public MetricValue getMetric(String applicationId) throws IOException { Response response = client.performRequest( "GET", urlGet, Collections.singletonMap( "q", "metadata.applicationId:" + applicationId)); List<MetricValue> metricValues = getMetricValuesFromResponse(response); return metricValues.get(0); }
MetricStoreImpl implements MetricStore { @Override public MetricValue getMetric(String applicationId) throws IOException { Response response = client.performRequest( "GET", urlGet, Collections.singletonMap( "q", "metadata.applicationId:" + applicationId)); List<MetricValue> metricValues = getMetricValuesFromResponse(response); return metricValues.get(0); } }
MetricStoreImpl implements MetricStore { @Override public MetricValue getMetric(String applicationId) throws IOException { Response response = client.performRequest( "GET", urlGet, Collections.singletonMap( "q", "metadata.applicationId:" + applicationId)); List<MetricValue> metricValues = getMetricValuesFromResponse(response); return metricValues.get(0); } MetricStoreImpl(@Value("${elasticsearch.host}") String host,
                           @Value("${elasticsearch.port}") int port,
                           @Value("${elasticsearch.scheme:http}") String scheme,
                           @Value("${elasticsearch.user:}") String user,
                           @Value("${elasticsearch.password:}") String password); }
MetricStoreImpl implements MetricStore { @Override public MetricValue getMetric(String applicationId) throws IOException { Response response = client.performRequest( "GET", urlGet, Collections.singletonMap( "q", "metadata.applicationId:" + applicationId)); List<MetricValue> metricValues = getMetricValuesFromResponse(response); return metricValues.get(0); } MetricStoreImpl(@Value("${elasticsearch.host}") String host,
                           @Value("${elasticsearch.port}") int port,
                           @Value("${elasticsearch.scheme:http}") String scheme,
                           @Value("${elasticsearch.user:}") String user,
                           @Value("${elasticsearch.password:}") String password); @Override List<MetricValue> getMetricValues(String metricName, int from,
                                             int size, long tmst); @Override ResponseEntity<?> addMetricValues(List<MetricValue> metricValues); @Override ResponseEntity<?> deleteMetricValues(String metricName); @Override MetricValue getMetric(String applicationId); }
MetricStoreImpl implements MetricStore { @Override public MetricValue getMetric(String applicationId) throws IOException { Response response = client.performRequest( "GET", urlGet, Collections.singletonMap( "q", "metadata.applicationId:" + applicationId)); List<MetricValue> metricValues = getMetricValuesFromResponse(response); return metricValues.get(0); } MetricStoreImpl(@Value("${elasticsearch.host}") String host,
                           @Value("${elasticsearch.port}") int port,
                           @Value("${elasticsearch.scheme:http}") String scheme,
                           @Value("${elasticsearch.user:}") String user,
                           @Value("${elasticsearch.password:}") String password); @Override List<MetricValue> getMetricValues(String metricName, int from,
                                             int size, long tmst); @Override ResponseEntity<?> addMetricValues(List<MetricValue> metricValues); @Override ResponseEntity<?> deleteMetricValues(String metricName); @Override MetricValue getMetric(String applicationId);  }