This is an automated email from the ASF dual-hosted git repository.
upthewaterspout 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 19b8199 GEODE-4090: Add ErrorCode mirroring ProtocolErrorCode enum
into protobuf
19b8199 is described below
commit 19b81995a0666ce7e6898e386684fcba4e291cf0
Author: Brian Rowe <[email protected]>
AuthorDate: Fri Dec 15 16:40:30 2017 -0800
GEODE-4090: Add ErrorCode mirroring ProtocolErrorCode enum into protobuf
* GEODE-4090: Add ErrorCode mirroring ProtocolErrorCode enum into protobuf
also added a test to assert the protobuf error codes match the protocol
error codes
---
.../src/main/proto/v1/basicTypes.proto | 26 ++++++++++++-
.../operations/GetAllRequestOperationHandler.java | 4 +-
.../operations/PutAllRequestOperationHandler.java | 4 +-
.../v1/utilities/ProtobufResponseUtilities.java | 4 +-
.../protobuf/v1/utilities/ProtobufUtilities.java | 11 ++++++
.../protobuf/v1/AuthenticationIntegrationTest.java | 6 +--
.../protobuf/v1/AuthorizationIntegrationTest.java | 2 +-
.../protocol/protobuf/v1/ErrorCodesJUnitTest.java | 45 ++++++++++++++++++++++
.../v1/acceptance/LocatorConnectionDUnitTest.java | 3 +-
.../GetRegionRequestOperationHandlerJUnitTest.java | 2 +-
.../GetRequestOperationHandlerJUnitTest.java | 4 +-
.../PutRequestOperationHandlerJUnitTest.java | 9 ++---
.../RemoveRequestOperationHandlerJUnitTest.java | 6 +--
13 files changed, 101 insertions(+), 25 deletions(-)
diff --git a/geode-protobuf-messages/src/main/proto/v1/basicTypes.proto
b/geode-protobuf-messages/src/main/proto/v1/basicTypes.proto
index d6be91b..9ab7d2f 100644
--- a/geode-protobuf-messages/src/main/proto/v1/basicTypes.proto
+++ b/geode-protobuf-messages/src/main/proto/v1/basicTypes.proto
@@ -68,7 +68,7 @@ message Server {
}
message Error {
- int32 errorCode = 1;
+ ErrorCode errorCode = 1;
string message = 2;
}
@@ -76,3 +76,27 @@ message KeyedError {
EncodedValue key = 1;
Error error = 2;
}
+
+enum ErrorCode {
+ INVALID_ERROR_CODE = 0;
+ GENERIC_FAILURE = 1000;
+ VALUE_ENCODING_ERROR = 1100;
+ UNSUPPORTED_VERSION = 1101;
+ UNSUPPORTED_OPERATION = 1102;
+ UNSUPPORTED_AUTHENTICATION_MODE = 1103;
+ HANDSHAKE_REQUIRED = 1104;
+ AUTHENTICATION_FAILED = 1200;
+ AUTHORIZATION_FAILED = 1201;
+ ALREADY_AUTHENTICATED = 1202;
+ AUTHENTICATION_NOT_SUPPORTED = 1203;
+ LOW_MEMORY = 1300;
+ DATA_UNREACHABLE = 1301;
+ OPERATION_TIMEOUT = 1302;
+ CONSTRAINT_VIOLATION = 2000;
+ BAD_QUERY = 2001;
+ REGION_NOT_FOUND = 2100;
+ QUERY_PARAMETER_MISMATCH = 2200;
+ QUERY_BIND_FAILURE = 2201;
+ QUERY_NOT_PERMITTED = 2202;
+ QUERY_TIMEOUT = 2203;
+}
diff --git
a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java
index 88eef66..2b717fc 100644
---
a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java
+++
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java
@@ -104,8 +104,8 @@ public class GetAllRequestOperationHandler implements
private Object createKeyedError(BasicTypes.EncodedValue key, String
errorMessage,
ProtocolErrorCode errorCode) {
- return BasicTypes.KeyedError.newBuilder().setKey(key).setError(
-
BasicTypes.Error.newBuilder().setErrorCode(errorCode.codeValue).setMessage(errorMessage))
+ return
BasicTypes.KeyedError.newBuilder().setKey(key).setError(BasicTypes.Error.newBuilder()
+
.setErrorCode(ProtobufUtilities.getProtobufErrorCode(errorCode)).setMessage(errorMessage))
.build();
}
}
diff --git
a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java
index c556c71..0af9ab8 100644
---
a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java
+++
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java
@@ -91,8 +91,8 @@ public class PutAllRequestOperationHandler implements
logger.error(message, ex);
return BasicTypes.KeyedError.newBuilder().setKey(entry.getKey())
- .setError(
-
BasicTypes.Error.newBuilder().setErrorCode(errorCode.codeValue).setMessage(message))
+ .setError(BasicTypes.Error.newBuilder()
+
.setErrorCode(ProtobufUtilities.getProtobufErrorCode(errorCode)).setMessage(message))
.build();
}
}
diff --git
a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufResponseUtilities.java
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufResponseUtilities.java
index 23ab351..7b24d60 100644
---
a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufResponseUtilities.java
+++
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufResponseUtilities.java
@@ -53,8 +53,8 @@ public abstract class ProtobufResponseUtilities {
public static ClientProtocol.ErrorResponse
makeErrorResponse(ProtocolErrorCode errorCode,
String message) {
return ClientProtocol.ErrorResponse.newBuilder()
- .setError(
-
BasicTypes.Error.newBuilder().setErrorCode(errorCode.codeValue).setMessage(message))
+ .setError(BasicTypes.Error.newBuilder()
+
.setErrorCode(ProtobufUtilities.getProtobufErrorCode(errorCode)).setMessage(message))
.build();
}
diff --git
a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilities.java
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilities.java
index 183e039..3b900ea 100644
---
a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilities.java
+++
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilities.java
@@ -19,6 +19,7 @@ import com.google.protobuf.ByteString;
import org.apache.geode.annotations.Experimental;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
+import org.apache.geode.internal.protocol.ProtocolErrorCode;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
import org.apache.geode.internal.protocol.protobuf.v1.EncodingTypeTranslator;
@@ -171,6 +172,16 @@ public abstract class ProtobufUtilities {
}
/**
+ * This will convert a ProtocolErrorCode to a BasicTypes.ErrorCode for
protobuf
+ *
+ * @param errorCode - incoming ProtocolErrorCode
+ * @return matching protobuf error code
+ */
+ public static BasicTypes.ErrorCode getProtobufErrorCode(ProtocolErrorCode
errorCode) {
+ return BasicTypes.ErrorCode.forNumber(errorCode.codeValue);
+ }
+
+ /**
* @return a Protobuf BasicTypes.Region message that represents the {@link
Region}
*/
diff --git
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthenticationIntegrationTest.java
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthenticationIntegrationTest.java
index f3f68f4..c1c4672 100644
---
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthenticationIntegrationTest.java
+++
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthenticationIntegrationTest.java
@@ -189,7 +189,7 @@ public class AuthenticationIntegrationTest {
ClientProtocol.Message errorResponse =
protobufProtocolSerializer.deserialize(inputStream);
assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
errorResponse.getResponse().getResponseAPICase());
- assertEquals(AUTHENTICATION_FAILED.codeValue,
+ assertEquals(BasicTypes.ErrorCode.AUTHENTICATION_FAILED,
errorResponse.getResponse().getErrorResponse().getError().getErrorCode());
verifyConnectionClosed();
}
@@ -289,7 +289,7 @@ public class AuthenticationIntegrationTest {
ClientProtocol.Message errorResponse =
protobufProtocolSerializer.deserialize(inputStream);
assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
errorResponse.getResponse().getResponseAPICase());
- assertEquals(UNSUPPORTED_AUTHENTICATION_MODE.codeValue,
+ assertEquals(BasicTypes.ErrorCode.UNSUPPORTED_AUTHENTICATION_MODE,
errorResponse.getResponse().getErrorResponse().getError().getErrorCode());
verifyConnectionClosed();
}
@@ -310,7 +310,7 @@ public class AuthenticationIntegrationTest {
ClientProtocol.Message errorResponse =
protobufProtocolSerializer.deserialize(inputStream);
assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
errorResponse.getResponse().getResponseAPICase());
- assertEquals(UNSUPPORTED_AUTHENTICATION_MODE.codeValue,
+ assertEquals(BasicTypes.ErrorCode.UNSUPPORTED_AUTHENTICATION_MODE,
errorResponse.getResponse().getErrorResponse().getError().getErrorCode());
verifyConnectionClosed();
}
diff --git
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
index cc69333..bc3a515 100644
---
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
+++
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
@@ -206,7 +206,7 @@ public class AuthorizationIntegrationTest {
ClientProtocol.Message response =
protobufProtocolSerializer.deserialize(inputStream);
assertEquals(expectedResponseType,
response.getResponse().getResponseAPICase());
if (expectedResponseType ==
ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE) {
- Assert.assertEquals(ProtocolErrorCode.AUTHORIZATION_FAILED.codeValue,
+ Assert.assertEquals(BasicTypes.ErrorCode.AUTHORIZATION_FAILED,
response.getResponse().getErrorResponse().getError().getErrorCode());
}
}
diff --git
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/ErrorCodesJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/ErrorCodesJUnitTest.java
new file mode 100644
index 0000000..b341faa
--- /dev/null
+++
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/ErrorCodesJUnitTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.internal.protocol.ProtocolErrorCode;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class ErrorCodesJUnitTest {
+ @Test
+ public void testProtobufErrorCodesMatchProtocolErrorCodes() {
+ BasicTypes.ErrorCode[] protobufErrorCodes = BasicTypes.ErrorCode.values();
+ ProtocolErrorCode[] protocolErrorCodes = ProtocolErrorCode.values();
+
+ // These arrays should identical except the protobuf is required to have a
0 value, and defines
+ // an UNRECOGNIZED entry
+ assertEquals(protobufErrorCodes.length - 2, protocolErrorCodes.length);
+ for (int i = 0; i < protobufErrorCodes.length; ++i) {
+ if (i == 0) {
+ assertEquals(BasicTypes.ErrorCode.INVALID_ERROR_CODE,
protobufErrorCodes[i]);
+ } else if (i == protobufErrorCodes.length - 1) {
+ assertEquals(BasicTypes.ErrorCode.UNRECOGNIZED, protobufErrorCodes[i]);
+ } else {
+ assertEquals(protobufErrorCodes[i].getNumber(), protocolErrorCodes[i -
1].codeValue);
+ }
+ }
+ }
+}
diff --git
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/LocatorConnectionDUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/LocatorConnectionDUnitTest.java
index fc52d33..bbfd7cd 100644
---
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/LocatorConnectionDUnitTest.java
+++
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/LocatorConnectionDUnitTest.java
@@ -38,6 +38,7 @@ import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.protocol.ProtocolErrorCode;
import
org.apache.geode.internal.protocol.exception.InvalidProtocolMessageException;
import
org.apache.geode.internal.protocol.protobuf.statistics.ProtobufClientStatisticsImpl;
+import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
import org.apache.geode.internal.protocol.protobuf.v1.ConnectionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.LocatorAPI;
@@ -149,7 +150,7 @@ public class LocatorConnectionDUnitTest extends
JUnit4CacheTestCase {
ClientProtocol.Response messageResponse =
getAvailableServersResponseMessage.getResponse();
assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
messageResponse.getResponseAPICase());
- assertEquals(ProtocolErrorCode.UNSUPPORTED_OPERATION.codeValue,
+ assertEquals(BasicTypes.ErrorCode.UNSUPPORTED_OPERATION,
messageResponse.getErrorResponse().getError().getErrorCode());
validateStats(messagesReceived + 1, messagesSent + 1,
diff --git
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandlerJUnitTest.java
index ec141fd..bdcec29 100644
---
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandlerJUnitTest.java
+++
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandlerJUnitTest.java
@@ -98,7 +98,7 @@ public class GetRegionRequestOperationHandlerJUnitTest
extends OperationHandlerJ
Assert.assertTrue(result instanceof Failure);
ClientProtocol.ErrorResponse errorMessage =
(ClientProtocol.ErrorResponse) result.getErrorMessage();
- Assert.assertEquals(ProtocolErrorCode.REGION_NOT_FOUND.codeValue,
+ Assert.assertEquals(BasicTypes.ErrorCode.REGION_NOT_FOUND,
errorMessage.getError().getErrorCode());
}
diff --git
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandlerJUnitTest.java
index aafdbdb..72f2759 100644
---
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandlerJUnitTest.java
+++
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandlerJUnitTest.java
@@ -87,7 +87,7 @@ public class GetRequestOperationHandlerJUnitTest extends
OperationHandlerJUnitTe
Assert.assertTrue(response instanceof Failure);
ClientProtocol.ErrorResponse errorMessage =
(ClientProtocol.ErrorResponse) response.getErrorMessage();
- Assert.assertEquals(ProtocolErrorCode.REGION_NOT_FOUND.codeValue,
+ Assert.assertEquals(BasicTypes.ErrorCode.REGION_NOT_FOUND,
errorMessage.getError().getErrorCode());
}
@@ -128,7 +128,7 @@ public class GetRequestOperationHandlerJUnitTest extends
OperationHandlerJUnitTe
Assert.assertTrue(response instanceof Failure);
ClientProtocol.ErrorResponse errorMessage =
(ClientProtocol.ErrorResponse) response.getErrorMessage();
- Assert.assertEquals(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue,
+ Assert.assertEquals(BasicTypes.ErrorCode.VALUE_ENCODING_ERROR,
errorMessage.getError().getErrorCode());
}
diff --git
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandlerJUnitTest.java
index 8e5a690..ef07fca 100644
---
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandlerJUnitTest.java
+++
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandlerJUnitTest.java
@@ -98,8 +98,7 @@ public class PutRequestOperationHandlerJUnitTest extends
OperationHandlerJUnitTe
assertTrue(result instanceof Failure);
ClientProtocol.ErrorResponse errorMessage =
(ClientProtocol.ErrorResponse) result.getErrorMessage();
- assertEquals(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue,
- errorMessage.getError().getErrorCode());
+ assertEquals(BasicTypes.ErrorCode.VALUE_ENCODING_ERROR,
errorMessage.getError().getErrorCode());
}
@Test
@@ -112,8 +111,7 @@ public class PutRequestOperationHandlerJUnitTest extends
OperationHandlerJUnitTe
assertTrue(result instanceof Failure);
ClientProtocol.ErrorResponse errorMessage =
(ClientProtocol.ErrorResponse) result.getErrorMessage();
- assertEquals(ProtocolErrorCode.REGION_NOT_FOUND.codeValue,
- errorMessage.getError().getErrorCode());
+ assertEquals(BasicTypes.ErrorCode.REGION_NOT_FOUND,
errorMessage.getError().getErrorCode());
}
@Test
@@ -127,8 +125,7 @@ public class PutRequestOperationHandlerJUnitTest extends
OperationHandlerJUnitTe
assertTrue(result instanceof Failure);
ClientProtocol.ErrorResponse errorMessage =
(ClientProtocol.ErrorResponse) result.getErrorMessage();
- assertEquals(ProtocolErrorCode.CONSTRAINT_VIOLATION.codeValue,
- errorMessage.getError().getErrorCode());
+ assertEquals(BasicTypes.ErrorCode.CONSTRAINT_VIOLATION,
errorMessage.getError().getErrorCode());
}
private RegionAPI.PutRequest generateTestRequest()
diff --git
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandlerJUnitTest.java
index 64bb352..e8bd857 100644
---
a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandlerJUnitTest.java
+++
b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandlerJUnitTest.java
@@ -83,8 +83,7 @@ public class RemoveRequestOperationHandlerJUnitTest extends
OperationHandlerJUni
assertTrue(result instanceof Failure);
ClientProtocol.ErrorResponse errorMessage =
(ClientProtocol.ErrorResponse) result.getErrorMessage();
- assertEquals(ProtocolErrorCode.REGION_NOT_FOUND.codeValue,
- errorMessage.getError().getErrorCode());
+ assertEquals(BasicTypes.ErrorCode.REGION_NOT_FOUND,
errorMessage.getError().getErrorCode());
}
@Test
@@ -116,8 +115,7 @@ public class RemoveRequestOperationHandlerJUnitTest extends
OperationHandlerJUni
assertTrue(result instanceof Failure);
ClientProtocol.ErrorResponse errorMessage =
(ClientProtocol.ErrorResponse) result.getErrorMessage();
- assertEquals(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue,
- errorMessage.getError().getErrorCode());
+ assertEquals(BasicTypes.ErrorCode.VALUE_ENCODING_ERROR,
errorMessage.getError().getErrorCode());
}
private ClientProtocol.Request generateTestRequest(boolean missingRegion,
boolean missingKey)
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].