private void assertQueryReturns(CacheQuery<?> cacheQuery, Object[] expected) { assertQueryListContains(cacheQuery.list(), expected); try (ResultIterator<?> eagerIterator = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.EAGER))) { assertQueryIteratorContains(eagerIterator, expected); } try (ResultIterator<?> lazyIterator = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.LAZY))) { assertQueryIteratorContains(lazyIterator, expected); } }
@Test(expectedExceptions = UnsupportedOperationException.class) public void testIteratorRemove() { cacheQuery.maxResults(1); try (ResultIterator<Person> iterator = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.EAGER))) { assert iterator.hasNext(); iterator.remove(); } StaticTestingErrorHandler.assertAllGood(cacheAMachine1, cacheAMachine2); }
public void testLazyNonOrdered() { try (ResultIterator<Person> ignored = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.LAZY))) { assert cacheQuery.getResultSize() == 10 : cacheQuery.getResultSize(); } StaticTestingErrorHandler.assertAllGood(cacheAMachine1, cacheAMachine2); }
@Test(expectedExceptions = UnsupportedOperationException.class) public void testEagerIteratorRemove() throws ParseException { loadTestingData(); CacheQuery<?> cacheQuery = createCacheQuery(cache, "blurb", "playing"); ResultIterator<?> found = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.EAGER)); try { assertTrue(found.hasNext()); found.remove(); } finally { found.close(); } }
@Test(expectedExceptions = NoSuchElementException.class) public void testIteratorNextOutOfBounds() { cacheQuery.maxResults(1); try (ResultIterator<Person> iterator = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.EAGER))) { assert iterator.hasNext(); iterator.next(); assert !iterator.hasNext(); iterator.next(); } StaticTestingErrorHandler.assertAllGood(cacheAMachine1, cacheAMachine2); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testLazyIteratorWithInvalidFetchSize() throws ParseException { loadTestingData(); queryParser = createQueryParser("blurb"); Query luceneQuery = queryParser.parse("Eats"); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).<Person>getQuery(luceneQuery).firstResult(1); cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.LAZY).fetchSize(0)); }
@Test(expectedExceptions = NoSuchElementException.class) public void testLazyIteratorWithNoElementsFound() throws ParseException { loadTestingData(); queryParser = createQueryParser("blurb"); Query luceneQuery = queryParser.parse("fish"); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).<Person>getQuery(luceneQuery).firstResult(1); ResultIterator<?> found = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.LAZY)); try { found.next(); } finally { found.close(); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testIteratorWithNullFetchMode() throws ParseException { loadTestingData(); queryParser = createQueryParser("blurb"); Query luceneQuery = queryParser.parse("Eats"); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).<Person>getQuery(luceneQuery).firstResult(1); ResultIterator<?> found = cacheQuery.iterator(new FetchOptions().fetchMode(null)); try { found.next(); } finally { found.close(); } }
@Test(expectedExceptions = NoSuchElementException.class) public void testEagerIteratorExCase() throws ParseException { loadTestingData(); CacheQuery<?> cacheQuery = createCacheQuery(cache, "blurb", "playing"); ResultIterator<?> found = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.EAGER)); try { assertTrue(found.hasNext()); found.next(); assertFalse(found.hasNext()); found.next(); } finally { found.close(); } }
public void testEagerIterator() throws ParseException { loadTestingData(); CacheQuery<?> cacheQuery = createCacheQuery(cache, "blurb", "playing"); ResultIterator<?> found = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.EAGER)); try { assertTrue(found.hasNext()); found.next(); assertFalse(found.hasNext()); } finally { found.close(); } StaticTestingErrorHandler.assertAllGood(cache); }
@Test public void testQuerySkipsNullsInEagerIterator() throws Exception { withTx(tm(), (Callable<Void>) () -> { cache.remove("1"); // cache will now be out of sync with the index Query query = createQueryBuilder().keyword().onField("bar").matching("1").createQuery(); ResultIterator<?> iterator = searchManager.getQuery(query).iterator(new FetchOptions().fetchMode(EAGER)); assertFalse(iterator.hasNext()); try { iterator.next(); fail("Expected NoSuchElementException"); } catch (NoSuchElementException e) { // pass } return null; }); }
@Test public void testQueryReturnsNullWhenProjectingCacheValue() throws Exception { withTx(tm(), (Callable<Void>) () -> { cache.remove("1"); // cache will now be out of sync with the index Query query = createQueryBuilder().keyword().onField("bar").matching("1").createQuery(); ResultIterator<Object[]> iterator = searchManager.getQuery(query).projection(ProjectionConstants.VALUE, "bar").iterator(new FetchOptions().fetchMode(LAZY)); assertTrue(iterator.hasNext()); Object[] projection = iterator.next(); assertNull(projection[0]); assertEquals("1", projection[1]); return null; }); }
@Test public void testQuerySkipsNullsInLazyIterator() throws Exception { withTx(tm(), (Callable<Void>) () -> { cache.remove("1"); // cache will now be out of sync with the index Query query = createQueryBuilder().keyword().onField("bar").matching("1").createQuery(); ResultIterator<?> iterator = searchManager.getQuery(query).iterator(new FetchOptions().fetchMode(LAZY)); assertFalse(iterator.hasNext()); try { iterator.next(); fail("Expected NoSuchElementException"); } catch (NoSuchElementException e) { // pass } return null; }); }
public void testLazyIteratorWithOffset() throws ParseException { loadTestingData(); queryParser = createQueryParser("blurb"); Query luceneQuery = queryParser.parse("Eats"); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).<Person>getQuery(luceneQuery).firstResult(1); ResultIterator<?> iterator = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.LAZY)); try { assertEquals(2, countElements(iterator)); } finally { iterator.close(); } StaticTestingErrorHandler.assertAllGood(cache); }
public void testIteratorWithDefaultOptions() throws ParseException { loadTestingData(); queryParser = createQueryParser("blurb"); Query luceneQuery = queryParser.parse("playing"); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).getQuery(luceneQuery); ResultIterator<?> found = cacheQuery.iterator(); try { assertTrue(found.hasNext()); found.next(); assertFalse(found.hasNext()); } finally { found.close(); } StaticTestingErrorHandler.assertAllGood(cache); }
public void testEagerOrdered() { // applying sort SortField sortField = new SortField("age", Type.INT); Sort sort = new Sort(sortField); cacheQuery.sort(sort); try (ResultIterator<Person> iterator = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.EAGER))) { assertEquals(10, cacheQuery.getResultSize()); int previousAge = 0; while (iterator.hasNext()) { Person person = iterator.next(); assert person.getAge() > previousAge; previousAge = person.getAge(); } } StaticTestingErrorHandler.assertAllGood(cacheAMachine1, cacheAMachine2); }
public void testSearchKeyTransformer() throws ParseException { SearchManagerImplementor manager = (SearchManagerImplementor) Search.getSearchManager(cache); manager.registerKeyTransformer(CustomKey3.class, CustomKey3Transformer.class); loadTestingDataWithCustomKey(); queryParser = createQueryParser("blurb"); Query luceneQuery = queryParser.parse("Eats"); CacheQuery<?> cacheQuery = manager.getQuery(luceneQuery); ResultIterator<?> iterator = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.LAZY)); try { assertEquals(3, countElements(iterator)); } finally { iterator.close(); } StaticTestingErrorHandler.assertAllGood(cache); }
public void testSearchManagerWithInstantiation() throws ParseException { loadTestingData(); queryParser = createQueryParser("blurb"); Query luceneQuery = queryParser.parse("playing"); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).getQuery(luceneQuery); ResultIterator<?> found = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.valueOf("LAZY"))); try { assertTrue(found.hasNext()); found.next(); assertFalse(found.hasNext()); } finally { found.close(); } }
public void testLazyIterator() throws ParseException { loadTestingData(); queryParser = createQueryParser("blurb"); Query luceneQuery = queryParser.parse("playing"); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).getQuery(luceneQuery); ResultIterator<?> found = cacheQuery.iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.LAZY)); try { assertTrue(found.hasNext()); found.next(); assertFalse(found.hasNext()); } finally { found.close(); } StaticTestingErrorHandler.assertAllGood(cache); }
public void testQuerySkipsNullsInEagerIterator() throws Exception { prepareData(); withTx(tm(0), (Callable<Void>) () -> { cache1.remove("1"); // cache will now be out of sync with the index searchManager = Search.getSearchManager(cache1); Query query = createQueryBuilder().keyword().onField("bar").matching("1").createQuery(); ResultIterator<?> iterator = searchManager.getQuery(query).iterator(new FetchOptions().fetchMode(EAGER)); assertFalse("Iterator should not have elements.", iterator.hasNext()); try { iterator.next(); fail("Expected NoSuchElementException"); } catch (NoSuchElementException e) { // pass } return null; }); }