geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasonhu...@apache.org
Subject [geode] 01/03: GEODE-3736: CompactRangeIndex getSizeEstimate should not throw ClassCastExceptions
Date Thu, 05 Oct 2017 23:01:57 GMT
This is an automated email from the ASF dual-hosted git repository.

jasonhuynh pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 13143fb481b9b6fd66da73a3787684cc555ba1ad
Author: Jason Huynh <huynhja@gmail.com>
AuthorDate: Wed Oct 4 11:08:47 2017 -0700

    GEODE-3736: CompactRangeIndex getSizeEstimate should not throw ClassCastExceptions
    
      * Minor refactor of CorruptedIndexIntegrationTest
      * Refactored CompactRangeIndexQueryIntegrationTest to use ServerStarterRule
---
 .../query/internal/index/CompactRangeIndex.java    |  5 +++
 .../query/dunit/CorruptedIndexIntegrationTest.java | 29 ++-------------
 .../CompactRangeIndexQueryIntegrationTest.java     | 41 ++++++++++++++++++++--
 3 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactRangeIndex.java
b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactRangeIndex.java
index ad4f3a1..2cb7857 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactRangeIndex.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactRangeIndex.java
@@ -429,6 +429,11 @@ public class CompactRangeIndex extends AbstractIndex {
           }
           break;
       }
