geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject [5/6] incubator-geode git commit: GEODE-11: PageableLuceneQueryResults extends Iterator
Date Fri, 24 Jun 2016 21:55:15 GMT
GEODE-11: PageableLuceneQueryResults extends Iterator

Changing PageableLuceneQueryResults to extend
Iterator<List<LuceneResultStruct>> so that it can be used with utilities that
expect an iterator.

This closes #169


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/8bbea5b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/8bbea5b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/8bbea5b5

Branch: refs/heads/develop
Commit: 8bbea5b5809ffefb43f669b3ab59830797f50897
Parents: 2c4e17f
Author: Aparna Dharmakkan <adharmakkan@pivotal.io>
Authored: Mon Jun 20 15:31:22 2016 -0700
Committer: Dan Smith <upthewaterspout@apache.org>
Committed: Fri Jun 24 14:41:42 2016 -0700

----------------------------------------------------------------------
 .../lucene/PageableLuceneQueryResults.java      |  7 ++--
 .../cache/lucene/internal/LuceneQueryImpl.java  |  8 ++--
 .../PageableLuceneQueryResultsImpl.java         | 11 ++---
 .../LuceneIndexMaintenanceIntegrationTest.java  |  2 +-
 .../gemfire/cache/lucene/LuceneQueriesBase.java |  2 +-
 .../lucene/LuceneQueriesIntegrationTest.java    |  6 +--
 .../internal/LuceneQueryImplJUnitTest.java      | 13 +-----
 ...PageableLuceneQueryResultsImplJUnitTest.java | 44 ++++++++++++++------
 .../cache/lucene/test/LuceneTestUtilities.java  |  5 +--
 9 files changed, 53 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bbea5b5/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/PageableLuceneQueryResults.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/PageableLuceneQueryResults.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/PageableLuceneQueryResults.java
index ef229da..c2def44 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/PageableLuceneQueryResults.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/PageableLuceneQueryResults.java
@@ -19,6 +19,7 @@
 
 package com.gemstone.gemfire.cache.lucene;
 
+import java.util.Iterator;
 import java.util.List;
 
 import com.gemstone.gemfire.annotations.Experimental;
@@ -32,7 +33,7 @@ import com.gemstone.gemfire.annotations.Experimental;
  * @param <V> The type of the value
  */
 @Experimental
