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 2021/06/10 16:12:16 UTC

[geode] branch support/1.13 updated: GEODE-9307: Removed MembershipListener after force disconnect (#6515)

This is an automated email from the ASF dual-hosted git repository.

nnag pushed a commit to branch support/1.13
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/support/1.13 by this push:
     new 1f0eda2  GEODE-9307: Removed MembershipListener after force disconnect (#6515)
1f0eda2 is described below

commit 1f0eda2768c1ad1f0feb2b418a84c2de931d9d89
Author: Barry Oglesby <bo...@users.noreply.github.com>
AuthorDate: Thu May 27 08:51:30 2021 -1000

    GEODE-9307: Removed MembershipListener after force disconnect (#6515)
    
    (cherry picked from commit 2bc4bd93a6c24ea32c3a44c502fcb20c0a255cb4)
---
 .../DistributionAdvisorIntegrationTest.java        | 59 ++++++++++++++++++++++
 .../distributed/internal/DistributionAdvisor.java  |  7 ++-
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/DistributionAdvisorIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/DistributionAdvisorIntegrationTest.java
new file mode 100644
index 0000000..e04ddf4
--- /dev/null
+++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/DistributionAdvisorIntegrationTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.distributed.internal;
+
+import static org.apache.geode.distributed.ConfigurationProperties.DISABLE_AUTO_RECONNECT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
+
+public class DistributionAdvisorIntegrationTest {
+
+  @Rule
+  // The embedded locator causes a ClusterDistributionManager to be created rather than a
+  // LonerDistributionManager which is necessary for this test
+  public ServerStarterRule server =
+      new ServerStarterRule().withProperty(DISABLE_AUTO_RECONNECT, "true").withNoCacheServer()
+          .withEmbeddedLocator().withAutoStart();
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Test
+  public void verifyMembershipListenerIsRemovedAfterForceDisconnect() {
+    // Create a region
+    DistributionAdvisee region = (DistributionAdvisee) server.createRegion(RegionShortcut.REPLICATE,
+        testName.getMethodName());
+
+    // Get the DistributionManager and MembershipListener before force disconnecting the server
+    DistributionManager manager = region.getDistributionManager();
+    MembershipListener listener = region.getDistributionAdvisor().getMembershipListener();
+
+    // Verify the MembershipListener is added to the DistributionManager
+    assertThat(manager.getMembershipListeners().contains(listener)).isTrue();
+
+    // Force disconnect the server
+    server.forceDisconnectMember();
+
+    // Verify the MembershipListener is removed from the DistributionManager
+    assertThat(manager.getMembershipListeners().contains(listener)).isFalse();
+  }
+}
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionAdvisor.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionAdvisor.java
index 3675b12..6a3d721 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionAdvisor.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionAdvisor.java
@@ -295,6 +295,11 @@ public class DistributionAdvisor {
         .mapToLong(CacheServer::getMaximumTimeBetweenPings).max().orElse(0L);
   }
 
+  @VisibleForTesting
+  MembershipListener getMembershipListener() {
+    return membershipListener;
+  }
+
   /**
    * find the region for a delta-gii operation (synch)
    */
@@ -374,7 +379,7 @@ public class DistributionAdvisor {
         membershipClosed = true;
         operationMonitor.close();
       }
-      getDistributionManager().removeMembershipListener(membershipListener);
+      getDistributionManagerWithNoCheck().removeMembershipListener(membershipListener);
     } catch (CancelException e) {
       // if distribution has stopped, above is a no-op.
     } catch (IllegalArgumentException ignore) {