JoinTransform implements Transform { @Override public List<Metric> transform(QueryContext queryContext, List<Metric>... listOfList) { List<Metric> result = new ArrayList<>(); for (List<Metric> list : listOfList) { for (Metric metric : list) { result.add(metric); } } return result; }  @Override List<Metric> transform(QueryContext queryContext, List<Metric>... listOfList); @Override List<Metric> transform(QueryContext queryContext, List<Metric> metrics, List<String> constants); @Override String getResultScopeName(); @Override List<Metric> transform(QueryContext context, List<Metric> metrics);  }
@Test public void testJoinTransformWithEmptyMetricsLists() { Transform joinTransform = new JoinTransform(); List<Metric> metrics_1 = new ArrayList<Metric>(); List<Metric> metrics_2 = new ArrayList<Metric>(); List<Metric> result = joinTransform.transform(null, metrics_1, metrics_2); assertEquals(result.size(), 0); }
@Test(expected = UnsupportedOperationException.class) public void testJoinTransformWithConstant() { Transform joinTransform = new JoinTransform(); List<Metric> metrics = new ArrayList<Metric>(); List<String> constants = new ArrayList<String>(); joinTransform.transform(null, metrics, constants); }
@Test public void testJoinTransformWithMultipleMetrics() { Transform joinTransform = new JoinTransform(); Map<Long, Double> datapoints_1 = new HashMap<Long, Double>(); datapoints_1.put(1000L, 1.0); datapoints_1.put(2000L, 2.0); datapoints_1.put(3000L, 3.0); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); metric_1.setDatapoints(datapoints_1); Map<Long, Double> datapoints_2 = new HashMap<Long, Double>(); datapoints_2.put(4000L, 10.0); datapoints_2.put(5000L, 100.0); datapoints_2.put(6000L, 1000.0); Metric metric_2 = new Metric(TEST_SCOPE, TEST_METRIC); metric_2.setDatapoints(datapoints_2); Map<Long, Double> datapoints_3 = new HashMap<Long, Double>(); datapoints_3.put(7000L, 0.1); datapoints_3.put(8000L, 0.01); datapoints_3.put(9000L, 0.0001); Metric metric_3 = new Metric(TEST_SCOPE, TEST_METRIC); metric_3.setDatapoints(datapoints_3); final List<Metric> metrics_1 = new ArrayList<Metric>(); final List<Metric> metrics_2 = new ArrayList<Metric>(); final List<Metric> metrics_3 = new ArrayList<Metric>(); metrics_1.add(metric_1); metrics_2.add(metric_2); metrics_3.add(metric_3); Map<Long, Double> expected_1 = new HashMap<Long, Double>(); Map<Long, Double> expected_2 = new HashMap<Long, Double>(); Map<Long, Double> expected_3 = new HashMap<Long, Double>(); expected_1.put(1000L, 1.0); expected_1.put(2000L, 2.0); expected_1.put(3000L, 3.0); expected_2.put(4000L, 10.0); expected_2.put(5000L, 100.0); expected_2.put(6000L, 1000.0); expected_3.put(7000L, 0.1); expected_3.put(8000L, 0.01); expected_3.put(9000L, 0.0001); List<Metric> result = joinTransform.transform(null, metrics_1, metrics_2, metrics_3); assertEquals(result.size(), 3); assertEquals(expected_1, result.get(0).getDatapoints()); assertEquals(expected_2, result.get(1).getDatapoints()); assertEquals(expected_3, result.get(2).getDatapoints()); }
@Test public void testJoinTransformWithOneMetric() { Transform joinTransform = new JoinTransform(); Map<Long, Double> datapoints_1 = new HashMap<Long, Double>(); datapoints_1.put(1000L, 1.0); datapoints_1.put(2000L, 2.0); datapoints_1.put(3000L, 3.0); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); metric_1.setDatapoints(datapoints_1); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); Map<Long, Double> expected = new HashMap<Long, Double>(); expected.put(1000L, 1.0); expected.put(2000L, 2.0); expected.put(3000L, 3.0); List<Metric> result = joinTransform.transform(null, metrics); assertEquals(result.get(0).getDatapoints().size(), 3); assertEquals(expected, result.get(0).getDatapoints()); }