geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [25/46] geode git commit: GEODE-2124: Queries that invoke StructSet addAll fail with ClassCastException
Date Mon, 12 Dec 2016 22:36:28 GMT
GEODE-2124: Queries that invoke StructSet addAll fail with ClassCastException

 * Fixed addAll method in StructSet to call the overridden add method


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

Branch: refs/heads/feature/GEODE-1930
Commit: 6e5013102927099a725282b6bad5d64a79152fab
Parents: bf2a038
Author: Jason Huynh <huynhja@gmail.com>
Authored: Fri Nov 18 11:32:53 2016 -0800
Committer: Jason Huynh <huynhja@gmail.com>
Committed: Mon Nov 21 10:03:52 2016 -0800

----------------------------------------------------------------------
 .../geode/cache/query/internal/StructSet.java   |  14 +-
 .../query/dunit/SelectStarQueryDUnitTest.java   | 135 +++++++++++++++++++
 2 files changed, 147 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/6e501310/geode-core/src/main/java/org/apache/geode/cache/query/internal/StructSet.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/StructSet.java
b/geode-core/src/main/java/org/apache/geode/cache/query/internal/StructSet.java
index 6d04c02..e89e123 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/StructSet.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/StructSet.java
@@ -240,15 +240,25 @@ public final class StructSet /* extends ObjectOpenCustomHashSet */ implements
Se
   public boolean addAll(Collection c) {
     if (c instanceof StructSet) {
       return addAll((StructSet) c);
+    } else {
+      boolean modified = false;
+      for (Object o : c) {
+        modified = add(o);
+      }
+      return modified;
     }
-    return this.contents.addAll(c);
   }
 
   public boolean removeAll(Collection c) {
     if (c instanceof StructSet) {
       return removeAll((StructSet) c);
+    } else {
+      boolean modified = false;
+      for (Object o : c) {
+        modified = remove(o);
+      }
+      return modified;
     }
-    return this.contents.removeAll(c);
   }
 
   public boolean retainAll(Collection c) {

http://git-wip-us.apache.org/repos/asf/geode/blob/6e501310/geode-core/src/test/java/org/apache/geode/cache/query/dunit/SelectStarQueryDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/dunit/SelectStarQueryDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/cache/query/dunit/SelectStarQueryDUnitTest.java
index 4596fdc..525aa2f 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/query/dunit/SelectStarQueryDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/dunit/SelectStarQueryDUnitTest.java
@@ -92,6 +92,141 @@ public class SelectStarQueryDUnitTest extends JUnit4CacheTestCase {
   }
 
   @Test
+  public void functionWithStructTypeInInnerQueryShouldNotThrowException() throws Exception
{
+    final Host host = Host.getHost(0);
+    final VM server1 = host.getVM(0);
+    final VM client = host.getVM(3);
+    PortfolioPdx[] portfolios = new PortfolioPdx[10];
+    for (int i = 0; i < portfolios.length; i++) {
+      portfolios[i] = new PortfolioPdx(i);
+    }
+
+    // create servers and regions
+    final int port1 = startPartitionedCacheServer(server1, portfolios);
+
+    // create client
+    client.invoke(new SerializableCallable("Create client") {
+      @Override
+      public Object call() throws Exception {
+        ClientCacheFactory cf = new ClientCacheFactory();
+        cf.addPoolServer(getServerHostName(server1.getHost()), port1);
+        ClientCache cache = getClientCache(cf);
+        cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regName);
+        return null;
+      }
+    });
+
+    // put serialized PortfolioPdx objects
+    client.invoke(new SerializableCallable("Put objects") {
+      @Override
+      public Object call() throws Exception {
+        Region r1 = getRootRegion(regName);
+        for (int i = 10; i < 100; i++) {
+          r1.put("key-" + i, new PortfolioPdx(i));
+        }
+        return null;
+      }
+    });
+
+    // query remotely from client
+    client.invoke(new SerializableCallable("Query") {
+      @Override
+      public Object call() throws Exception {
+        getLogWriter().info("Querying remotely from client");
+        QueryService remoteQS = null;
+        try {
+          remoteQS = ((ClientCache) getCache()).getQueryService();
+          SelectResults sr = (SelectResults) remoteQS
+              .newQuery("select distinct oP.ID, oP.status, oP.getType from /" + regName
+                  + " oP where element(select distinct p.ID, p.status, p.getType from /"
+ regName
+                  + " p where p.ID = oP.ID).status = 'inactive'")
+              .execute();
+          assertEquals(50, sr.size());
+        } catch (Exception e) {
+          fail("Exception getting query service ", e);
+        }
+
+        return null;
+      }
+    });
+
+    closeCache(client);
+    closeCache(server1);
+  }
+
+  @Test
+  public void functionWithStructTypeInInnerQueryShouldNotThrowExceptionWhenRunOnMultipleNodes()
+      throws Exception {
+    final Host host = Host.getHost(0);
+    final VM server1 = host.getVM(0);
+    final VM server2 = host.getVM(1);
+    final VM server3 = host.getVM(2);
+    final VM client = host.getVM(3);
+    PortfolioPdx[] portfolios = new PortfolioPdx[10];
+    for (int i = 0; i < portfolios.length; i++) {
+      portfolios[i] = new PortfolioPdx(i);
+    }
+
+    // create servers and regions
+    final int port1 = startPartitionedCacheServer(server1, portfolios);
+    final int port2 = startPartitionedCacheServer(server2, portfolios);
+    final int port3 = startPartitionedCacheServer(server3, portfolios);
+
+    // create client
+    client.invoke(new SerializableCallable("Create client") {
+      @Override
+      public Object call() throws Exception {
+        ClientCacheFactory cf = new ClientCacheFactory();
+        cf.addPoolServer(getServerHostName(server1.getHost()), port1);
+        cf.addPoolServer(getServerHostName(server2.getHost()), port2);
+        cf.addPoolServer(getServerHostName(server3.getHost()), port3);
+        ClientCache cache = getClientCache(cf);
+        cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regName);
+        return null;
+      }
+    });
+
+    // put serialized PortfolioPdx objects
+    client.invoke(new SerializableCallable("Put objects") {
+      @Override
+      public Object call() throws Exception {
+        Region r1 = getRootRegion(regName);
+        for (int i = 10; i < 100; i++) {
+          r1.put("key-" + i, new PortfolioPdx(i));
+        }
+        return null;
+      }
+    });
+
+    // query remotely from client
+    client.invoke(new SerializableCallable("Query") {
+      @Override
+      public Object call() throws Exception {
+        getLogWriter().info("Querying remotely from client");
+        QueryService remoteQS = null;
+        try {
+          remoteQS = ((ClientCache) getCache()).getQueryService();
+          SelectResults sr = (SelectResults) remoteQS
+              .newQuery("select distinct oP.ID, oP.status, oP.getType from /" + regName
+                  + " oP where element(select distinct p.ID, p.status, p.getType from /"
+ regName
+                  + " p where p.ID = oP.ID).status = 'inactive'")
+              .execute();
+          assertEquals(50, sr.size());
+        } catch (Exception e) {
+          fail("Exception getting query service ", e);
+        }
+        return null;
+      }
+    });
+
+
+    closeCache(client);
+    closeCache(server1);
+    closeCache(server2);
+    closeCache(server3);
+  }
+
+  @Test
   public void testSelectStarQueryForPartitionedRegion() throws Exception {
     final Host host = Host.getHost(0);
     final VM server1 = host.getVM(0);


Mime
View raw message