+    } catch (ClassCastException e) {
+      //no values will match in this index because the key types are not the same
+      //This means that there will be 0 results and it will be fast to use this index
+      //because it has filtered everything out
+      return 0;
     } catch (EntryDestroyedException ignore) {
       return Integer.MAX_VALUE;
     } finally {
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/dunit/CorruptedIndexIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/cache/query/dunit/CorruptedIndexIntegrationTest.java
index b7a3742..64ff11e 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/query/dunit/CorruptedIndexIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/dunit/CorruptedIndexIntegrationTest.java
@@ -63,14 +63,11 @@ public class CorruptedIndexIntegrationTest extends JUnit4CacheTestCase
{
 
     IntStream.rangeClosed(1, 3).forEach(i -> region.put(i, new Portfolio(i)));
 
-
     assertEquals("Uncorrupted index must have all the entries", 3,
         idIndex.getStatistics().getNumberOfValues());
     assertEquals("Corrupted index should not have indexed any entries", 0,
         exceptionIndex.getStatistics().getNumberOfValues());
-
     SelectResults results = (SelectResults) queryService.newQuery(queryString).execute();
-
     assertEquals("Query execution must be successful ", 1, results.size());
   }
 
@@ -100,9 +97,7 @@ public class CorruptedIndexIntegrationTest extends JUnit4CacheTestCase
{
 
     assertEquals("Uncorrupted index must have all the entries ", 3,
         idIndex.getStatistics().getNumberOfValues());
-
     SelectResults results = (SelectResults) queryService.newQuery(queryString).execute();
-
     assertEquals("Query execution must be successful ", 1, results.size());
   }
 
@@ -155,12 +150,9 @@ public class CorruptedIndexIntegrationTest extends JUnit4CacheTestCase
{
     map2.put("APPL", 3);
     map2.put("AOL", "hello");
     p2.positions = map2;
-
     region.put(2, p2);
 
     assertEquals("Put must be successful", 2, region.size());
-
-
     assertEquals("Index must be invalid at this point ", false, keyIndex1.isValid());
 
     QueryObserverImpl observer = new QueryObserverImpl();
@@ -170,12 +162,9 @@ public class CorruptedIndexIntegrationTest extends JUnit4CacheTestCase
{
         .newQuery(
             "select * from /portfolio p where p.positions['AOL'] = 'hello' OR p.positions['IBM']
= 2")
         .execute();
-
     assertEquals("Correct results expected from the query execution ", 2, results.size());
-
     assertEquals("No index must be used while executing the query ", 0,
         observer.indexesUsed.size());
-
   }
 
   @Test
@@ -203,7 +192,6 @@ public class CorruptedIndexIntegrationTest extends JUnit4CacheTestCase
{
     map2.put("APPL", 3);
     map2.put("AOL", "hello");
     p2.positions = map2;
-
     region.put(2, p2);
 
     assertEquals("Put must be successful", 2, region.size());
@@ -226,12 +214,9 @@ public class CorruptedIndexIntegrationTest extends JUnit4CacheTestCase
{
         .newQuery(
             "select * from /portfolio p where p.positions['AOL'] = 'hello' OR p.positions['IBM']
= 2")
         .execute();
-
     assertEquals("Current results expected from the query execution ", 2, results.size());
-
     assertEquals("No index must be used while executing the query ", 0,
         observer.indexesUsed.size());
-
   }
 
   @Test
@@ -240,7 +225,6 @@ public class CorruptedIndexIntegrationTest extends JUnit4CacheTestCase
{
     String regionName = "portfolio";
     String INDEX_NAME = "key_index1";
 
-
     Cache cache = getCache();
     Region region =
         cache.createRegionFactory().setDataPolicy(DataPolicy.PARTITION).create(regionName);
@@ -258,19 +242,13 @@ public class CorruptedIndexIntegrationTest extends JUnit4CacheTestCase
{
     map2.put("APPL", 3);
     map2.put("AOL", "hello");
     p2.positions = map2;
-
     region.put(2, p2);
 
     assertEquals("Put must be successful", 2, region.size());
 
     QueryService queryService = cache.getQueryService();
-
-    try {
-      Index keyIndex1 = queryService.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
-      assertEquals("Index must be valid", true, keyIndex1.isValid());
-    } catch (Exception exception) {
-      fail();
-    }
+    Index keyIndex1 = queryService.createIndex(INDEX_NAME, "positions[*]", "/portfolio");
+    assertEquals("Index must be valid", true, keyIndex1.isValid());
 
     QueryObserverImpl observer = new QueryObserverImpl();
     QueryObserverHolder.setInstance(observer);
@@ -279,11 +257,8 @@ public class CorruptedIndexIntegrationTest extends JUnit4CacheTestCase
{
         .newQuery(
             "select * from /portfolio p where p.positions['AOL'] = 'hello' OR p.positions['IBM']
= 2")
         .execute();
-
     assertEquals("Current results expected from the query execution ", 2, results.size());
-
     assertEquals("Index must be used while executing the query ", 2, observer.indexesUsed.size());
-
   }
 
 
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/CompactRangeIndexQueryIntegrationTest.java
b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/CompactRangeIndexQueryIntegrationTest.java
index 15a8c55..e970e7d 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/CompactRangeIndexQueryIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/CompactRangeIndexQueryIntegrationTest.java
@@ -19,10 +19,12 @@ import static org.junit.Assert.*;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.DataPolicy;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.cache.client.internal.Op;
@@ -31,8 +33,11 @@ import org.apache.geode.cache.query.Index;
 import org.apache.geode.cache.query.Query;
 import org.apache.geode.cache.query.QueryService;
 import org.apache.geode.cache.query.SelectResults;
+import org.apache.geode.cache.query.data.Portfolio;
 import org.apache.geode.cache.query.data.PortfolioPdx;
 
+import org.apache.geode.cache.query.dunit.CorruptedIndexIntegrationTest;
+import org.apache.geode.cache.query.internal.QueryObserverHolder;
 import org.apache.geode.cache.query.internal.index.CompactRangeIndex;
 import org.apache.geode.cache.query.internal.index.IndexProtocol;
 import org.apache.geode.internal.cache.LocalRegion;
@@ -44,14 +49,18 @@ import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
 
 @Category(IntegrationTest.class)
 public class CompactRangeIndexQueryIntegrationTest {
 
+  @Rule
+  public ServerStarterRule serverStarterRule = new ServerStarterRule().withAutoStart();
+
   @Test
   public void multipleNotEqualsClausesOnAPartitionedRegionShouldReturnCorrectResults()
       throws Exception {
-    Cache cache = CacheUtils.getCache();
+    Cache cache = serverStarterRule.getCache();
     Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create("portfolios");
     int numMatching = 10;
     QueryService qs = cache.getQueryService();
@@ -73,8 +82,7 @@ public class CompactRangeIndexQueryIntegrationTest {
   @Test
   public void whenAuxFilterWithAnIterableFilterShouldNotCombineFiltersIntoAndJunction()
       throws Exception {
-    CacheUtils.startCache();
-    Cache cache = CacheUtils.getCache();
+    Cache cache = serverStarterRule.getCache();
     Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create("ExampleRegion");
     QueryService qs = cache.getQueryService();
     qs.createIndex("ExampleRegionIndex", "er['codeNumber','origin']", "/ExampleRegion er");
@@ -98,4 +106,31 @@ public class CompactRangeIndexQueryIntegrationTest {
     SelectResults rs = (SelectResults) q.execute();
     assertEquals(4, rs.size());
   }
+
+  @Test
+  public void getSizeEstimateShouldNotThrowClassCastException()
+      throws Exception {
+    String regionName = "portfolio";
+
+    Cache cache = serverStarterRule.getCache();
+    assertNotNull(cache);
+    Region region = cache.createRegionFactory().setDataPolicy(DataPolicy.REPLICATE).create(regionName);
+
+    Portfolio p = new Portfolio(1, 2);
+    region.put(1, p);
+
+    Portfolio p2 = new Portfolio(3, 4);
+    region.put(2, p2);
+
+    QueryService queryService = cache.getQueryService();
+    CompactRangeIndex statusIndex = (CompactRangeIndex)queryService.createIndex("statusIndex",
"status", "/portfolio");
+    CompactRangeIndex idIndex = (CompactRangeIndex)queryService.createIndex("idIndex", "ID",
"/portfolio");
+
+    SelectResults results = (SelectResults) queryService
+        .newQuery(
+            "select * from /portfolio where status = 4 AND ID = 'StringID'")
+        .execute();
+
+    assertNotNull(results);
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <commits@geode.apache.org>.

Mime
View raw message