This is an automated email from the ASF dual-hosted git repository.
bschuchardt pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new bdc8251 commit dade94b3b5a3a3b2178a62e31edab27ccca40aa8 Merge:
526bcfc 73be2d9 Author: Bruce Schuchardt <[email protected]> Date: Mon
Nov 20 11:39:19 2017 -0800
bdc8251 is described below
commit bdc8251135a7dccaa3c1f4bb29a2e15f5629c1cb
Author: Bruce Schuchardt <[email protected]>
AuthorDate: Mon Nov 20 11:41:57 2017 -0800
commit dade94b3b5a3a3b2178a62e31edab27ccca40aa8
Merge: 526bcfc 73be2d9
Author: Bruce Schuchardt <[email protected]>
Date: Mon Nov 20 11:39:19 2017 -0800
GEODE-3793: Refactor version validation into testable class.
Merge branch 'feature/GEODE-3793' of
https://github.com/PivotalSarge/geode into PivotalSarge-feature/GEODE-3793
---
.../HandshakeRequestOperationHandler.java | 9 ++--
.../protobuf/v1/operations/VersionValidator.java | 43 ++++++++++++++++
.../HandshakeRequestOperationHandlerJUnitTest.java | 4 +-
.../v1/operations/VersionValidatorJUnitTest.java | 59 ++++++++++++++++++++++
4 files changed, 108 insertions(+), 7 deletions(-)
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 9fd480b..1521fc0 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 @@ import
org.apache.geode.internal.protocol.state.exception.ConnectionStateExcepti
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 @@ public class HandshakeRequestOperationHandler implements
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 0000000..86eea86
--- /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 8b7416f..0641e5d 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 class HandshakeRequestOperationHandlerJUnitTest {
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 0000000..b59d154
--- /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));
+ }
+}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].