{
QueryHistory history = new QueryHistory();
for (int i = 0; i < 600; i++) {
CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTable1 where id=" + i);
history.add(new QueryEntry(query, 4563));
}
assertEquals(500, history.size());
testHistRange(history, 599, 100);
storage.store(userId, history);
}
{
Optional<QueryHistory> history = storage.read(userId, QueryHistory.class);
assertNotNull(history);
assertEquals(500, history.get().size());
testHistRange(history.get(), 599, 100);
for (int i = 0; i < 10; i++) {
CqlQuery query = new CqlQuery(CqlQueryType.SELECT, "select * from MyTable2 where id=" + i);
history.get().add(new QueryEntry(query, 567));
}
storage.store(userId, history.get());
}
{
QueryHistory history = storage.read(userId, QueryHistory.class).get();
assertNotNull(history);
assertEquals(500, history.size());
try (QueryHistory.HistoryIterator hit = history.iterator()) {
for (int i = 9; i >= 0; i--) {
assertTrue(hit.hasNext());
QueryEntry entry = hit.next();
assertTrue(history.contains(entry));
assertNotNull(entry.executedOnUtc);
assertEquals("select * from MyTable2 where id=" + i, entry.query.part);
}
for (int i = 599; i > 110; i--) {
assertTrue(hit.hasNext());
QueryEntry entry = hit.next();
assertTrue(history.contains(entry));
assertNotNull(entry.executedOnUtc);
assertEquals("select * from MyTable1 where id=" + i, entry.query.part);
}
}