geode-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GEODE-3793) Test/prove out new protocol's versioning/message additions
Date Mon, 20 Nov 2017 21:45:00 GMT

    [ https://issues.apache.org/jira/browse/GEODE-3793?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16259903#comment-16259903
] 

ASF GitHub Bot commented on GEODE-3793:
---------------------------------------

bschuchardt closed pull request #1058: GEODE-3793: Refactor version validation into testable
class.
URL: https://github.com/apache/geode/pull/1058
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/HandshakeRequestOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/HandshakeRequestOperationHandler.java
index 9fd480b576..1521fc063c 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/HandshakeRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/HandshakeRequestOperationHandler.java
@@ -34,6 +34,7 @@
 public class HandshakeRequestOperationHandler implements
     OperationHandler<ConnectionAPI.HandshakeRequest, ConnectionAPI.HandshakeResponse,
ClientProtocol.ErrorResponse> {
   private static final Logger logger = LogManager.getLogger();
+  private final VersionValidator validator = new VersionValidator();
 
   @Override
   public Result<ConnectionAPI.HandshakeResponse, ClientProtocol.ErrorResponse> process(
@@ -47,11 +48,9 @@
       return Failure.of(ProtobufResponseUtilities.makeErrorResponse(e));
     }
 
-    boolean handshakeSucceeded = false;
-    // Require an exact match with our version of the protobuf code for this implementation
-    if (request.getMajorVersion() == ConnectionAPI.MajorVersions.CURRENT_MAJOR_VERSION_VALUE
-        && request.getMinorVersion() == ConnectionAPI.MinorVersions.CURRENT_MINOR_VERSION_VALUE)
{
-      handshakeSucceeded = true;
+    final boolean handshakeSucceeded =
+        validator.isValid(request.getMajorVersion(), request.getMinorVersion());
+    if (handshakeSucceeded) {
       ConnectionStateProcessor nextStateProcessor = stateProcessor.handshakeSucceeded();
       messageExecutionContext.setConnectionStateProcessor(nextStateProcessor);
     }
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/VersionValidator.java
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/VersionValidator.java
new file mode 100644
index 0000000000..86eea8603d
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/VersionValidator.java
@@ -0,0 +1,43 @@
+/*
+ * 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.protocol.protobuf.v1.operations;
+
+import org.apache.geode.internal.protocol.protobuf.v1.ConnectionAPI;
+
+public class VersionValidator {
+  private int majorVersion;
+  private int minorVersion;
+
+  public VersionValidator() {
+    this(ConnectionAPI.MajorVersions.CURRENT_MAJOR_VERSION_VALUE,
+        ConnectionAPI.MinorVersions.CURRENT_MINOR_VERSION_VALUE);
+  }
+
+  VersionValidator(int majorVersion, int minorVersion) {
+    this.majorVersion = majorVersion;
+    this.minorVersion = minorVersion;
+  }
+
+  public boolean isValid(int majorVersion, int minorVersion) {
+    if (majorVersion != ConnectionAPI.MajorVersions.INVALID_MAJOR_VERSION_VALUE
+        && majorVersion == this.majorVersion) {
+      if (minorVersion != ConnectionAPI.MinorVersions.INVALID_MINOR_VERSION_VALUE
+          && minorVersion <= this.minorVersion) {
+        return true;
+      }
+    }
+    return false;
+  }
+}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/HandshakeRequestOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/HandshakeRequestOperationHandlerJUnitTest.java
index 8b7416f6eb..0641e5d196 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/HandshakeRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/HandshakeRequestOperationHandlerJUnitTest.java
@@ -167,8 +167,8 @@ public void testAuthorizingStateFailsHandshake() throws Exception {
         errorMessage.getError().getErrorCode());
   }
 
-  private ConnectionAPI.HandshakeRequest generateHandshakeRequest(int minorVersion,
-      int majorVersion) {
+  private ConnectionAPI.HandshakeRequest generateHandshakeRequest(int majorVersion,
+      int minorVersion) {
     return ConnectionAPI.HandshakeRequest.newBuilder().setMajorVersion(majorVersion)
         .setMinorVersion(minorVersion).build();
   }
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/VersionValidatorJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/VersionValidatorJUnitTest.java
new file mode 100644
index 0000000000..b59d154629
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/VersionValidatorJUnitTest.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.internal.protocol.protobuf.v1.operations;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.internal.protocol.protobuf.v1.ConnectionAPI;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class VersionValidatorJUnitTest {
+  private static final int MAJOR_VERSION = 3;
+  private static final int MINOR_VERSION = 3;
+  private static final VersionValidator validator =
+      new VersionValidator(MAJOR_VERSION, MINOR_VERSION);
+
+  @Test
+  public void testInvalidVersions() throws Exception {
+    assertFalse(
+        validator.isValid(MAJOR_VERSION, ConnectionAPI.MinorVersions.INVALID_MINOR_VERSION_VALUE));
+    assertFalse(
+        validator.isValid(ConnectionAPI.MajorVersions.INVALID_MAJOR_VERSION_VALUE, MINOR_VERSION));
+    assertFalse(validator.isValid(ConnectionAPI.MajorVersions.INVALID_MAJOR_VERSION_VALUE,
+        ConnectionAPI.MinorVersions.INVALID_MINOR_VERSION_VALUE));
+  }
+
+  @Test
+  public void testCurrentVersions() throws Exception {
+    assertTrue(validator.isValid(MAJOR_VERSION, MINOR_VERSION));
+  }
+
+  @Test
+  public void testPreviousMajorVersions() throws Exception {
+    assertFalse(validator.isValid(MAJOR_VERSION - 1, MINOR_VERSION));
+    assertFalse(validator.isValid(MAJOR_VERSION - 2, MINOR_VERSION));
+  }
+
+  @Test
+  public void testPreviousMinorVersions() throws Exception {
+    assertTrue(validator.isValid(MAJOR_VERSION, MINOR_VERSION - 1));
+    assertTrue(validator.isValid(MAJOR_VERSION, MINOR_VERSION - 2));
+  }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Test/prove out new protocol's versioning/message additions
> ----------------------------------------------------------
>
>                 Key: GEODE-3793
>                 URL: https://issues.apache.org/jira/browse/GEODE-3793
>             Project: Geode
>          Issue Type: Task
>          Components: client/server
>            Reporter: Geode Integration
>
> Test and prove out the new protocol's versioning/addition of messages.
> Expected: 
> Clients on a different major version will receive a helpful error message (and are not
supported)
> Clients on the same major version (but possibly different minor version) will be supported.
> So, devs should be able to add new messages to the protocol, bumping the minor version,
and clients without knowledge of that message should still be supported (as long as they're
on the same major version).



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message