@Test
  public void testNoTtl() throws DatastoreException {
    m_aggregator.setMetricName("testTtl");

    ListDataPointGroup group = new ListDataPointGroup("group");
    group.addDataPoint(new LongDataPoint(1, 10));
    group.addDataPoint(new LongDataPoint(2, 20));

    DataPointGroup results = m_aggregator.aggregate(group);

    assertThat(results.hasNext(), equalTo(true));
    DataPoint dataPoint = results.next();
    assertThat(dataPoint.getTimestamp(), equalTo(1L));
    assertThat(dataPoint.getLongValue(), equalTo(10L));

    verify(m_mockDatastore)
        .putDataPoint(eq("testTtl"), any(ImmutableSortedMap.class), eq(dataPoint), eq(0));

    assertThat(results.hasNext(), equalTo(true));
    dataPoint = results.next();
    assertThat(dataPoint.getTimestamp(), equalTo(2L));
    assertThat(dataPoint.getLongValue(), equalTo(20L));

    verify(m_mockDatastore)
        .putDataPoint(eq("testTtl"), any(ImmutableSortedMap.class), eq(dataPoint), eq(0));

    results.close();
  }
  @Test
  public void testNotAddingSavedFrom() throws DatastoreException {
    m_aggregator.setMetricName("testTtl");
    m_aggregator.setTags(ImmutableSortedMap.<String, String>of("sweet_tag", "value"));
    m_aggregator.setAddSavedFrom(false);

    ImmutableSortedMap<String, String> verifyMap =
        ImmutableSortedMap.<String, String>naturalOrder().put("sweet_tag", "value").build();

    ListDataPointGroup group = new ListDataPointGroup("group");
    group.addDataPoint(new LongDataPoint(1, 10));
    group.addDataPoint(new LongDataPoint(2, 20));
    group.addTag("host", "tag_should_not_be_there");

    DataPointGroup results = m_aggregator.aggregate(group);

    assertThat(results.hasNext(), equalTo(true));
    DataPoint dataPoint = results.next();
    assertThat(dataPoint.getTimestamp(), equalTo(1L));
    assertThat(dataPoint.getLongValue(), equalTo(10L));

    verify(m_mockDatastore).putDataPoint(eq("testTtl"), eq(verifyMap), eq(dataPoint), eq(0));

    assertThat(results.hasNext(), equalTo(true));
    dataPoint = results.next();
    assertThat(dataPoint.getTimestamp(), equalTo(2L));
    assertThat(dataPoint.getLongValue(), equalTo(20L));

    verify(m_mockDatastore).putDataPoint(eq("testTtl"), eq(verifyMap), eq(dataPoint), eq(0));

    results.close();
  }
  @Test
  public void testGroupByTagFilter() throws DatastoreException {
    m_aggregator.setMetricName("testTtl");
    m_aggregator.setTtl(42);

    GroupBy groupBy = new TagGroupBy("host", "host2");

    m_aggregator.setGroupBys(Collections.singletonList(groupBy));

    ImmutableSortedMap<String, String> verifyMap =
        ImmutableSortedMap.<String, String>naturalOrder()
            .put("saved_from", "group")
            .put("host", "bob")
            .build();

    ListDataPointGroup group = new ListDataPointGroup("group");
    group.addDataPoint(new LongDataPoint(1, 10));
    group.addDataPoint(new LongDataPoint(2, 20));
    group.addTag("host", "bob");
    group.addTag("some_tag", "tag_should_not_be_there");
    group.addTag("host2", "host2_tag");
    group.addTag("host2", "wont show up because there are two");

    DataPointGroup results = m_aggregator.aggregate(group);

    assertThat(results.hasNext(), equalTo(true));
    DataPoint dataPoint = results.next();
    assertThat(dataPoint.getTimestamp(), equalTo(1L));
    assertThat(dataPoint.getLongValue(), equalTo(10L));

    verify(m_mockDatastore).putDataPoint(eq("testTtl"), eq(verifyMap), eq(dataPoint), eq(42));

    assertThat(results.hasNext(), equalTo(true));
    dataPoint = results.next();
    assertThat(dataPoint.getTimestamp(), equalTo(2L));
    assertThat(dataPoint.getLongValue(), equalTo(20L));

    verify(m_mockDatastore).putDataPoint(eq("testTtl"), eq(verifyMap), eq(dataPoint), eq(42));

    results.close();
  }
 @Override
 public void close() {
   m_innerDataPointGroup.close();
 }