CloudDatastoreBackend extends AbstractDatabaseBackend { @Override public int deleteExpiredItems(Class modelClass, String field, Long cutoffTime, Integer numItems) { Datastore datastore = getService(); KeyQuery.Builder queryBuilder = Query.newKeyQueryBuilder() .setKind(modelClass.getSimpleName()) .setFilter(PropertyFilter.le(field, cutoffTime)) .setOrderBy(OrderBy.asc(field)); if (numItems != null) { queryBuilder.setLimit(numItems); } KeyQuery query = queryBuilder.build(); final QueryResults<Key> keys = datastore.run(query); int numDeletedItems = 0; while (keys.hasNext()) { datastore.delete(keys.next()); numDeletedItems++; } return numDeletedItems; }  @Override List<Model> getAll(Class modelClass); @Override Model get(Class modelClass, String objectId); void save(Model model); @Override void delete(Model model); @Override int deleteExpiredItems(Class modelClass, String field, Long cutoffTime, Integer numItems); @Override void initializeDatabase(); @Override CheckResult checkConnection();  }
@Test public void testDeleteExpiredItems() { deleteExpiredItems(false); }
@Test public void testDeleteExpiredItemsWithLimit() { deleteExpiredItems(true); }