You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bo...@apache.org on 2016/12/19 20:15:49 UTC

geode git commit: GEODE-2224: Local QueryService no longer throws exception in transaction

Repository: geode
Updated Branches:
  refs/heads/develop b68e5845a -> cf0694499


GEODE-2224: Local QueryService no longer throws exception in transaction


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

Branch: refs/heads/develop
Commit: cf069449938bad72f951384abad4c1fc41e2781d
Parents: b68e584
Author: Barry Oglesby <bo...@pivotal.io>
Authored: Fri Dec 16 15:43:18 2016 -0800
Committer: Barry Oglesby <bo...@pivotal.io>
Committed: Mon Dec 19 12:12:18 2016 -0800

----------------------------------------------------------------------
 .../cache/query/internal/DefaultQuery.java      |  9 +-
 .../cache/query/LocalQueryServiceJUnitTest.java | 97 ++++++++++++++++++++
 2 files changed, 99 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/cf069449/geode-core/src/main/java/org/apache/geode/cache/query/internal/DefaultQuery.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/DefaultQuery.java b/geode-core/src/main/java/org/apache/geode/cache/query/internal/DefaultQuery.java
index 068f1d1..8bfd4fa 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/DefaultQuery.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/DefaultQuery.java
@@ -560,10 +560,7 @@ public class DefaultQuery implements Query {
       TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
     QueryObserver observer = QueryObserverHolder.getInstance();
     long startTime = CachePerfStats.getStatTime();
-    TXStateProxy tx = null;
-    if (!((GemFireCacheImpl) this.cache).isClient()) { // fixes bug 42294
-      tx = ((TXManagerImpl) this.cache.getCacheTransactionManager()).internalSuspend();
-    }
+    TXStateProxy tx = ((TXManagerImpl) this.cache.getCacheTransactionManager()).internalSuspend();
     try {
       observer.startQuery(this);
       observer.beforeQueryEvaluation(compiledQuery, context);
@@ -602,9 +599,7 @@ public class DefaultQuery implements Query {
       updateStatistics(endTime - startTime);
       pdxClassToFieldsMap.remove();
       pdxClassToMethodsMap.remove();
-      if (tx != null) {
-        ((TXManagerImpl) this.cache.getCacheTransactionManager()).resume(tx);
-      }
+      ((TXManagerImpl) this.cache.getCacheTransactionManager()).resume(tx);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/cf069449/geode-core/src/test/java/org/apache/geode/cache/query/LocalQueryServiceJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/LocalQueryServiceJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/LocalQueryServiceJUnitTest.java
new file mode 100644
index 0000000..edd3f05
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/LocalQueryServiceJUnitTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.cache.query;
+
+import org.apache.geode.cache.CacheTransactionManager;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+@Category(UnitTest.class)
+public class LocalQueryServiceJUnitTest {
+
+  @Test
+  public void testLocalQueryService() throws Exception {
+    ClientCache c = null;
+    try {
+      c = new ClientCacheFactory().create();
+      addExpectedException(c, IOException.class.getName());
+      Region r = createRegion(c);
+      int numEntries = 10;
+      loadRegion(r, numEntries);
+      SelectResults sR = executeLocalQuery(c, "SELECT * from /localRegion");
+      assertEquals(numEntries, sR.size());
+    } finally {
+      if (c != null) {
+        c.close();
+      }
+    }
+  }
+
+  @Test
+  public void testLocalQueryServiceWithTransaction() throws Exception {
+    ClientCache c = null;
+    try {
+      c = new ClientCacheFactory().create();
+      addExpectedException(c, IOException.class.getName());
+      Region r = createRegion(c);
+      int numEntries = 10;
+      loadRegion(r, numEntries);
+      CacheTransactionManager cacheTransactionManager = c.getCacheTransactionManager();
+      cacheTransactionManager.begin();
+      SelectResults sR = executeLocalQuery(c, "SELECT * from /localRegion");
+      assertEquals(numEntries, sR.size());
+      cacheTransactionManager.commit();
+    } finally {
+      if (c != null) {
+        c.close();
+      }
+    }
+  }
+
+  private Region createRegion(ClientCache c) {
+    ClientRegionFactory factory = c.createClientRegionFactory(ClientRegionShortcut.LOCAL);
+    return factory.create("localRegion");
+  }
+
+  private void loadRegion(Region r, int numEntries) {
+    for (int i = 0; i < numEntries; i++) {
+      r.put(i, i);
+    }
+  }
+
+  private SelectResults executeLocalQuery(ClientCache c, String qS) throws QueryException {
+    QueryService qs = c.getLocalQueryService();
+    Query q = qs.newQuery("SELECT * from /localRegion");
+    return (SelectResults) q.execute();
+  }
+
+  private void addExpectedException(ClientCache c, String exception) {
+    c.getLogger().info("<ExpectedException action=add>" + exception + "</ExpectedException>");
+  }
+
+  private void removeExpectedException(ClientCache c, String exception) {
+    c.getLogger().info("<ExpectedException action=remove>" + exception + "</ExpectedException>");
+  }
+}