public void testBothRanges() {
rangeTestHelper(20, 28);
}
private void rangeTestHelper(final int start, final int end) {
Broker broker = _factory.newBroker();
Query q = broker.newQuery(JPQLParser.LANG_JPQL, "Select a FROM " +
CacheObjectAChild1.class.getSimpleName() + " a");
q.setRange(start, end);
// should not yet be in the cache
CacheTestHelper.assertInCache(this, q, Boolean.FALSE);
Collection c = (Collection) q.execute();
// iterate the results. This will cause the query to be
// enlisted in the cache.
CacheTestHelper.iterate(c);
assertEquals(end - start, c.size());
CacheTestHelper.assertInCache(this, q, Boolean.TRUE);
broker.close();
broker = _factory.newBroker();
q = broker.newQuery(JPQLParser.LANG_JPQL, "Select a FROM " +
CacheObjectAChild1.class.getSimpleName() + " a");
q.setRange(start, end);
CacheTestHelper.assertInCache(this, q, Boolean.TRUE);
c = (Collection) q.execute();
assertEquals(end - start, c.size());
// now check if a smaller range is in cache
q = broker.newQuery(JPQLParser.LANG_JPQL, "Select a FROM " +
CacheObjectAChild1.class.getSimpleName() + " a");
q.setRange(start, end - 1);
CacheTestHelper.assertInCache(this, q, Boolean.FALSE);
c = (Collection) q.execute();
assertEquals(end - start - 1, c.size());
broker.close();
}