You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2022/05/19 17:21:42 UTC

[GitHub] [geode] mhansonp commented on a diff in pull request #7690: GEODE-10310: Add disable reatempt on CacheClose

mhansonp commented on code in PR #7690:
URL: https://github.com/apache/geode/pull/7690#discussion_r877328839


##########
geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/PartitionedRegionCacheCloseNoRetryDistributedTest.java:
##########
@@ -0,0 +1,288 @@
+/*
+ * 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.partitioned;
+
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.geode.cache.RegionShortcut.PARTITION_PERSISTENT;
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+import static org.apache.geode.test.dunit.VM.getVM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.InternalGemFireException;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.execute.Function;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.distributed.internal.DistributionMessageObserver;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.control.InternalResourceManager;
+import org.apache.geode.test.awaitility.GeodeAwaitility;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.rules.CacheRule;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+import org.apache.geode.util.internal.GeodeGlossary;
+
+public class PartitionedRegionCacheCloseNoRetryDistributedTest implements Serializable {
+
+  private String partitionedRegionName;
+
+  private VM vm0;
+  private VM vm1;
+  private VM vm2;
+  private VM vm3;
+
+  private static final long TIMEOUT_MILLIS = GeodeAwaitility.getTimeout().toMillis();
+
+  @Rule
+  public CacheRule cacheRule =
+      CacheRule.builder().addConfig(getDistributedSystemProperties()).build();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+
+  @Before
+  public void setUp() {
+    vm0 = getVM(0);
+    vm1 = getVM(1);
+    vm2 = getVM(2);
+    vm3 = getVM(3);
+
+    invokeInEveryVM(() -> {
+      System.setProperty(
+          GeodeGlossary.GEMFIRE_PREFIX + "PartitionMessage.DISABLE_REATTEMPT_ON_CACHE_CLOSE",
+          "true");
+    });
+    String uniqueName = getClass().getSimpleName() + "-" + testName.getMethodName();
+    partitionedRegionName = uniqueName + "-partitionedRegion";
+  }
+
+  @After
+  public void tearDown() {
+    invokeInEveryVM(() -> {
+      System.clearProperty(
+          GeodeGlossary.GEMFIRE_PREFIX + "PartitionMessage.DISABLE_REATTEMPT_ON_CACHE_CLOSE");
+      InternalResourceManager.setResourceObserver(null);
+      DistributionMessageObserver.setInstance(null);
+    });
+  }
+
+  private Properties getDistributedSystemProperties() {
+    Properties config = new Properties();
+    config.setProperty(SERIALIZABLE_OBJECT_FILTER, TestFunction.class.getName());
+    return config;
+  }
+
+
+  @Test
+  public void testCacheCloseDuringWrite()
+      throws InterruptedException {
+    int redundantCopies = 1;
+    int recoveryDelay = -1;
+    int numBuckets = 100;
+    boolean diskSynchronous = true;
+
+    vm0.invoke(() -> {
+      createPartitionedRegion(redundantCopies, recoveryDelay, numBuckets, diskSynchronous);
+      createData(0, numBuckets, "a");
+    });
+
+    vm1.invoke(() -> {
+      createPartitionedRegion(redundantCopies, recoveryDelay, numBuckets, diskSynchronous);
+    });
+
+    // Need to invoke this async because vm1 will wait for vm0 to come back online
+    // unless we explicitly revoke it.
+
+    int endData = 10000;
+
+    AsyncInvocation<Object> createRegionDataAsync = vm0.invokeAsync(
+        () -> {
+          Exception exc = null;
+          try {
+            createData(numBuckets, endData, "b");
+          } catch (Exception e) {
+            exc = e;
+          }
+
+          assertThat(exc).isNotNull();
+          assertThat(exc).isInstanceOf(InternalGemFireException.class);
+
+        });
+
+    AsyncInvocation<Object> closeCacheAsync = vm1.invokeAsync(
+        () -> {
+          getCache().close();
+        });
+
+    closeCacheAsync.get();
+    createRegionDataAsync.get();
+
+  }
+
+
+  @Test
+  public void testCacheCloseDuringInvalidate()
+      throws InterruptedException {
+    int redundantCopies = 1;
+    int recoveryDelay = -1;
+    int numBuckets = 100;
+    boolean diskSynchronous = true;
+    int endData = 10000;
+
+    vm0.invoke(() -> {
+      createPartitionedRegion(redundantCopies, recoveryDelay, numBuckets, diskSynchronous);
+      createData(0, endData, "a");
+    });
+
+    vm1.invoke(() -> {
+      createPartitionedRegion(redundantCopies, recoveryDelay, numBuckets, diskSynchronous);
+    });
+
+    // Need to invoke this async because vm1 will wait for vm0 to come back online
+    // unless we explicitly revoke it.
+
+    AsyncInvocation<Object> invalidateRegionDataAsync = vm0.invokeAsync(
+        () -> {
+          Exception exc = null;
+          try {
+            invalidateData(0, endData);
+          } catch (Exception e) {
+            exc = e;
+          }
+
+          assertThat(exc).isNotNull();
+          assertThat(exc).isInstanceOf(InternalGemFireException.class);
+
+        });
+
+    AsyncInvocation<Object> closeCacheAsync = vm1.invokeAsync(

Review Comment:
   Same as above



##########
geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/PartitionedRegionCacheCloseNoRetryDistributedTest.java:
##########
@@ -0,0 +1,288 @@
+/*
+ * 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.partitioned;
+
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.geode.cache.RegionShortcut.PARTITION_PERSISTENT;
+import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
+import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+import static org.apache.geode.test.dunit.VM.getVM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.geode.InternalGemFireException;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.execute.Function;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.distributed.internal.DistributionMessageObserver;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.control.InternalResourceManager;
+import org.apache.geode.test.awaitility.GeodeAwaitility;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.rules.CacheRule;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+import org.apache.geode.util.internal.GeodeGlossary;
+
+public class PartitionedRegionCacheCloseNoRetryDistributedTest implements Serializable {
+
+  private String partitionedRegionName;
+
+  private VM vm0;
+  private VM vm1;
+  private VM vm2;
+  private VM vm3;
+
+  private static final long TIMEOUT_MILLIS = GeodeAwaitility.getTimeout().toMillis();
+
+  @Rule
+  public CacheRule cacheRule =
+      CacheRule.builder().addConfig(getDistributedSystemProperties()).build();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+
+  @Before
+  public void setUp() {
+    vm0 = getVM(0);
+    vm1 = getVM(1);
+    vm2 = getVM(2);
+    vm3 = getVM(3);
+
+    invokeInEveryVM(() -> {
+      System.setProperty(
+          GeodeGlossary.GEMFIRE_PREFIX + "PartitionMessage.DISABLE_REATTEMPT_ON_CACHE_CLOSE",
+          "true");
+    });
+    String uniqueName = getClass().getSimpleName() + "-" + testName.getMethodName();
+    partitionedRegionName = uniqueName + "-partitionedRegion";
+  }
+
+  @After
+  public void tearDown() {
+    invokeInEveryVM(() -> {
+      System.clearProperty(
+          GeodeGlossary.GEMFIRE_PREFIX + "PartitionMessage.DISABLE_REATTEMPT_ON_CACHE_CLOSE");
+      InternalResourceManager.setResourceObserver(null);
+      DistributionMessageObserver.setInstance(null);
+    });
+  }
+
+  private Properties getDistributedSystemProperties() {
+    Properties config = new Properties();
+    config.setProperty(SERIALIZABLE_OBJECT_FILTER, TestFunction.class.getName());
+    return config;
+  }
+
+
+  @Test
+  public void testCacheCloseDuringWrite()
+      throws InterruptedException {
+    int redundantCopies = 1;
+    int recoveryDelay = -1;
+    int numBuckets = 100;
+    boolean diskSynchronous = true;
+
+    vm0.invoke(() -> {
+      createPartitionedRegion(redundantCopies, recoveryDelay, numBuckets, diskSynchronous);
+      createData(0, numBuckets, "a");
+    });
+
+    vm1.invoke(() -> {
+      createPartitionedRegion(redundantCopies, recoveryDelay, numBuckets, diskSynchronous);
+    });
+
+    // Need to invoke this async because vm1 will wait for vm0 to come back online
+    // unless we explicitly revoke it.
+
+    int endData = 10000;
+
+    AsyncInvocation<Object> createRegionDataAsync = vm0.invokeAsync(
+        () -> {
+          Exception exc = null;
+          try {
+            createData(numBuckets, endData, "b");
+          } catch (Exception e) {
+            exc = e;
+          }
+
+          assertThat(exc).isNotNull();
+          assertThat(exc).isInstanceOf(InternalGemFireException.class);
+
+        });
+
+    AsyncInvocation<Object> closeCacheAsync = vm1.invokeAsync(
+        () -> {
+          getCache().close();
+        });
+
+    closeCacheAsync.get();
+    createRegionDataAsync.get();
+
+  }
+
+
+  @Test
+  public void testCacheCloseDuringInvalidate()
+      throws InterruptedException {
+    int redundantCopies = 1;
+    int recoveryDelay = -1;
+    int numBuckets = 100;
+    boolean diskSynchronous = true;
+    int endData = 10000;
+
+    vm0.invoke(() -> {
+      createPartitionedRegion(redundantCopies, recoveryDelay, numBuckets, diskSynchronous);
+      createData(0, endData, "a");
+    });
+
+    vm1.invoke(() -> {
+      createPartitionedRegion(redundantCopies, recoveryDelay, numBuckets, diskSynchronous);
+    });
+
+    // Need to invoke this async because vm1 will wait for vm0 to come back online
+    // unless we explicitly revoke it.
+
+    AsyncInvocation<Object> invalidateRegionDataAsync = vm0.invokeAsync(

Review Comment:
   This would probably be better as AsyncInvocation<Void>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org