LimitTransform implements Transform { @Override public List<Metric> transform(QueryContext context, List<Metric> metrics) { throw new UnsupportedOperationException("Limit transform requires a limit number!"); }  @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(expected = IllegalArgumentException.class) public void testLimitTransformWithoutMetrics() { Transform limitTransform = new LimitTransform(); List<Metric> metrics = null; List<String> constants = new ArrayList<String>(); constants.add("1"); limitTransform.transform(null, metrics, constants); }
@Test(expected = IllegalArgumentException.class) public void testLimitTransformWithoutConstant() { Transform limitTransform = new LimitTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); List<String> constants = new ArrayList<String>(); limitTransform.transform(null, metrics, constants); }
@Test(expected = IllegalArgumentException.class) public void testLimitTransformWithIllegalLimitNumber() { Transform limitTransform = new LimitTransform(); Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); List<String> constants = new ArrayList<String>(); constants.add("-1"); limitTransform.transform(null, metrics, constants); }
@Test public void testLimitTransformWithLimitLessThanMetricsLen() { Transform limitTransform = new LimitTransform(); 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); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); metrics.add(metric_2); metrics.add(metric_3); List<String> constants = new ArrayList<String>(); constants.add("2"); Map<Long, Double> expected_1 = new HashMap<Long, Double>(); expected_1.put(1000L, 1.0); expected_1.put(2000L, 2.0); expected_1.put(3000L, 3.0); Map<Long, Double> expected_2 = new HashMap<Long, Double>(); expected_2.put(4000L, 10.0); expected_2.put(5000L, 100.0); expected_2.put(6000L, 1000.0); List<Metric> result = limitTransform.transform(null, metrics, constants); assertEquals(result.size(), 2); assertEquals(expected_1, result.get(0).getDatapoints()); assertEquals(expected_2, result.get(1).getDatapoints()); }
@Test public void testLimitTransformWithLimitEqualToMetricsLen() { Transform limitTransform = new LimitTransform(); 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); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); metrics.add(metric_2); metrics.add(metric_3); List<String> constants = new ArrayList<String>(); constants.add("3"); Map<Long, Double> expected_1 = new HashMap<Long, Double>(); expected_1.put(1000L, 1.0); expected_1.put(2000L, 2.0); expected_1.put(3000L, 3.0); Map<Long, Double> expected_2 = new HashMap<Long, Double>(); expected_2.put(4000L, 10.0); expected_2.put(5000L, 100.0); expected_2.put(6000L, 1000.0); Map<Long, Double> expected_3 = new HashMap<Long, Double>(); expected_3.put(7000L, 0.1); expected_3.put(8000L, 0.01); expected_3.put(9000L, 0.0001); List<Metric> result = limitTransform.transform(null, metrics, constants); assertEquals(result.get(0).getDatapoints().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 testLimitTransformWithGreaterThanThanMetricsLen() { Transform limitTransform = new LimitTransform(); 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); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); metrics.add(metric_2); metrics.add(metric_3); List<String> constants = new ArrayList<String>(); constants.add("100"); Map<Long, Double> expected_1 = new HashMap<Long, Double>(); expected_1.put(1000L, 1.0); expected_1.put(2000L, 2.0); expected_1.put(3000L, 3.0); Map<Long, Double> expected_2 = new HashMap<Long, Double>(); expected_2.put(4000L, 10.0); expected_2.put(5000L, 100.0); expected_2.put(6000L, 1000.0); Map<Long, Double> expected_3 = new HashMap<Long, Double>(); expected_3.put(7000L, 0.1); expected_3.put(8000L, 0.01); expected_3.put(9000L, 0.0001); List<Metric> result = limitTransform.transform(null, metrics, constants); assertEquals(result.get(0).getDatapoints().size(), 3); assertEquals(expected_1, result.get(0).getDatapoints()); assertEquals(expected_2, result.get(1).getDatapoints()); assertEquals(expected_3, result.get(2).getDatapoints()); }