-public interface PageableLuceneQueryResults<K, V> {
+public interface PageableLuceneQueryResults<K, V> extends Iterator<List<LuceneResultStruct<K,V>>>
{
   /**
    * @return total number of hits for this query
    */
@@ -48,10 +49,10 @@ public interface PageableLuceneQueryResults<K, V> {
    * 
    * @return a page of results, or null if there are no more pages
    */
-  public List<LuceneResultStruct<K, V>> getNextPage();
+  public List<LuceneResultStruct<K, V>> next();
 
   /**
    *  True if there another page of results. 
    */
-  public boolean hasNextPage();
+  public boolean hasNext();
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bbea5b5/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
index 3125193..ef2f4ee 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
@@ -19,7 +19,6 @@
 
 package com.gemstone.gemfire.cache.lucene.internal;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -87,12 +86,11 @@ public class LuceneQueryImpl<K, V> implements LuceneQuery<K,
V> {
   @Override
   public List<LuceneResultStruct<K, V>> findResults() throws LuceneQueryException
{
     PageableLuceneQueryResults<K, V> pages = findPages(0);
-    final List<LuceneResultStruct<K, V>> page = pages.getNextPage();
-
-    if(page == null) {
+    if(!pages.hasNext()) {
       return Collections.emptyList();
     }
-    return page;
+
+    return pages.next();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bbea5b5/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
index 487b740..17668a7 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
@@ -22,6 +22,7 @@ package com.gemstone.gemfire.cache.lucene.internal;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
 
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.lucene.PageableLuceneQueryResults;
@@ -69,9 +70,9 @@ public class PageableLuceneQueryResultsImpl<K,V> implements PageableLuceneQueryR
   }
 
   @Override
-  public List<LuceneResultStruct<K,V>> getNextPage() {
-    if(!hasNextPage()) {
-      return null;
+  public List<LuceneResultStruct<K,V>> next() {
+    if(!hasNext()) {
+      throw new NoSuchElementException();
     }
     
     int end = currentHit + pageSize;
@@ -84,7 +85,7 @@ public class PageableLuceneQueryResultsImpl<K,V> implements PageableLuceneQueryR
     }
     
     Map<K,V> values = userRegion.getAll(keys);
-    
+
     ArrayList<LuceneResultStruct<K,V>> results = new ArrayList<LuceneResultStruct<K,V>>(hits.size());
     for(EntryScore<K> score : scores) {
       V value = values.get(score.getKey());
@@ -98,7 +99,7 @@ public class PageableLuceneQueryResultsImpl<K,V> implements PageableLuceneQueryR
   }
 
   @Override
-  public boolean hasNextPage() {
+  public boolean hasNext() {
     return hits.size() > currentHit;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bbea5b5/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
index d0c91e5..7d7fa3d 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
@@ -155,7 +155,7 @@ public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest
     index.waitUntilFlushed(WAIT_FOR_FLUSH_TIME);
     // Execute query to fetch all the values for "description" field.
     LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME,
"description:\"hello world\"", DEFAULT_FIELD);
-    LuceneQueryResults<Integer, TestObject> results = query.search();
+    PageableLuceneQueryResults<Integer, TestObject> results = query.findPages();
     // The query should return 0 results.
     assertEquals(0, results.size());
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bbea5b5/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
index 77ce0bb..301d5af 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
@@ -152,7 +152,7 @@ public abstract class LuceneQueriesBase extends LuceneDUnitTest {
       query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "text:world",
DEFAULT_FIELD);
       PageableLuceneQueryResults<Integer, TestObject> results = query.findPages();
       assertEquals(3, results.size());
-      List<LuceneResultStruct<Integer, TestObject>> page = results.getNextPage();
+      List<LuceneResultStruct<Integer, TestObject>> page = results.next();
 
       Map<Integer, TestObject> data = new HashMap<Integer, TestObject>();
       for (LuceneResultStruct<Integer, TestObject> row : page) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bbea5b5/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
index d563f4e..988e4f5 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -122,10 +122,10 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest
{
     final LuceneQuery<Object, Object> query = addValuesAndCreateQuery();
 
     final PageableLuceneQueryResults<Object, Object> pages = query.findPages();
-    assertTrue(pages.hasNextPage());
+    assertTrue(pages.hasNext());
     assertEquals(3, pages.size());
-    final List<LuceneResultStruct<Object, Object>> page1 = pages.getNextPage();
-    final List<LuceneResultStruct<Object, Object>> page2 = pages.getNextPage();
+    final List<LuceneResultStruct<Object, Object>> page1 = pages.next();
+    final List<LuceneResultStruct<Object, Object>> page2 = pages.next();
     List<LuceneResultStruct<Object, Object>> allEntries=new ArrayList<>();
     allEntries.addAll(page1);
     allEntries.addAll(page2);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bbea5b5/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplJUnitTest.java
index 95371e4..c325f55 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplJUnitTest.java
@@ -19,7 +19,6 @@
 
 package com.gemstone.gemfire.cache.lucene.internal;
 
-import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
@@ -32,20 +31,14 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.mockito.ArgumentCaptor;
 
 import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.execute.Execution;
-import com.gemstone.gemfire.cache.execute.FunctionAdapter;
-import com.gemstone.gemfire.cache.execute.FunctionContext;
-import com.gemstone.gemfire.cache.execute.FunctionService;
 import com.gemstone.gemfire.cache.execute.ResultCollector;
-import com.gemstone.gemfire.cache.lucene.LuceneIntegrationTest;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryException;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryProvider;
 import com.gemstone.gemfire.cache.lucene.PageableLuceneQueryResults;
@@ -55,10 +48,6 @@ import com.gemstone.gemfire.cache.lucene.internal.distributed.LuceneFunction;
 import com.gemstone.gemfire.cache.lucene.internal.distributed.LuceneFunctionContext;
 import com.gemstone.gemfire.cache.lucene.internal.distributed.TopEntries;
 import com.gemstone.gemfire.cache.lucene.internal.distributed.TopEntriesCollector;
-import com.gemstone.gemfire.cache.lucene.internal.distributed.TopEntriesCollectorManager;
-import com.gemstone.gemfire.cache.lucene.internal.repository.IndexResultCollector;
-import com.gemstone.gemfire.internal.cache.ValidatingDiskRegion;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
@@ -151,7 +140,7 @@ public class LuceneQueryImplJUnitTest {
     assertEquals("index", context.getIndexName());
 
     assertEquals(5, results.getMaxScore(), 0.01);
-    final List<LuceneResultStruct<Object, Object>> page = results.getNextPage();
+    final List<LuceneResultStruct<Object, Object>> page = results.next();
     assertEquals(1, page.size());
     LuceneResultStruct element = page.iterator().next();
     assertEquals("hi", element.getKey());

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bbea5b5/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/PageableLuceneQueryResultsImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/PageableLuceneQueryResultsImplJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/PageableLuceneQueryResultsImplJUnitTest.java
index 7703a74..902052b 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/PageableLuceneQueryResultsImplJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/PageableLuceneQueryResultsImplJUnitTest.java
@@ -22,13 +22,17 @@ import static org.junit.Assert.*;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
@@ -36,11 +40,15 @@ import org.mockito.stubbing.Answer;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.lucene.LuceneResultStruct;
 import com.gemstone.gemfire.cache.lucene.internal.distributed.EntryScore;
+import com.gemstone.gemfire.cache.lucene.internal.distributed.TopEntries;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
 public class PageableLuceneQueryResultsImplJUnitTest {
 
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
   private List<EntryScore<String>> hits;
   private List<LuceneResultStruct> expected = new ArrayList<LuceneResultStruct>();
   private Region<String, String> userRegion;
@@ -86,22 +94,23 @@ public class PageableLuceneQueryResultsImplJUnitTest {
     
     assertEquals(23, results.size());
     
-    assertTrue(results.hasNextPage());
+    assertTrue(results.hasNext());
     
-    List<LuceneResultStruct<String, String>> next  = results.getNextPage();
+    List<LuceneResultStruct<String, String>> next  = results.next();
     assertEquals(expected.subList(0, 10), next);
     
-    assertTrue(results.hasNextPage());
-    next  = results.getNextPage();
+    assertTrue(results.hasNext());
+    next  = results.next();
     assertEquals(expected.subList(10, 20), next);
     
-    assertTrue(results.hasNextPage());
-    next  = results.getNextPage();
+    assertTrue(results.hasNext());
+    next  = results.next();
     assertEquals(expected.subList(20, 23), next);
     
     
-    assertFalse(results.hasNextPage());
-    assertNull(results.getNextPage());
+    assertFalse(results.hasNext());
+    thrown.expect(NoSuchElementException.class);
+    results.next();
   }
   
   @Test
@@ -110,13 +119,24 @@ public class PageableLuceneQueryResultsImplJUnitTest {
     
     assertEquals(23, results.size());
     
-    assertTrue(results.hasNextPage());
+    assertTrue(results.hasNext());
     
-    List<LuceneResultStruct<String, String>> next  = results.getNextPage();
+    List<LuceneResultStruct<String, String>> next  = results.next();
     assertEquals(expected, next);
     
-    assertFalse(results.hasNextPage());
-    assertNull(results.getNextPage());
+    assertFalse(results.hasNext());
+    thrown.expect(NoSuchElementException.class);
+    results.next();
+  }
+
+  @Test
+  public void shouldThrowNoSuchElementExceptionFromNextWithNoMorePages() {
+    PageableLuceneQueryResultsImpl<String, String> results = new PageableLuceneQueryResultsImpl<>(
+      Collections.emptyList(), userRegion, 0);
+
+    assertFalse(results.hasNext());
+    thrown.expect(NoSuchElementException.class);
+    results.next();
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bbea5b5/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
index 06c3c7d..8aca11c 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
@@ -21,7 +21,6 @@ package com.gemstone.gemfire.cache.lucene.test;
 import static org.junit.Assert.*;
 
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
@@ -100,8 +99,8 @@ public class LuceneTestUtilities {
   public static <K> void verifyQueryKeyAndValues(LuceneQuery<K,Object> query,
HashMap expectedResults) throws LuceneQueryException {
     HashMap actualResults = new HashMap<>();
     final PageableLuceneQueryResults<K, Object> results = query.findPages();
-    while(results.hasNextPage()) {
-      results.getNextPage().stream()
+    while(results.hasNext()) {
+      results.next().stream()
         .forEach(struct -> {
           Object value = struct.getValue();
           if (value instanceof PdxInstance) {


Mime
View raw message