@SuppressWarnings("unchecked")
@Test
public void testWhenMetricsExistInCacheShouldReturnMetricsFromBothCacheNTSDB() throws Exception {

	long currTime = System.currentTimeMillis();
	long startTime = currTime-4*24*60*60*1000, endTime = currTime;
	MetricQuery query = new MetricQuery("scope", "metric", new HashMap<>(),
			startTime, endTime);
	Metric lastHourMetric= new Metric("scope", "metric");
	Map<Long, Double> lastHourDps = new HashMap<>();
	lastHourDps.put(endTime, 2d);
	lastHourMetric.setDatapoints(lastHourDps);
	Map<MetricQuery, List<Metric>> lastHourMetrics = mock(Map.class);
	when(lastHourMetrics.get(any())).thenReturn(Arrays.asList(lastHourMetric));
	when(tsdbService.getMetrics(any())).thenReturn(lastHourMetrics);
	StringBuilder cacheKey = new StringBuilder();
	cacheKey.append(startTime);
	cacheKey.append(":null:scope:metric:{}:AVG:AVG:300000");
	String cacheKeyValue = "{\"metatagsRecord\":null,\"datapoints\":{\""+ startTime+ "\":1},"
			+ "\"metric\":\"metric\",\"units\":null,\"namespace\":null,\"query\":{\"aggregator\":\"AVG\",\"downsampler\":\"AVG\","
			+ "\"downsamplingPeriod\":300000,\"metric\":\"metric\",\"startTimestamp\":1544659200000,\"endTimestamp\":1544816134802,"
			+ "\"scope\":\"scope\",\"tags\":{}},\"displayName\":null,\"scope\":\"scope\",\"uid\":null,\"tags\":{}}";
	Map<String, Object> metricsFromCache = new HashMap<>();
	metricsFromCache.put(cacheKey.toString(), Arrays.asList(cacheKeyValue));
	when(cacheService.getRange(anySet(), anyInt(), anyInt())).thenReturn(metricsFromCache);
	Map<MetricQuery, List<Metric>> actual = cachedTSDBService.getMetrics(Arrays.asList(query));
	Metric expectedMetric= new Metric("scope", "metric");
	Map<Long, Double> dps = new HashMap<>();
	dps.put(startTime, 1d);
	dps.put(endTime, 2d);
	expectedMetric.setDatapoints(dps);
	List<Metric> expected = new ArrayList<>();
	expected.add(expectedMetric);
	assertEquals(expected, actual.get(query));
}