@Test
public void testCreateReadAndClear() throws Exception {
QueryFavourites favourites = favService.read();
for (int i = 0; i < 20; i++) {
assertTrue(favourites.addWithSizeCheck(new QueryEntry(new CqlQuery(CqlQueryType.SELECT,
"select * from HistoryStarTest where id=" + i), 1000 + i)));
assertTrue(favourites.addWithSizeCheck(new QueryEntry(new CqlQuery(CqlQueryType.SELECT,
"select * from HistoryStarTest where id=" + i), 2000 + i)));
favService.store(favourites);
QueryFavourites favQueue = asyncFileStore.getFromWriteQueue(user).get();
assertNotNull(favQueue);
// should be the same instance
assertSame(favourites, favQueue);
}
assertEquals(20, favourites.size());
assertFalse(storage.read(user, QueryFavourites.class).isPresent());
asyncFileStore.flush();
assertFalse(asyncFileStore.getFromWriteQueue(user).isPresent());
assertSame(favourites, favService.read());
QueryFavourites readFavs = storage.read(user, QueryFavourites.class).get();
assertNotSame(favourites, readFavs);
{
for (int i = 0; i < 20; i++) {
QueryEntry entry = new QueryEntry(new CqlQuery(CqlQueryType.SELECT,
"select * from HistoryStarTest where id=" + i), 4000 + i);
assertTrue(entry.toString(), readFavs.contains(entry));
}
}