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/03/23 18:31:10 UTC

[geode] branch support/1.14 updated: GEODE-9043: A register interest attempt from a newer client to an older server throws a NoSubscriptionServersAvailableException instead of a ServerRefusedConnectionException (#6177)

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

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


The following commit(s) were added to refs/heads/support/1.14 by this push:
     new 26a178f  GEODE-9043: A register interest attempt from a newer client to an older server throws a NoSubscriptionServersAvailableException instead of a ServerRefusedConnectionException (#6177)
26a178f is described below

commit 26a178f259f9787ef643a807f69e0b6e8a9e9cb1
Author: Sarah <sa...@pivotal.io>
AuthorDate: Tue Mar 23 14:29:48 2021 -0400

    GEODE-9043: A register interest attempt from a newer client to an older server throws a NoSubscriptionServersAvailableException instead of a ServerRefusedConnectionException (#6177)
    
    (cherry picked from commit 0abd7667b324da3a88fa341675b68f08118c83cb)
---
 ...dCompatibilityHigherVersionClientDUnitTest.java | 12 +++++++---
 .../client/internal/QueueManagerJUnitTest.java     | 28 ++++++++++++++++++++++
 .../cache/client/internal/QueueManagerImpl.java    |  4 +++-
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/tier/sockets/BackwardCompatibilityHigherVersionClientDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/tier/sockets/BackwardCompatibilityHigherVersionClientDUnitTest.java
index 0ae2306..c3bf584 100755
--- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/tier/sockets/BackwardCompatibilityHigherVersionClientDUnitTest.java
+++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/tier/sockets/BackwardCompatibilityHigherVersionClientDUnitTest.java
@@ -18,6 +18,7 @@ import static org.apache.geode.cache.Region.SEPARATOR;
 import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
 import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
 import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPort;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -34,6 +35,7 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionAttributes;
 import org.apache.geode.cache.Scope;
 import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.cache.client.ServerRefusedConnectionException;
 import org.apache.geode.cache.client.internal.ClientSideHandshakeImpl;
 import org.apache.geode.cache.client.internal.ConnectionFactoryImpl;
 import org.apache.geode.cache.client.internal.PoolImpl;
@@ -156,13 +158,17 @@ public class BackwardCompatibilityHigherVersionClientDUnitTest extends JUnit4Dis
    */
   @Test
   public void testHigherVersionedClient() {
-    Integer port1 = ((Integer) server1
+    Integer port1 = (server1
         .invoke(() -> BackwardCompatibilityHigherVersionClientDUnitTest.createServerCache()));
 
     client1.invoke(
         () -> BackwardCompatibilityHigherVersionClientDUnitTest.setHandshakeVersionForTesting());
-    client1.invoke(() -> BackwardCompatibilityHigherVersionClientDUnitTest
-        .createClientCache(NetworkUtils.getServerHostName(server1.getHost()), port1));
+
+    assertThatThrownBy(() -> client1.invoke(() -> BackwardCompatibilityHigherVersionClientDUnitTest
+        .createClientCache(NetworkUtils.getServerHostName(server1.getHost()), port1)))
+            .getCause().isInstanceOf(ServerRefusedConnectionException.class)
+            .hasMessageContaining("refused connection: Peer or client version with ordinal");
+
     client1.invoke(
         () -> BackwardCompatibilityHigherVersionClientDUnitTest.verifyConnectionToServerFailed());
   }
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/QueueManagerJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/QueueManagerJUnitTest.java
index b01f9f7..e2f8569 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/QueueManagerJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/cache/client/internal/QueueManagerJUnitTest.java
@@ -22,7 +22,11 @@ import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
 import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.catchThrowable;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
 
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -47,9 +51,11 @@ import org.junit.experimental.categories.Category;
 
 import org.apache.geode.CancelCriterion;
 import org.apache.geode.cache.NoSubscriptionServersAvailableException;
+import org.apache.geode.cache.client.ServerRefusedConnectionException;
 import org.apache.geode.cache.client.SocketFactory;
 import org.apache.geode.cache.client.SubscriptionNotEnabledException;
 import org.apache.geode.cache.query.QueryService;
+import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.DistributedSystem;
 import org.apache.geode.distributed.internal.ServerLocation;
 import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
@@ -247,6 +253,28 @@ public class QueueManagerJUnitTest {
     assertPortEquals(2, manager.getAllConnections().getPrimary());
   }
 
+  @Test
+  public void testThrowsServerRefusedConnectionException() {
+    String serverRefusedConnectionExceptionMessage =
+        "Peer or client version with ordinal x not supported. Highest known version is x.x.x.";
+    // Spy the factory so that the createClientToServerConnection method can be mocked
+    DummyFactory factorySpy = spy(factory);
+    manager = new QueueManagerImpl(pool, endpoints, source, factorySpy, 2, 20, logger,
+        ClientProxyMembershipID.getNewProxyMembership(ds));
+    // Cause a ServerRefusedConnectionException to be thrown from createClientToServerConnection
+    ServerRefusedConnectionException e =
+        new ServerRefusedConnectionException(mock(DistributedMember.class),
+            serverRefusedConnectionExceptionMessage);
+    ServerLocation sl = new ServerLocation("localhost", 1);
+    when(factorySpy.createClientToServerConnection(sl, true)).thenThrow(e);
+    // Add a server connection
+    factory.addConnection(0, 0, 1);
+    // Attempt to start the manager
+    assertThatThrownBy(() -> manager.start(background))
+        .isInstanceOf(ServerRefusedConnectionException.class)
+        .hasMessageContaining(serverRefusedConnectionExceptionMessage);
+  }
+
   private static void assertPortEquals(int expected, Connection actual) {
     assertThat(actual.getServer().getPort()).isEqualTo(expected);
   }
diff --git a/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java b/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java
index 145817c..22e762c 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/client/internal/QueueManagerImpl.java
@@ -42,6 +42,7 @@ import org.apache.geode.annotations.Immutable;
 import org.apache.geode.cache.InterestResultPolicy;
 import org.apache.geode.cache.NoSubscriptionServersAvailableException;
 import org.apache.geode.cache.client.ServerConnectivityException;
+import org.apache.geode.cache.client.ServerRefusedConnectionException;
 import org.apache.geode.cache.client.internal.PoolImpl.PoolTask;
 import org.apache.geode.cache.client.internal.RegisterInterestTracker.RegionInterestEntry;
 import org.apache.geode.cache.client.internal.ServerDenyList.DenyListListener;
@@ -451,7 +452,8 @@ public class QueueManagerImpl implements QueueManager {
       Connection connection = null;
       try {
         connection = factory.createClientToServerConnection(server, true);
-      } catch (GemFireSecurityException | GemFireConfigException e) {
+      } catch (GemFireSecurityException | GemFireConfigException
+          | ServerRefusedConnectionException e) {
         throw e;
       } catch (Exception e) {
         if (isDebugEnabled) {