geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcmellaw...@apache.org
Subject [geode] 02/02: GEODE-5884: Adding to function exception list if cause is FunctionInvocationTargetException (#2809)
Date Fri, 16 Nov 2018 00:56:18 GMT
This is an automated email from the ASF dual-hosted git repository.

mcmellawatt pushed a commit to branch release/1.8.0
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 35f7a43a2ed822d7cdb0fc6536726e76be519106
Author: Jason Huynh <huynhja@gmail.com>
AuthorDate: Thu Nov 8 15:18:19 2018 -0800

    GEODE-5884: Adding to function exception list if cause is FunctionInvocationTargetException
(#2809)
---
 .../client/internal/ExecuteRegionFunctionOp.java   | 31 +++++++++--
 .../internal/ExecuteRegionFunctionOpTest.java      | 63 ++++++++++++++++++++++
 2 files changed, 89 insertions(+), 5 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/cache/client/internal/ExecuteRegionFunctionOp.java
b/geode-core/src/main/java/org/apache/geode/cache/client/internal/ExecuteRegionFunctionOp.java
index 3dbf079..5f4f41f 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/client/internal/ExecuteRegionFunctionOp.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/client/internal/ExecuteRegionFunctionOp.java
@@ -335,6 +335,7 @@ public class ExecuteRegionFunctionOp {
 
     private FunctionException functionException;
 
+
     public ExecuteRegionFunctionOpImpl(String region, Function function,
         ServerRegionFunctionExecutor serverRegionExecutor, ResultCollector rc, byte hasResult,
         Set<String> removedNodes) {
@@ -378,6 +379,22 @@ public class ExecuteRegionFunctionOp {
       this.isHA = function.isHA();
     }
 
+    // For testing only
+    ExecuteRegionFunctionOpImpl() {
+      super(MessageType.EXECUTE_REGION_FUNCTION,
+          0);
+      resultCollector = null;
+      function = null;
+      isReExecute = (byte) 0;
+      regionName = "";
+      executor = null;
+      hasResult = (byte) 0;
+      failedNodes = null;
+      functionId = null;
+      executeOnBucketSet = true;
+      isHA = true;
+    }
+
     public ExecuteRegionFunctionOpImpl(String region, String function,
         ServerRegionFunctionExecutor serverRegionExecutor, ResultCollector rc, byte hasResult,
         Set<String> removedNodes, boolean isHA, boolean optimizeForWrite,
@@ -640,13 +657,13 @@ public class ExecuteRegionFunctionOp {
       return null;
     }
 
-    private void addFunctionException(final FunctionException result) {
-      if (result instanceof FunctionInvocationTargetException) {
+    void addFunctionException(final FunctionException result) {
+      if (result.getCause() instanceof FunctionInvocationTargetException) {
         if (this.functionException == null) {
-          this.functionException = new FunctionException(result);
+          this.functionException = result;
         }
-        this.functionException.addException(result);
-      } else if (result instanceof InternalFunctionInvocationTargetException) {
+        this.functionException.addException(result.getCause());
+      } else if (result instanceof FunctionInvocationTargetException) {
         if (this.functionException == null) {
           this.functionException = new FunctionException(result);
         }
@@ -659,6 +676,10 @@ public class ExecuteRegionFunctionOp {
       }
     }
 
+    FunctionException getFunctionException() {
+      return functionException;
+    }
+
     @Override
     protected boolean isErrorResponse(int msgType) {
       return msgType == MessageType.EXECUTE_REGION_FUNCTION_ERROR;
diff --git a/geode-core/src/test/java/org/apache/geode/cache/client/internal/ExecuteRegionFunctionOpTest.java
b/geode-core/src/test/java/org/apache/geode/cache/client/internal/ExecuteRegionFunctionOpTest.java
new file mode 100644
index 0000000..4629ce9
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/cache/client/internal/ExecuteRegionFunctionOpTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.client.internal;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.execute.FunctionException;
+import org.apache.geode.cache.execute.FunctionInvocationTargetException;
+import org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException;
+import org.apache.geode.test.junit.categories.ClientServerTest;
+
+@Category({ClientServerTest.class})
+public class ExecuteRegionFunctionOpTest {
+
+  @Test
+  public void addFunctionExceptionWithFunctionTargetInvocationExceptionWrapsInPlainFunctionException()
{
+    FunctionInvocationTargetException exception = mock(FunctionInvocationTargetException.class);
+    ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl op =
+        new ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl();
+    op.addFunctionException(exception);
+    assertThat(op.getFunctionException()).isInstanceOf(FunctionException.class);
+    assertThat(op.getFunctionException()).isNotInstanceOf(FunctionInvocationTargetException.class);
+  }
+
+  @Test
+  public void addFunctionExceptionWithInternalFunctionTargetInvocationExceptionWrapsInPlainFunctionException()
{
+    FunctionInvocationTargetException exception =
+        mock(InternalFunctionInvocationTargetException.class);
+    ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl op =
+        new ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl();
+    op.addFunctionException(exception);
+    assertThat(op.getFunctionException()).isInstanceOf(FunctionException.class);
+    assertThat(op.getFunctionException())
+        .isNotInstanceOf(InternalFunctionInvocationTargetException.class);
+  }
+
+  @Test
+  public void addFunctionExceptionWithCauseFunctionTargetInvocationExceptionAddsToListOfException()
{
+    FunctionInvocationTargetException cause = mock(FunctionInvocationTargetException.class);
+    FunctionException exception = new FunctionException(cause);
+    ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl op =
+        new ExecuteRegionFunctionOp.ExecuteRegionFunctionOpImpl();
+    op.addFunctionException(exception);
+    assertThat(op.getFunctionException()).isInstanceOf(FunctionException.class);
+    assertThat(op.getFunctionException().getExceptions()).contains(cause);
+  }
+}


Mime
View raw message