diff --git a/processing/src/test/java/io/druid/segment/incremental/IncrementalIndexStorageAdapterTest.java b/processing/src/test/java/io/druid/segment/incremental/IncrementalIndexStorageAdapterTest.java index e3b603af9ae..fc0fa5fa177 100644 --- a/processing/src/test/java/io/druid/segment/incremental/IncrementalIndexStorageAdapterTest.java +++ b/processing/src/test/java/io/druid/segment/incremental/IncrementalIndexStorageAdapterTest.java @@ -37,9 +37,12 @@ import io.druid.query.filter.DimFilters; import io.druid.query.groupby.GroupByQuery; import io.druid.query.groupby.GroupByQueryConfig; import io.druid.query.groupby.GroupByQueryEngine; -import junit.framework.Assert; +import io.druid.segment.Cursor; +import io.druid.segment.DimensionSelector; +import io.druid.segment.filter.SelectorFilter; import org.joda.time.DateTime; import org.joda.time.Interval; +import org.junit.Assert; import org.junit.Test; import java.nio.ByteBuffer; @@ -115,6 +118,56 @@ public class IncrementalIndexStorageAdapterTest Assert.assertEquals(ImmutableMap.of("sally", "bo", "cnt", 1l), row.getEvent()); } + @Test + public void testResetSanity() { + IncrementalIndex index = new IncrementalIndex( + 0, QueryGranularity.MINUTE, new AggregatorFactory[]{new CountAggregatorFactory("cnt")} + ); + + + DateTime t = DateTime.now(); + Interval interval = new Interval(t.minusMinutes(1), t.plusMinutes(1)); + + index.add( + new MapBasedInputRow( + t.minus(1).getMillis(), + Lists.newArrayList("billy"), + ImmutableMap.of("billy", "hi") + ) + ); + index.add( + new MapBasedInputRow( + t.minus(1).getMillis(), + Lists.newArrayList("sally"), + ImmutableMap.of("sally", "bo") + ) + ); + + IncrementalIndexStorageAdapter adapter = new IncrementalIndexStorageAdapter(index); + Iterable cursorIterable = adapter.makeCursors(new SelectorFilter("sally", "bo"), + interval, + QueryGranularity.NONE); + Cursor cursor = cursorIterable.iterator().next(); + DimensionSelector dimSelector; + + dimSelector = cursor.makeDimensionSelector("sally"); + Assert.assertEquals("bo", dimSelector.lookupName(dimSelector.getRow().get(0))); + + index.add( + new MapBasedInputRow( + t.minus(1).getMillis(), + Lists.newArrayList("sally"), + ImmutableMap.of("sally", "ah") + ) + ); + + // Cursor reset should not be affected by out of order values + cursor.reset(); + + dimSelector = cursor.makeDimensionSelector("sally"); + Assert.assertEquals("bo", dimSelector.lookupName(dimSelector.getRow().get(0))); + } + @Test public void testFilterByNull() throws Exception {