Mmuzaf commented on code in PR #2506:
URL: https://github.com/apache/cassandra/pull/2506#discussion_r1275035694


##########
test/unit/org/apache/cassandra/net/HandshakeTest.java:
##########
@@ -146,94 +144,38 @@ public void testSendIncompatibleFutureVersion() throws 
InterruptedException, Exe
     @Test
     public void testSendIncompatibleOldVersion() throws InterruptedException, 
ExecutionException
     {
-        Result result = handshake(current_version + 1, current_version + 1, 
current_version + 1, current_version + 2, current_version + 3);
+        Result result = handshake(current_version + 1, current_version + 1, 
current_version + 2, current_version + 3);
         Assert.assertEquals(Result.Outcome.INCOMPATIBLE, result.outcome);
         Assert.assertEquals(current_version + 2, 
result.incompatible().closestSupportedVersion);
         Assert.assertEquals(current_version + 3, 
result.incompatible().maxMessagingVersion);
     }
 
     @Test
-    public void testSendCompatibleMaxVersionPre40() throws 
InterruptedException, ExecutionException
-    {
-        Result result = handshake(VERSION_3014, VERSION_30, VERSION_3014, 
VERSION_30, VERSION_3014);
-        Assert.assertEquals(Result.Outcome.SUCCESS, result.outcome);
-        Assert.assertEquals(VERSION_3014, result.success().messagingVersion);
-        result.success().channel.close();
-    }
-
-    @Test
-    public void testSendCompatibleFutureVersionPre40() throws 
InterruptedException, ExecutionException
-    {
-        Result result = handshake(VERSION_3014, VERSION_30, VERSION_3014, 
VERSION_30, VERSION_30);
-        Assert.assertEquals(Result.Outcome.RETRY, result.outcome);
-        Assert.assertEquals(VERSION_30, result.retry().withMessagingVersion);
-    }
-
-    @Test
-    public void testSendIncompatibleFutureVersionPre40() throws 
InterruptedException, ExecutionException
-    {
-        Result result = handshake(VERSION_3014, VERSION_3014, VERSION_3014, 
VERSION_30, VERSION_30);
-        Assert.assertEquals(Result.Outcome.INCOMPATIBLE, result.outcome);
-        Assert.assertEquals(-1, result.incompatible().closestSupportedVersion);
-        Assert.assertEquals(VERSION_30, 
result.incompatible().maxMessagingVersion);
-    }
-
-    @Test
-    public void testSendCompatibleOldVersionPre40() throws InterruptedException
-    {
-        try
-        {
-            handshake(VERSION_30, VERSION_30, VERSION_3014, VERSION_3014, 
VERSION_3014);
-            Assert.fail("Should have thrown");
-        }
-        catch (ExecutionException e)
-        {
-            assertTrue(e.getCause() instanceof ClosedChannelException);
-        }
-    }
-
-    @Test
-    public void testSendIncompatibleOldVersionPre40() throws 
InterruptedException
+    public void testSendAllSupported() throws InterruptedException, 
ExecutionException
     {
-        try
-        {
-            handshake(VERSION_30, VERSION_30, VERSION_30, VERSION_3014, 
VERSION_3014);
-            Assert.fail("Should have thrown");
+        List<MessagingService.Version> supportedVersions = 
MessagingService.Version.supportedVersions();
+        for (MessagingService.Version outMin : supportedVersions)
+            for (MessagingService.Version outMax : supportedVersions)
+                if (outMin.value <= outMax.value)
+                    for (MessagingService.Version inMin : supportedVersions)
+                        for (MessagingService.Version inMax : 
supportedVersions)
+                            if (inMin.value <= inMax.value)
+                            {
+                                Result result = handshake(outMin.value, 
outMax.value, inMin.value, inMax.value);
+                                // expect success if out and in have a version 
in common
+                                boolean expectSuccess = outMin.value <= 
inMax.value && inMin.value <= outMax.value;
+
+                                Assert.assertEquals(String.format("wrong 
result outcome for outMin %s outMax %s inMin %s inMax %s", outMin.value, 
outMax.value, inMin.value, inMax.value),
+                                                expectSuccess ? 
Result.Outcome.SUCCESS : Result.Outcome.INCOMPATIBLE, result.outcome);
+
+                                if (expectSuccess)
+                                {
+                                    Assert.assertEquals(String.format("wrong 
agreed messagingVersion for outMin %s outMax %s inMin %s inMax %s", 
outMin.value, outMax.value, inMin.value, inMax.value),
+                                                    Math.min(outMax.value, 
inMax.value), result.success().messagingVersion);
+                                    result.success().channel.close();
+                                }
+                            }
         }

Review Comment:
   nit: wrong indentation



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to