geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject [geode] branch develop updated: GEODE-5290: Fixes NPE with ResultsCollectionPdxDeserializerWrapper iterator (#2027)
Date Wed, 06 Jun 2018 00:27:14 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/develop by this push:
     new 44643a8  GEODE-5290: Fixes NPE with ResultsCollectionPdxDeserializerWrapper iterator
(#2027)
44643a8 is described below

commit 44643a86a3b2cc254703e6fc460fa09fdf790e8a
Author: Biju Kunjummen <biju.kunjummen@gmail.com>
AuthorDate: Tue Jun 5 17:26:37 2018 -0700

    GEODE-5290: Fixes NPE with ResultsCollectionPdxDeserializerWrapper iterator (#2027)
    
    Co-authored-by: gesterzhou <gzhou@pivotal.io>
    Co-authored-by: nabarunnag <nag@cs.wisc.edu>
---
 .../ResultsCollectionPdxDeserializerWrapper.java   |  4 ++
 .../geode/cache/query/PdxStringQueryJUnitTest.java | 14 ++++++
 .../geode/cache/query/dunit/PdxQueryDUnitTest.java | 51 ++++++++++++++++++++++
 3 files changed, 69 insertions(+)

diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/ResultsCollectionPdxDeserializerWrapper.java
b/geode-core/src/main/java/org/apache/geode/cache/query/internal/ResultsCollectionPdxDeserializerWrapper.java
index 321d762..2309251 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/ResultsCollectionPdxDeserializerWrapper.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/ResultsCollectionPdxDeserializerWrapper.java
@@ -16,6 +16,7 @@ package org.apache.geode.cache.query.internal;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -45,6 +46,9 @@ public class ResultsCollectionPdxDeserializerWrapper implements SelectResults
{
 
   @Override
   public Iterator iterator() {
+    if (results == null) {
+      return new SelectResultsPdxInstanceIterator(Collections.emptyIterator());
+    }
     return new SelectResultsPdxInstanceIterator(results.iterator());
   }
 
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/PdxStringQueryJUnitTest.java
b/geode-core/src/test/java/org/apache/geode/cache/query/PdxStringQueryJUnitTest.java
index ee44fbb..9c9619c 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/query/PdxStringQueryJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/PdxStringQueryJUnitTest.java
@@ -16,6 +16,7 @@ package org.apache.geode.cache.query;
 
 import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -34,6 +35,8 @@ import org.junit.experimental.categories.Category;
 import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.query.internal.QueryObserver;
+import org.apache.geode.cache.query.internal.ResultsCollectionPdxDeserializerWrapper;
+import org.apache.geode.cache.query.internal.ResultsSet;
 import org.apache.geode.cache.query.internal.index.CompactRangeIndex;
 import org.apache.geode.cache.query.internal.index.IndexStore.IndexStoreEntry;
 import org.apache.geode.cache.query.internal.index.PrimaryKeyIndex;
@@ -262,6 +265,17 @@ public class PdxStringQueryJUnitTest {
     region.clear();
   }
 
+  @Test
+  public void testPdxResultsCollector() {
+    SelectResults<Struct> sr1 = new ResultsCollectionPdxDeserializerWrapper();
+    assertNotNull(sr1.asList());
+
+    SelectResults<Struct> sr2 =
+        new ResultsCollectionPdxDeserializerWrapper(new ResultsSet(), false);
+    assertNotNull(sr2.asList());
+
+  }
+
   private void putPdxInstances() throws Exception {
     PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", false, this.cache);
     pf.writeInt("ID", 111);
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/dunit/PdxQueryDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/cache/query/dunit/PdxQueryDUnitTest.java
index c85fd0b..7f52083 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/query/dunit/PdxQueryDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/dunit/PdxQueryDUnitTest.java
@@ -3555,4 +3555,55 @@ public class PdxQueryDUnitTest extends PDXQueryTestBase {
     this.closeClient(vm1);
     this.closeClient(vm0);
   }
+
+  /**
+   * Test Aggregate queries on Pdx instances
+   */
+
+  @Test
+  public void testAggregateQueries() {
+    VM vm0 = VM.getVM(0);
+    VM vm1 = VM.getVM(1);
+    VM vm2 = VM.getVM(2);
+
+    final int port0 = vm0.invoke(() -> {
+      configAndStartBridgeServer();
+      Region region = getRootRegion().getSubregion(regionName);
+      for (int i = 0; i < 10; i++) {
+        region.put("key-" + i, new TestObject(i, "val-" + i));
+      }
+      return getCacheServerPort();
+    });
+
+    final int port1 = vm1.invoke(() -> {
+      configAndStartBridgeServer();
+      return getCacheServerPort();
+    });
+
+    final String host0 = NetworkUtils.getServerHostName();
+
+    final String poolName = "testClientServerQueryPool";
+    createPool(vm2, poolName, new String[] {host0}, new int[] {port1}, true);
+
+    vm2.invoke(() -> {
+      QueryService queryService = PoolManager.find(poolName).getQueryService();
+      Query query = queryService.newQuery("select SUM(price) from " + regName + " where id
> 0");
+      SelectResults<Object> selectResults = (SelectResults) query.execute();
+      assertEquals(1, selectResults.size());
+      assertEquals(45, selectResults.asList().get(0));
+    });
+
+    vm2.invoke(() -> {
+      QueryService queryService = PoolManager.find(poolName).getQueryService();
+      Query query = queryService.newQuery("select SUM(price) from " + regName + " where id
> 9");
+      SelectResults<Long> selectResults = (SelectResults) query.execute();
+      assertEquals(0, selectResults.size());
+      assertEquals(0, selectResults.asList().size());
+    });
+
+    this.closeClient(vm0);
+    this.closeClient(vm1);
+    this.closeClient(vm2);
+  }
+
 }

-- 
To stop receiving notification emails like this one, please contact
nnag@apache.org.

Mime
View raw message