FillCalculateTransform implements Transform { @Override public List<Metric> transform(QueryContext context, List<Metric> metrics) { throw new UnsupportedOperationException("Fill Transform need a type!"); }  @Override List<Metric> transform(QueryContext context, List<Metric> metrics); @Override List<Metric> transform(QueryContext queryContext, List<Metric> metrics, List<String> constants); @Override String getResultScopeName(); @Override List<Metric> transform(QueryContext queryContext, List<Metric>... listOfList);  }
@Test public void testMetricListWithPercentile() { Transform fillCalculateTransform = new FillCalculateTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); metric_1.setDatapoints(input); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); List<String> constants = new ArrayList<>(); constants.add("p95"); Map<Long, Double> expected_1 = new HashMap<>(); expected_1.put(1000L, 10.0); expected_1.put(2000L, 10.0); expected_1.put(3000L, 10.0); expected_1.put(4000L, 10.0); expected_1.put(5000L, 10.0); expected_1.put(6000L, 10.0); expected_1.put(7000L, 10.0); expected_1.put(8000L, 10.0); expected_1.put(9000L, 10.0); expected_1.put(10000L, 10.0); List<Metric> result = fillCalculateTransform.transform(null, metrics, constants); assertEquals(result.size(), 1); assertEquals(result.get(0).getDatapoints().size(), 10); assertEquals(expected_1, result.get(0).getDatapoints()); }
@Test public void testMetricListIntervalOffsetWithPercentile() { Transform fillCalculateTransform = new FillCalculateTransform(); Map<Long, Double> input1 = new HashMap<>(); input1.put(1000L, 1.0); input1.put(4000L, 4.0); input1.put(5000L, 5.0); input1.put(6000L, 6.0); input1.put(7000L, 7.0); input1.put(8000L, 8.0); input1.put(9000L, 9.0); input1.put(10000L, 10.0); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); metric_1.setDatapoints(input1); List<Metric> metrics = new ArrayList<>(); metrics.add(metric_1); List<String> constants = new ArrayList<>(); constants.add("p80"); constants.add("1s"); constants.add("1s"); Map<Long, Double> expected_1 = new HashMap<>(); expected_1.put(1000L, 9.2); expected_1.put(3000L, 9.2); expected_1.put(4000L, 9.2); expected_1.put(5000L, 9.2); expected_1.put(6000L, 9.2); expected_1.put(7000L, 9.2); expected_1.put(8000L, 9.2); expected_1.put(9000L, 9.2); expected_1.put(10000L, 9.2); List<Metric> result = fillCalculateTransform.transform(null, metrics, constants); assertEquals(result.size(), 1); assertEquals(expected_1, result.get(0).getDatapoints()); }
@Test public void testMetricListWithMin() { Transform fillCalculateTransform = new FillCalculateTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); metric_1.setDatapoints(input); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); List<String> constants = new ArrayList<>(); constants.add("min"); Map<Long, Double> expected_1 = new HashMap<>(); expected_1.put(1000L, 1.0); expected_1.put(2000L, 1.0); expected_1.put(3000L, 1.0); expected_1.put(4000L, 1.0); expected_1.put(5000L, 1.0); expected_1.put(6000L, 1.0); expected_1.put(7000L, 1.0); expected_1.put(8000L, 1.0); expected_1.put(9000L, 1.0); expected_1.put(10000L, 1.0); List<Metric> result = fillCalculateTransform.transform(null, metrics, constants); assertEquals(result.size(), 1); assertEquals(result.get(0).getDatapoints().size(), 10); assertEquals(expected_1, result.get(0).getDatapoints()); }
@Test public void testMetricListWithMax() { Transform fillCalculateTransform = new FillCalculateTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); metric_1.setDatapoints(input); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); List<String> constants = new ArrayList<>(); constants.add("max"); Map<Long, Double> expected_1 = new HashMap<>(); expected_1.put(1000L, 10.0); expected_1.put(2000L, 10.0); expected_1.put(3000L, 10.0); expected_1.put(4000L, 10.0); expected_1.put(5000L, 10.0); expected_1.put(6000L, 10.0); expected_1.put(7000L, 10.0); expected_1.put(8000L, 10.0); expected_1.put(9000L, 10.0); expected_1.put(10000L, 10.0); List<Metric> result = fillCalculateTransform.transform(null, metrics, constants); assertEquals(result.size(), 1); assertEquals(result.get(0).getDatapoints().size(), 10); assertEquals(expected_1, result.get(0).getDatapoints()); }
@Test public void testMetricListWithAvg() { Transform fillCalculateTransform = new FillCalculateTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); metric_1.setDatapoints(input); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); List<String> constants = new ArrayList<>(); constants.add("avg"); Map<Long, Double> expected_1 = new HashMap<>(); expected_1.put(1000L, 5.5); expected_1.put(2000L, 5.5); expected_1.put(3000L, 5.5); expected_1.put(4000L, 5.5); expected_1.put(5000L, 5.5); expected_1.put(6000L, 5.5); expected_1.put(7000L, 5.5); expected_1.put(8000L, 5.5); expected_1.put(9000L, 5.5); expected_1.put(10000L, 5.5); List<Metric> result = fillCalculateTransform.transform(null, metrics, constants); assertEquals(result.size(), 1); assertEquals(result.get(0).getDatapoints().size(), 10); assertEquals(expected_1, result.get(0).getDatapoints()); }
@Test(expected = UnsupportedOperationException.class) public void testMetricListWithDev() { Transform fillCalculateTransform = new FillCalculateTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); metric_1.setDatapoints(input); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); List<String> constants = new ArrayList<>(); constants.add("dev"); fillCalculateTransform.transform(null, metrics, constants); }