You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by nn...@apache.org on 2018/06/01 18:14:15 UTC

[geode] branch develop updated: GEODE-5272: CacheClosedException not wrapped in TypeMismatchException (#2009)

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 e628df4  GEODE-5272: CacheClosedException not wrapped in TypeMismatchException (#2009)
e628df4 is described below

commit e628df40588fab25fe75e6308232b2ab8ae84767
Author: Nabarun Nag <na...@users.noreply.github.com>
AuthorDate: Fri Jun 1 11:14:05 2018 -0700

    GEODE-5272: CacheClosedException not wrapped in TypeMismatchException (#2009)
    
    Co-authored-by: bijukunjummen <bi...@gmail.com>
---
 .../cache/query/internal/CompiledIteratorDef.java  | 47 +++++++++++--------
 .../internal/CompiledIteratorDefJUnitTest.java     | 52 ++++++++++++++++++++++
 2 files changed, 80 insertions(+), 19 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledIteratorDef.java b/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledIteratorDef.java
index 4dfa7ef..c13db20 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledIteratorDef.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledIteratorDef.java
@@ -24,6 +24,7 @@ import java.util.Set;
 
 import org.apache.logging.log4j.Logger;
 
+import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.query.AmbiguousNameException;
 import org.apache.geode.cache.query.FunctionDomainException;
@@ -113,31 +114,39 @@ public class CompiledIteratorDef extends AbstractCompiledValue {
         && !this.isDependentOnAnyIteratorOfScopeLessThanItsOwn(context)) {
       // The current Iterator definition is independent , so lets evaluate
       // the collection
-      try {
-        rIter.evaluateCollection(context);
-      } catch (QueryExecutionTimeoutException qet) {
-        throw qet;
-      } catch (RegionNotFoundException re) {
-        throw re;
-      } catch (NotAuthorizedException e) {
-        throw e;
-      } catch (QueryExecutionCanceledException e) {
-        throw e;
-      } catch (Exception e) {
-        if (logger.isDebugEnabled()) {
-          logger.debug("Exception while getting runtime iterator.", e);
-        }
-        throw new TypeMismatchException(
-            LocalizedStrings.CompiledIteratorDef_EXCEPTION_IN_EVALUATING_THE_COLLECTION_EXPRESSION_IN_GETRUNTIMEITERATOR_EVEN_THOUGH_THE_COLLECTION_IS_INDEPENDENT_OF_ANY_RUNTIMEITERATOR
-                .toLocalizedString(),
-            e);
-      }
+      evaluateCollectionForIndependentIterator(context, rIter);
     }
     // cache in context
     context.cachePut(this, rIter);
     return rIter;
   }
 
+  protected void evaluateCollectionForIndependentIterator(ExecutionContext context,
+      RuntimeIterator rIter)
+      throws RegionNotFoundException, TypeMismatchException {
+    try {
+      rIter.evaluateCollection(context);
+    } catch (QueryExecutionTimeoutException qet) {
+      throw qet;
+    } catch (RegionNotFoundException re) {
+      throw re;
+    } catch (NotAuthorizedException e) {
+      throw e;
+    } catch (QueryExecutionCanceledException e) {
+      throw e;
+    } catch (CacheClosedException e) {
+      throw e;
+    } catch (Exception e) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("Exception while getting runtime iterator.", e);
+      }
+      throw new TypeMismatchException(
+          LocalizedStrings.CompiledIteratorDef_EXCEPTION_IN_EVALUATING_THE_COLLECTION_EXPRESSION_IN_GETRUNTIMEITERATOR_EVEN_THOUGH_THE_COLLECTION_IS_INDEPENDENT_OF_ANY_RUNTIMEITERATOR
+              .toLocalizedString(),
+          e);
+    }
+  }
+
   ObjectType getCollectionElementTypeCast() throws TypeMismatchException {
     ObjectType typ = this.collectionExpr.getTypecast();
     if (typ != null) {
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/internal/CompiledIteratorDefJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/internal/CompiledIteratorDefJUnitTest.java
new file mode 100644
index 0000000..25e4bc3
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/internal/CompiledIteratorDefJUnitTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.internal;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.query.internal.types.TypeUtils;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class CompiledIteratorDefJUnitTest {
+
+  @Test
+  public void cacheClosedWhileEvaluateCollectionShouldNotThrowTypeMismatchException()
+      throws Exception {
+    CompiledValue compiledValue = mock(CompiledValue.class);
+    CompiledIteratorDef compiledIteratorDef =
+        new CompiledIteratorDef("TestIterator", TypeUtils.OBJECT_TYPE, compiledValue);
+    ExecutionContext executionContext = mock(ExecutionContext.class);
+    RuntimeIterator runtimeIterator = mock(RuntimeIterator.class);
+
+    when(runtimeIterator.evaluateCollection(executionContext))
+        .thenThrow(CacheClosedException.class);
+
+    try {
+      compiledIteratorDef.evaluateCollectionForIndependentIterator(executionContext,
+          runtimeIterator);
+      fail();
+    } catch (Exception e) {
+      assertTrue(e instanceof CacheClosedException);
+    }
+  }
+}

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