Пример #1
0
  @Test
  public void movingWithOnlyOnePoint() {
    Transform movingTransform = new MetricMappingTransform(new MovingValueMapping());
    Map<Long, String> datapoints = new HashMap<Long, String>();

    datapoints.put(0L, "3.0");

    Map<Long, String> actual = new HashMap<Long, String>();

    actual.put(0L, "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("120s");
    constants.add("avg");

    List<Metric> result = movingTransform.transform(metrics, constants);

    assertEquals(result.get(0).getDatapoints().size(), 1);
    assertEquals(result.get(0).getDatapoints(), actual);
  }
Пример #2
0
  @Test
  public void movingRunOutOfPointsBeforeHittingwindow() {
    Transform movingTransform = new MetricMappingTransform(new MovingValueMapping());
    Map<Long, String> datapoints = new HashMap<Long, String>();

    datapoints.put(0L, "3.0");
    datapoints.put(60000L, "6.0");
    datapoints.put(120000L, "9.0");

    Map<Long, String> actual = new HashMap<Long, String>();

    actual.put(0L, "3.0");
    actual.put(60000L, "4.5");
    actual.put(120000L, "7.5");

    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("120s");
    constants.add("avg");

    List<Metric> result = movingTransform.transform(metrics, constants);

    assertEquals(result.get(0).getDatapoints().size(), 3);
    assertEquals(result.get(0).getDatapoints(), actual);
  }
Пример #3
0
  @Test
  public void testJoinTransformWithOneMetric() {
    Transform joinTransform = new JoinTransform();
    Map<Long, String> datapoints_1 = new HashMap<Long, String>();

    datapoints_1.put(1000L, "1");
    datapoints_1.put(2000L, "2");
    datapoints_1.put(3000L, "3");

    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, String> expected = new HashMap<Long, String>();

    expected.put(1000L, "1");
    expected.put(2000L, "2");
    expected.put(3000L, "3");

    List<Metric> result = joinTransform.transform(metrics);

    assertEquals(result.get(0).getDatapoints().size(), 3);
    assertEquals(expected, result.get(0).getDatapoints());
  }
Пример #4
0
  @Test
  public void testMovingMedianTransformWithTimeInterval() {
    Transform movingTransform = new MetricMappingTransform(new MovingValueMapping());
    Map<Long, String> datapoints = new HashMap<Long, String>();

    datapoints.put(1000L, "1");
    datapoints.put(2000L, "2");
    datapoints.put(3000L, "3");
    datapoints.put(5000L, "10");
    datapoints.put(6000L, "2");
    datapoints.put(7000L, "3");
    datapoints.put(10000L, "15");

    Map<Long, String> actual = new HashMap<Long, String>();

    actual.put(1000L, "1.0");
    actual.put(2000L, "1.5");
    actual.put(3000L, "2.5");
    actual.put(5000L, "10.0");
    actual.put(6000L, "6.0");
    actual.put(7000L, "2.5");
    actual.put(10000L, "15.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("2s");
    constants.add("median");

    List<Metric> result = movingTransform.transform(metrics, constants);

    assertEquals(result.get(0).getDatapoints().size(), actual.size());
    assertEquals(result.get(0).getDatapoints(), actual);
  }
Пример #5
0
  @Test
  public void testJoinTransformWithMultipleMetrics() {
    Transform joinTransform = new JoinTransform();
    Map<Long, String> datapoints_1 = new HashMap<Long, String>();

    datapoints_1.put(1000L, "1");
    datapoints_1.put(2000L, "2");
    datapoints_1.put(3000L, "3");

    Metric metric_1 = new Metric(TEST_SCOPE, TEST_METRIC);

    metric_1.setDatapoints(datapoints_1);

    Map<Long, String> datapoints_2 = new HashMap<Long, String>();

    datapoints_2.put(4000L, "10");
    datapoints_2.put(5000L, "100");
    datapoints_2.put(6000L, "1000");

    Metric metric_2 = new Metric(TEST_SCOPE, TEST_METRIC);

    metric_2.setDatapoints(datapoints_2);

    Map<Long, String> datapoints_3 = new HashMap<Long, String>();

    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, String> expected_1 = new HashMap<Long, String>();
    Map<Long, String> expected_2 = new HashMap<Long, String>();
    Map<Long, String> expected_3 = new HashMap<Long, String>();

    expected_1.put(1000L, "1");
    expected_1.put(2000L, "2");
    expected_1.put(3000L, "3");
    expected_2.put(4000L, "10");
    expected_2.put(5000L, "100");
    expected_2.put(6000L, "1000");
    expected_3.put(7000L, "0.1");
    expected_3.put(8000L, "0.01");
    expected_3.put(9000L, "0.0001");

    List<Metric> result = joinTransform.transform(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());
  }