You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ja...@apache.org on 2018/10/31 04:46:09 UTC
[geode] 01/03: GEODE-5884: Non HA Function waits for all results if
exception occurs
This is an automated email from the ASF dual-hosted git repository.
jasonhuynh pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
commit 913cec14fd9918918a8f0ada451344fd990e7586
Author: Jason Huynh <hu...@gmail.com>
AuthorDate: Tue Oct 16 14:23:40 2018 -0700
GEODE-5884: Non HA Function waits for all results if exception occurs
* Non HA functions will attempt to return as many results as possible when an exception occurs
* This behavior will be more in-line with single-hop execution
---
...istributedRegionFunctionExecutionDUnitTest.java | 2 +-
...ientServerRegionFunctionExecutionDUnitTest.java | 2 +-
.../sockets/command/ExecuteRegionFunction66.java | 46 +++++----
.../command/ExecuteRegionFunction66Test.java | 113 +++++++++++++++++++++
4 files changed, 143 insertions(+), 20 deletions(-)
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/DistributedRegionFunctionExecutionDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/DistributedRegionFunctionExecutionDUnitTest.java
index 0301ba8..78d62d9 100755
--- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/DistributedRegionFunctionExecutionDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/DistributedRegionFunctionExecutionDUnitTest.java
@@ -1173,7 +1173,7 @@ public class DistributedRegionFunctionExecutionDUnitTest extends JUnit4Distribut
fail("Function Invocation Target Exception should be thrown");
} catch (Exception e) {
e.printStackTrace();
- if (!(e.getCause() instanceof FunctionInvocationTargetException)) {
+ if (!((e instanceof FunctionInvocationTargetException) || (e.getCause() instanceof FunctionInvocationTargetException))) {
fail("FunctionInvocationTargetException should be thrown");
}
}
diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/PRClientServerRegionFunctionExecutionDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/PRClientServerRegionFunctionExecutionDUnitTest.java
index 07564ec..c1f0bfe 100755
--- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/PRClientServerRegionFunctionExecutionDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/PRClientServerRegionFunctionExecutionDUnitTest.java
@@ -477,7 +477,7 @@ public class PRClientServerRegionFunctionExecutionDUnitTest extends PRClientServ
fail("Expected ServerConnectivityException not thrown!");
} catch (Exception ex) {
if (!(ex.getCause() instanceof ServerConnectivityException)
- && !(ex.getCause() instanceof FunctionInvocationTargetException)) {
+ && !((ex instanceof FunctionInvocationTargetException || ex.getCause() instanceof FunctionInvocationTargetException))) {
throw ex;
}
}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteRegionFunction66.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteRegionFunction66.java
index 3a0c018..e953f00 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteRegionFunction66.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteRegionFunction66.java
@@ -246,24 +246,7 @@ public class ExecuteRegionFunction66 extends BaseCommand {
hasResult);
}
if (hasResult == 1) {
- if (function instanceof String) {
- switch (functionState) {
- case AbstractExecution.NO_HA_HASRESULT_NO_OPTIMIZEFORWRITE:
- execution.execute((String) function).getResult();
- break;
- case AbstractExecution.HA_HASRESULT_NO_OPTIMIZEFORWRITE:
- execution.execute((String) function).getResult();
- break;
- case AbstractExecution.HA_HASRESULT_OPTIMIZEFORWRITE:
- execution.execute((String) function).getResult();
- break;
- case AbstractExecution.NO_HA_HASRESULT_OPTIMIZEFORWRITE:
- execution.execute((String) function).getResult();
- break;
- }
- } else {
- execution.execute(functionObject).getResult();
- }
+ executeFunctionWithResult(function, functionState, functionObject, execution);
} else {
if (function instanceof String) {
switch (functionState) {
@@ -339,6 +322,33 @@ public class ExecuteRegionFunction66 extends BaseCommand {
}
}
+ void executeFunctionWithResult(Object function, byte functionState,
+ Function<?> functionObject, AbstractExecution execution) {
+ if (function instanceof String) {
+ switch (functionState) {
+ case AbstractExecution.NO_HA_HASRESULT_NO_OPTIMIZEFORWRITE:
+ execution.setWaitOnExceptionFlag(true);
+ execution.execute((String) function).getResult();
+ break;
+ case AbstractExecution.HA_HASRESULT_NO_OPTIMIZEFORWRITE:
+ execution.execute((String) function).getResult();
+ break;
+ case AbstractExecution.HA_HASRESULT_OPTIMIZEFORWRITE:
+ execution.execute((String) function).getResult();
+ break;
+ case AbstractExecution.NO_HA_HASRESULT_OPTIMIZEFORWRITE:
+ execution.setWaitOnExceptionFlag(true);
+ execution.execute((String) function).getResult();
+ break;
+ }
+ } else {
+ if (!functionObject.isHA()) {
+ execution.setWaitOnExceptionFlag(true);
+ }
+ execution.execute(functionObject).getResult();
+ }
+ }
+
private void sendException(byte hasResult, Message msg, String message,
ServerConnection serverConnection, Throwable e) throws IOException {
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteRegionFunction66Test.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteRegionFunction66Test.java
new file mode 100644
index 0000000..b77a879
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/command/ExecuteRegionFunction66Test.java
@@ -0,0 +1,113 @@
+/*
+ * 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.internal.cache.tier.sockets.command;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import org.apache.geode.CancelCriterion;
+import org.apache.geode.cache.execute.Execution;
+import org.apache.geode.cache.execute.Function;
+import org.apache.geode.cache.execute.FunctionService;
+import org.apache.geode.cache.execute.ResultCollector;
+import org.apache.geode.cache.operations.ExecuteFunctionOperationContext;
+import org.apache.geode.cache.query.internal.ExecutionContext;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.internal.Version;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.LocalRegion;
+import org.apache.geode.internal.cache.control.HeapMemoryMonitor;
+import org.apache.geode.internal.cache.control.InternalResourceManager;
+import org.apache.geode.internal.cache.execute.AbstractExecution;
+import org.apache.geode.internal.cache.tier.CachedRegionHelper;
+import org.apache.geode.internal.cache.tier.ServerSideHandshake;
+import org.apache.geode.internal.cache.tier.sockets.AcceptorImpl;
+import org.apache.geode.internal.cache.tier.sockets.ChunkedMessage;
+import org.apache.geode.internal.cache.tier.sockets.Message;
+import org.apache.geode.internal.cache.tier.sockets.Part;
+import org.apache.geode.internal.cache.tier.sockets.ServerConnection;
+import org.apache.geode.internal.security.AuthorizeRequest;
+import org.apache.geode.internal.security.SecurityService;
+import org.apache.geode.management.internal.security.ResourcePermissions;
+import org.apache.geode.security.NotAuthorizedException;
+import org.apache.geode.test.junit.categories.ClientServerTest;
+
+@Category({ClientServerTest.class})
+public class ExecuteRegionFunction66Test {
+ private static final String FUNCTION_ID = "function_id";
+
+ @Mock
+ private Function functionObject;
+
+ private ExecuteRegionFunction66 executeRegionFunction66;
+
+ @Rule
+ public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+ @Before
+ public void setUp() throws Exception {
+ this.executeRegionFunction66 = (ExecuteRegionFunction66) ExecuteRegionFunction66.getCommand();
+
+ this.functionObject = mock(Function.class);
+ when(this.functionObject.getId()).thenReturn(FUNCTION_ID);
+ doCallRealMethod().when(this.functionObject).getRequiredPermissions(any());
+ }
+
+ @Test
+ public void executingFunctionByStringWithNoHAShouldSetWaitOnException() throws Exception {
+ AbstractExecution execution = mock(AbstractExecution.class);
+ String functionName = "functionName";
+ when (execution.execute(functionName)).thenReturn(mock(ResultCollector.class));
+ this.executeRegionFunction66.executeFunctionWithResult(functionName, AbstractExecution.NO_HA_HASRESULT_NO_OPTIMIZEFORWRITE, functionObject, execution);
+ verify(execution, times(1)).setWaitOnExceptionFlag(true);
+ }
+
+ @Test
+ public void executingFunctionByStringWithNoHAWithOptimizeForWriteShouldSetWaitOnException() throws Exception {
+ AbstractExecution execution = mock(AbstractExecution.class);
+ String functionName = "functionName";
+ when (execution.execute(functionName)).thenReturn(mock(ResultCollector.class));
+ this.executeRegionFunction66.executeFunctionWithResult(functionName, AbstractExecution.NO_HA_HASRESULT_OPTIMIZEFORWRITE, functionObject, execution);
+ verify(execution, times(1)).setWaitOnExceptionFlag(true);
+ }
+
+ @Test
+ public void executeFunctionObjectShouldSetWaitOnException() throws Exception {
+ AbstractExecution execution = mock(AbstractExecution.class);
+ when (execution.execute(functionObject)).thenReturn(mock(ResultCollector.class));
+ this.executeRegionFunction66.executeFunctionWithResult(functionObject, AbstractExecution.NO_HA_HASRESULT_OPTIMIZEFORWRITE, functionObject, execution);
+ verify(execution, times(1)).setWaitOnExceptionFlag(true);
+ }
+
+
+
+}