@Test(enabled = ENABLED)
public void insertAndFindIndexEntries() {
dao = new MetricsDAO(storageSession, new MetricsConfiguration().setIndexPageSize(2).setIndexPartitions(1));
IndexEntry entry1 = new IndexEntry(IndexBucket.RAW, 0, hour(2).getMillis(), 100);
IndexEntry entry2 = new IndexEntry(IndexBucket.RAW, 0, hour(2).getMillis(), 101);
IndexEntry entry5 = new IndexEntry(IndexBucket.RAW, 0, hour(2).getMillis(), 103);
IndexEntry entry6 = new IndexEntry(IndexBucket.RAW, 0, hour(2).getMillis(), 104);
dao.updateIndex(IndexBucket.RAW, hour(2).getMillis(), 100).get();
dao.updateIndex(IndexBucket.RAW, hour(2).getMillis(), 101).get();
dao.updateIndex(IndexBucket.RAW, hour(2).getMillis(), 102).get();
dao.updateIndex(IndexBucket.RAW, hour(3).getMillis(), 101).get();
dao.updateIndex(IndexBucket.RAW, hour(2).getMillis(), 103).get();
dao.updateIndex(IndexBucket.RAW, hour(2).getMillis(), 104).get();
dao.updateIndex(IndexBucket.RAW, hour(2).getMillis(), 105).get();
List<IndexEntry> expected = asList(entry1, entry2);
List<IndexEntry> actual = new ArrayList<IndexEntry>();
ResultSet resultSet = dao.findIndexEntries(IndexBucket.RAW, 0, hour(2).getMillis()).get();
for (Row row : resultSet) {
actual.add(new IndexEntry(IndexBucket.RAW, 0, hour(2).getMillis(), row.getInt(0)));
}
assertEquals(actual, expected, "The first page of index entries is wrong");
actual.clear();
resultSet = dao.findIndexEntries(IndexBucket.RAW, 0, hour(2).getMillis(), 102).get();
expected = asList(entry5, entry6);
for (Row row : resultSet) {
actual.add(new IndexEntry(IndexBucket.RAW, 0, hour(2).getMillis(), row.getInt(0)));
}
assertEquals(actual, expected, "The next page of index entries is wrong");
}