@Override public List<E> list() throws SearchException { List<E> values = new ArrayList<>(); try (ResultIterator<E> iterator = iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.EAGER))) { while (iterator.hasNext()) { values.add(iterator.next()); } } return values; }
@Override public List<E> list() throws SearchException { partitionHandlingSupport.checkCacheAvailable(); List<E> values = new ArrayList<>(); try (ResultIterator<E> iterator = iterator(new FetchOptions().fetchMode(FetchOptions.FetchMode.EAGER))) { while (iterator.hasNext()) { values.add(iterator.next()); } } return values; }
private void assertQueryIteratorContains(ResultIterator<?> iterator, Object[] expected) { assert iterator.hasNext(); Object[] array = (Object[]) iterator.next(); assert Arrays.equals(array, expected); assert !iterator.hasNext(); }
public void testNextAndHasNext() { for (int i = 0; i < keys.size(); i++) { Object expectedValue = resultAt(i); assert iterator.hasNext(); // should have next as long as we are less than the number of elements. assert expectedValue == iterator.next(); // tests next() } assert !iterator.hasNext(); // this should now NOT be true. }
@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 = 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(); } }
@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 = UnsupportedOperationException.class) public void testIteratorRemove() throws ParseException { loadTestingData(); queryParser = createQueryParser("blurb"); Query luceneQuery = queryParser.parse("Eats"); CacheQuery<?> cacheQuery = Search.getSearchManager(cache).getQuery(luceneQuery); ResultIterator<?> iterator = cacheQuery.iterator(); try { if (iterator.hasNext()) { iterator.next(); iterator.remove(); } } finally { iterator.close(); } StaticTestingErrorHandler.assertAllGood(cache); }
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 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; }); }
@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 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; }); }
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 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 testQuerySkipsNullsInDefaultIterator() throws Exception { prepareData(); withTx(tm(0), (Callable<Void>) () -> { Cache<String, Foo> cache = getKeyLocation("1"); cache.remove("1"); // cache will now be out of sync with the index searchManager = Search.getSearchManager(cache); Query query = createQueryBuilder().keyword().onField("bar").matching("1").createQuery(); ResultIterator<?> iterator = searchManager.getQuery(query).iterator(); assertFalse(iterator.hasNext()); try { iterator.next(); fail("Expected NoSuchElementException"); } catch (NoSuchElementException e) { // pass } return null; }); }
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; }); }
public void testQueryReturnsNullWhenProjectingCacheValue() throws Exception { prepareData(); withTx(tm(0), (Callable<Void>) () -> { Cache<String, Foo> cache = getKeyLocation("1"); cache.remove("1"); // cache will now be out of sync with the index searchManager = Search.getSearchManager(cache); 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("Expected an element in iterator.", iterator.hasNext()); Object[] projection = iterator.next(); assertNull(projection[0]); assertEquals("1", projection[1]); return null; }); }