PropagateTransform implements Transform { @Override public List<Metric> transform(QueryContext context, List<Metric> metrics) { throw new UnsupportedOperationException("Propagate Transform needs a max window size"); }  @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 testPercentileTransformWithoutConstants() { Transform propagateTransform = new PropagateTransform(); Metric metric = new Metric(TEST_SCOPE, TEST_METRIC); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric); List<String> constants = new ArrayList<String>(); propagateTransform.transform(null, metrics, constants); }
@Test(expected = IllegalArgumentException.class) public void testPercentileTransformWithoutMetrics() { Transform propagateTransform = new PropagateTransform(); List<Metric> metrics = null; List<String> constants = new ArrayList<String>(); constants.add("9s"); propagateTransform.transform(null, metrics, constants); }
@Test(expected = SystemException.class) public void testWithIllegalTimeunit() { Transform propagateTransform = new PropagateTransform(); Map<Long, Double> datapoints = new HashMap<Long, Double>(); datapoints.put(1000L, 1.0); datapoints.put(2000L, 2.0); datapoints.put(3000L, 3.0); Metric metric = new Metric(TEST_SCOPE, TEST_METRIC); metric.setDatapoints(datapoints); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric); List<String> constants = new ArrayList<String>(1); constants.add("5w"); propagateTransform.transform(null, metrics, constants); }
@Test public void testWithWindowLessThanPropagateRange() { Transform propagateTransform = new PropagateTransform(); Map<Long, Double> datapoints = new HashMap<Long, Double>(); datapoints.put(1000L, 1.0); datapoints.put(4000L, 4.0); datapoints.put(5000L, 5.0); datapoints.put(6000L, 6.0); Metric metric = new Metric(TEST_SCOPE, TEST_METRIC); metric.setDatapoints(datapoints); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric); List<String> constants = new ArrayList<String>(); constants.add("1s"); Map<Long, Double> expected = new HashMap<Long, Double>(); expected.put(1000L, 1.0); expected.put(2000L, 1.0); expected.put(3000L, 1.0); expected.put(4000L, 4.0); expected.put(5000L, 5.0); expected.put(6000L, 6.0); List<Metric> result = propagateTransform.transform(null, metrics, constants); assertEquals(result.get(0).getDatapoints().size(), 6); assertEquals(expected, result.get(0).getDatapoints()); }
@Test public void testPropagateWithFillingDatapointsAtEnd() { Transform propagateTransform = new PropagateTransform(); Map<Long, Double> datapoints = new HashMap<Long, Double>(); datapoints.put(2000L, 1.0); datapoints.put(4000L, 4.0); Metric metric = new Metric(TEST_SCOPE, TEST_METRIC); metric.setDatapoints(datapoints); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric); List<String> constants = new ArrayList<String>(); constants.add("1s"); Map<Long, Double> expected = new HashMap<Long, Double>(); expected.put(2000L, 1.0); expected.put(3000L, 1.0); expected.put(4000L, 4.0); expected.put(5000L, 4.0); expected.put(6000L, 4.0); expected.put(7000L, 4.0); expected.put(8000L, 4.0); QueryContext context = QueryUtils.getQueryContext("1000:8000:argus.core:alerts.evaluated:zimsum:1m-sum", 0L); List<Metric> result = propagateTransform.transform(context, metrics, constants); assertEquals(result.get(0).getDatapoints().size(), 7); assertEquals(expected, result.get(0).getDatapoints()); }
@Test public void testWithWindowEqualsToPropagateRange() { Transform propagateTransform = new PropagateTransform(); Map<Long, Double> datapoints = new HashMap<Long, Double>(); datapoints.put(1000L, 1.0); datapoints.put(4000L, 4.0); datapoints.put(5000L, 5.0); datapoints.put(6000L, 6.0); Metric metric = new Metric(TEST_SCOPE, TEST_METRIC); metric.setDatapoints(datapoints); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric); List<String> constants = new ArrayList<String>(); constants.add("3s"); Map<Long, Double> expected = new HashMap<Long, Double>(); expected.put(1000L, 1.0); expected.put(4000L, 4.0); expected.put(5000L, 5.0); expected.put(6000L, 6.0); List<Metric> result = propagateTransform.transform(null, metrics, constants); assertEquals(result.get(0).getDatapoints().size(), 4); assertEquals(expected, result.get(0).getDatapoints()); }
@Test public void testWithWindowGreaterThanPropagateRange() { Transform propagateTransform = new PropagateTransform(); Map<Long, Double> datapoints = new HashMap<Long, Double>(); datapoints.put(1000L, 1.0); datapoints.put(4000L, 4.0); datapoints.put(5000L, 5.0); datapoints.put(6000L, 6.0); Metric metric = new Metric(TEST_SCOPE, TEST_METRIC); metric.setDatapoints(datapoints); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric); List<String> constants = new ArrayList<String>(); constants.add("4s"); Map<Long, Double> expected = new HashMap<Long, Double>(); expected.put(1000L, 1.0); expected.put(4000L, 4.0); expected.put(5000L, 5.0); expected.put(6000L, 6.0); List<Metric> result = propagateTransform.transform(null, metrics, constants); assertEquals(result.get(0).getDatapoints().size(), 4); assertEquals(expected, result.get(0).getDatapoints()); }
@Test public void testWithMultipePropagateRange() { Transform propagateTransform = new PropagateTransform(); Map<Long, Double> datapoints = new HashMap<Long, Double>(); datapoints.put(1000L, 1.0); datapoints.put(3000L, 3.0); datapoints.put(6000L, 6.0); Metric metric = new Metric(TEST_SCOPE, TEST_METRIC); metric.setDatapoints(datapoints); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric); List<String> constants = new ArrayList<String>(); constants.add("1s"); Map<Long, Double> expected = new HashMap<Long, Double>(); expected.put(1000L, 1.0); expected.put(2000L, 1.0); expected.put(3000L, 3.0); expected.put(4000L, 3.0); expected.put(5000L, 3.0); expected.put(6000L, 6.0); List<Metric> result = propagateTransform.transform(null, metrics, constants); assertEquals(result.get(0).getDatapoints().size(), 6); assertEquals(expected, result.get(0).getDatapoints()); }
@Test public void testMetricListWithMultipePropagateRange() { Transform propagateTransform = new PropagateTransform(); Map<Long, Double> datapoints_1 = new HashMap<Long, Double>(); datapoints_1.put(1000L, 1.0); datapoints_1.put(3000L, 3.0); datapoints_1.put(6000L, 6.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(1000L, 21.0); datapoints_2.put(3000L, 23.0); datapoints_2.put(6000L, 26.0); Metric metric_2 = new Metric(TEST_SCOPE, TEST_METRIC); metric_2.setDatapoints(datapoints_2); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric_1); metrics.add(metric_2); List<String> constants = new ArrayList<String>(); constants.add("1s"); Map<Long, Double> expected_1 = new HashMap<Long, Double>(); expected_1.put(1000L, 1.0); expected_1.put(2000L, 1.0); expected_1.put(3000L, 3.0); expected_1.put(4000L, 3.0); expected_1.put(5000L, 3.0); expected_1.put(6000L, 6.0); Map<Long, Double> expected_2 = new HashMap<Long, Double>(); expected_2.put(1000L, 21.0); expected_2.put(2000L, 21.0); expected_2.put(3000L, 23.0); expected_2.put(4000L, 23.0); expected_2.put(5000L, 23.0); expected_2.put(6000L, 26.0); List<Metric> result = propagateTransform.transform(null, metrics, constants); assertEquals(result.size(), 2); assertEquals(result.get(1).getDatapoints().size(), 6); assertEquals(expected_1, result.get(0).getDatapoints()); assertEquals(expected_2, result.get(1).getDatapoints()); }
@Test public void testWithOnlyOneDP() { Transform propagateTransform = new PropagateTransform(); Map<Long, Double> datapoints = new HashMap<Long, Double>(); datapoints.put(200000L, 1.0); Metric metric = new Metric(TEST_SCOPE, TEST_METRIC); metric.setDatapoints(datapoints); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric); List<String> constants = new ArrayList<String>(); constants.add("100s"); Map<Long, Double> expected = new HashMap<Long, Double>(); expected.put(200000L, 1.0); expected.put(300000L, 1.0); expected.put(400000L, 1.0); expected.put(500000L, 1.0); expected.put(600000L, 1.0); QueryContext queryContext = new QueryContext(); TSDBQueryExpression expression = new TSDBQueryExpression(); expression.setStartTimestamp(200000L); expression.setEndTimestamp(600000L); queryContext.setExpression(expression); List<Metric> result = propagateTransform.transform(queryContext, metrics, constants); assertEquals(result.get(0).getDatapoints().size(), 5); assertEquals(expected, result.get(0).getDatapoints()); }
@Test public void testNoMetricWithMissingPointAndOtherTimeUnit() { Transform propagateTransform = new PropagateTransform(); Map<Long, Double> datapoints = new HashMap<Long, Double>(); datapoints.put(1000L, 1.0); datapoints.put(2000L, 2.0); datapoints.put(3000L, 3.0); Metric metric = new Metric(TEST_SCOPE, TEST_METRIC); metric.setDatapoints(datapoints); List<Metric> metrics = new ArrayList<Metric>(); metrics.add(metric); List<String> constants = new ArrayList<String>(); constants.add("5m"); 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 = propagateTransform.transform(null, metrics, constants); assertEquals(result.get(0).getDatapoints().size(), 3); assertEquals(expected, result.get(0).getDatapoints()); }
@Test public void testEmptyDatapointSet() { Transform propagateTransform = new PropagateTransform(); Metric metric = new Metric(TEST_SCOPE, TEST_METRIC); metric.setDatapoints(Collections.<Long, Double> emptyMap()); List<Metric> metrics = Arrays.asList(metric); List<String> constants = Arrays.asList("1m"); List<Metric> result = propagateTransform.transform(null, metrics, constants); assertEquals(metrics, result); }