geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject geode git commit: GEODE-3321: Adding ErrorCode values to protobuf protocol. This now closes #676
Date Fri, 04 Aug 2017 17:54:43 GMT
Repository: geode
Updated Branches:
  refs/heads/develop 3c517d39b -> c8cc4e60b


GEODE-3321: Adding ErrorCode values to protobuf protocol. This now closes #676

Signed-off-by: Bruce Schuchardt <bschuchardt@pivotal.io>
Signed-off-by: Brian Rowe <browe@pivotal.io>


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/c8cc4e60
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/c8cc4e60
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/c8cc4e60

Branch: refs/heads/develop
Commit: c8cc4e60be2ae5fcaa90351d143d362949f3de81
Parents: 3c517d3
Author: Brian Rowe <browe@pivotal.io>
Authored: Tue Aug 1 16:56:24 2017 -0700
Committer: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Committed: Fri Aug 4 10:54:21 2017 -0700

----------------------------------------------------------------------
 .../protocol/protobuf/ProtocolErrorCode.java    | 39 ++++++++++++++++++++
 .../GetAllRequestOperationHandler.java          | 12 ++++--
 .../GetAvailableServersOperationHandler.java    |  6 ++-
 .../GetRegionRequestOperationHandler.java       |  2 +
 .../operations/GetRequestOperationHandler.java  | 12 ++++--
 .../PutAllRequestOperationHandler.java          | 17 ++++++---
 .../operations/PutRequestOperationHandler.java  | 11 +++++-
 .../RemoveRequestOperationHandler.java          | 15 +++++---
 .../utilities/ProtobufResponseUtilities.java    |  8 ++--
 ...tRegionRequestOperationHandlerJUnitTest.java | 25 ++++++-------
 .../GetRequestOperationHandlerJUnitTest.java    | 32 +++++++---------
 .../PutAllRequestOperationHandlerJUnitTest.java |  5 +--
 .../PutRequestOperationHandlerJUnitTest.java    | 24 ++++++------
 .../RemoveRequestOperationHandlerJUnitTest.java | 35 +++++++++---------
 14 files changed, 152 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtocolErrorCode.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtocolErrorCode.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtocolErrorCode.java
new file mode 100644
index 0000000..e3b262d
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtocolErrorCode.java
@@ -0,0 +1,39 @@
+/*
+ * 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.protocol.protobuf;
+
+public enum ProtocolErrorCode {
+  GENERIC_FAILURE(1000),
+  VALUE_ENCODING_ERROR(1100),
+  UNSUPPORTED_VERSION(1101),
+  AUTHENTICATION_FAILED(1200),
+  AUTHORIZATION_FAILED(1201),
+  UNAUTHORIZED_REQUEST(1202),
+  LOW_MEMORY(1300),
+  DATA_UNREACHABLE(1301),
+  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);
+
+  ProtocolErrorCode(int value) {
+    codeValue = value;
+  }
+
+  public int codeValue;
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandler.java
index a6ffd9d..7c8685f 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandler.java
@@ -19,6 +19,7 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.protocol.operations.OperationHandler;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.Success;
@@ -40,8 +41,9 @@ public class GetAllRequestOperationHandler
     String regionName = request.getRegionName();
     Region region = cache.getRegion(regionName);
     if (region == null) {
-      return Failure
-          .of(BasicTypes.ErrorResponse.newBuilder().setMessage("Region not found").build());
+      return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.REGION_NOT_FOUND.codeValue).setMessage("Region
not found")
+          .build());
     }
 
     try {
@@ -57,10 +59,12 @@ public class GetAllRequestOperationHandler
       }
       return Success.of(RegionAPI.GetAllResponse.newBuilder().addAllEntries(entries).build());
     } catch (UnsupportedEncodingTypeException ex) {
-      return Failure
-          .of(BasicTypes.ErrorResponse.newBuilder().setMessage("Encoding not supported.").build());
+      return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue)
+          .setMessage("Encoding not supported.").build());
     } catch (CodecNotRegisteredForTypeException ex) {
       return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue)
           .setMessage("Codec error in protobuf deserialization.").build());
     }
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandler.java
index cf3f828..39c837a 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandler.java
@@ -26,6 +26,7 @@ import org.apache.geode.internal.admin.remote.DistributionLocatorId;
 import org.apache.geode.protocol.operations.OperationHandler;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.ServerAPI;
 import org.apache.geode.protocol.protobuf.Success;
@@ -69,8 +70,9 @@ public class GetAvailableServersOperationHandler implements
         // try the next locator
       }
     }
-    return Failure
-        .of(BasicTypes.ErrorResponse.newBuilder().setMessage("Unable to find a locator").build());
+    return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+        .setErrorCode(ProtocolErrorCode.DATA_UNREACHABLE.codeValue)
+        .setMessage("Unable to find a locator").build());
   }
 
   private Result<ServerAPI.GetAvailableServersResponse> getGetAvailableServersFromLocator(

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRegionRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRegionRequestOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRegionRequestOperationHandler.java
index e8dfdda..5ad0cc1 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRegionRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRegionRequestOperationHandler.java
@@ -19,6 +19,7 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.protocol.operations.OperationHandler;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.Success;
@@ -37,6 +38,7 @@ public class GetRegionRequestOperationHandler
     Region region = cache.getRegion(regionName);
     if (region == null) {
       return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.REGION_NOT_FOUND.codeValue)
           .setMessage("No region exists for name: " + regionName).build());
     }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
index 21aa15f..861e518 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandler.java
@@ -19,6 +19,7 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.protocol.operations.OperationHandler;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.Success;
@@ -36,8 +37,9 @@ public class GetRequestOperationHandler
     String regionName = request.getRegionName();
     Region region = cache.getRegion(regionName);
     if (region == null) {
-      return Failure
-          .of(BasicTypes.ErrorResponse.newBuilder().setMessage("Region not found").build());
+      return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.REGION_NOT_FOUND.codeValue).setMessage("Region
not found")
+          .build());
     }
 
     try {
@@ -52,10 +54,12 @@ public class GetRequestOperationHandler
           ProtobufUtilities.createEncodedValue(serializationService, resultValue);
       return Success.of(RegionAPI.GetResponse.newBuilder().setResult(encodedValue).build());
     } catch (UnsupportedEncodingTypeException ex) {
-      return Failure
-          .of(BasicTypes.ErrorResponse.newBuilder().setMessage("Encoding not supported.").build());
+      return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue)
+          .setMessage("Encoding not supported.").build());
     } catch (CodecNotRegisteredForTypeException ex) {
       return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue)
           .setMessage("Codec error in protobuf deserialization.").build());
     }
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/PutAllRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/PutAllRequestOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/PutAllRequestOperationHandler.java
index 6e26e75..49fd811 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/PutAllRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/PutAllRequestOperationHandler.java
@@ -19,6 +19,7 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.protocol.operations.OperationHandler;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.Success;
@@ -44,6 +45,7 @@ public class PutAllRequestOperationHandler
 
     if (region == null) {
       return Failure.of(ProtobufResponseUtilities.createAndLogErrorResponse(
+          ProtocolErrorCode.REGION_NOT_FOUND,
           "Region passed by client did not exist: " + putAllRequest.getRegionName(), logger,
null));
     }
 
@@ -62,20 +64,23 @@ public class PutAllRequestOperationHandler
 
       region.put(decodedKey, decodedValue);
     } catch (UnsupportedEncodingTypeException ex) {
-      return buildAndLogKeyedError(entry, "Encoding not supported", ex);
+      return buildAndLogKeyedError(entry, ProtocolErrorCode.VALUE_ENCODING_ERROR,
+          "Encoding not supported", ex);
     } catch (CodecNotRegisteredForTypeException ex) {
-      return buildAndLogKeyedError(entry, "Codec error in protobuf deserialization", ex);
+      return buildAndLogKeyedError(entry, ProtocolErrorCode.VALUE_ENCODING_ERROR,
+          "Codec error in protobuf deserialization", ex);
     } catch (ClassCastException ex) {
-      return buildAndLogKeyedError(entry, "Invalid key or value type for region", ex);
+      return buildAndLogKeyedError(entry, ProtocolErrorCode.CONSTRAINT_VIOLATION,
+          "Invalid key or value type for region", ex);
     }
     return null;
   }
 
   private BasicTypes.KeyedErrorResponse buildAndLogKeyedError(BasicTypes.Entry entry,
-      String message, Exception ex) {
+      ProtocolErrorCode errorCode, String message, Exception ex) {
     logger.error(message, ex);
-    BasicTypes.ErrorResponse errorResponse =
-        BasicTypes.ErrorResponse.newBuilder().setMessage(message).build();
+    BasicTypes.ErrorResponse errorResponse = BasicTypes.ErrorResponse.newBuilder()
+        .setErrorCode(errorCode.codeValue).setMessage(message).build();
     return BasicTypes.KeyedErrorResponse.newBuilder().setKey(entry.getKey()).setError(errorResponse)
         .build();
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/PutRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/PutRequestOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/PutRequestOperationHandler.java
index ce61c55..9c51c87 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/PutRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/PutRequestOperationHandler.java
@@ -19,6 +19,7 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.protocol.operations.OperationHandler;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.Success;
@@ -37,6 +38,7 @@ public class PutRequestOperationHandler
     Region region = cache.getRegion(regionName);
     if (region == null) {
       return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.REGION_NOT_FOUND.codeValue)
           .setMessage("Region passed by client did not exist: " + regionName).build());
     }
 
@@ -50,12 +52,17 @@ public class PutRequestOperationHandler
         return Success.of(RegionAPI.PutResponse.newBuilder().build());
       } catch (ClassCastException ex) {
         return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+            .setErrorCode(ProtocolErrorCode.CONSTRAINT_VIOLATION.codeValue)
             .setMessage("invalid key or value type for region " + regionName).build());
       }
     } catch (UnsupportedEncodingTypeException ex) {
-      return Failure.of(BasicTypes.ErrorResponse.newBuilder().setMessage(ex.getMessage()).build());
+      return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue)
+          .setMessage(ex.getMessage()).build());
     } catch (CodecNotRegisteredForTypeException ex) {
-      return Failure.of(BasicTypes.ErrorResponse.newBuilder().setMessage(ex.getMessage()).build());
+      return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue)
+          .setMessage(ex.getMessage()).build());
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/RemoveRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/RemoveRequestOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/RemoveRequestOperationHandler.java
index 0bf162e..296f8b2 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/RemoveRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/RemoveRequestOperationHandler.java
@@ -19,6 +19,7 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.protocol.operations.OperationHandler;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.Success;
@@ -41,8 +42,9 @@ public class RemoveRequestOperationHandler
     String regionName = request.getRegionName();
     Region region = cache.getRegion(regionName);
     if (region == null) {
-      return Failure
-          .of(BasicTypes.ErrorResponse.newBuilder().setMessage("Region not found").build());
+      return Failure.of(BasicTypes.ErrorResponse.newBuilder()
+          .setErrorCode(ProtocolErrorCode.REGION_NOT_FOUND.codeValue).setMessage("Region
not found")
+          .build());
     }
 
     try {
@@ -52,11 +54,12 @@ public class RemoveRequestOperationHandler
       return Success.of(RegionAPI.RemoveResponse.newBuilder().build());
     } catch (UnsupportedEncodingTypeException ex) {
       // can be thrown by encoding or decoding.
-      return Failure.of(ProtobufResponseUtilities
-          .createAndLogErrorResponse("Encoding not supported.", logger, ex));
+      return Failure.of(ProtobufResponseUtilities.createAndLogErrorResponse(
+          ProtocolErrorCode.VALUE_ENCODING_ERROR, "Encoding not supported.", logger, ex));
     } catch (CodecNotRegisteredForTypeException ex) {
-      return Failure.of(ProtobufResponseUtilities
-          .createAndLogErrorResponse("Codec error in protobuf deserialization.", logger,
ex));
+      return Failure.of(ProtobufResponseUtilities.createAndLogErrorResponse(
+          ProtocolErrorCode.VALUE_ENCODING_ERROR, "Codec error in protobuf deserialization.",
+          logger, ex));
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufResponseUtilities.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufResponseUtilities.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufResponseUtilities.java
index 06ae401..bb3ef98 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufResponseUtilities.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufResponseUtilities.java
@@ -16,6 +16,7 @@ package org.apache.geode.protocol.protobuf.utilities;
 
 import org.apache.geode.cache.Region;
 import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.logging.log4j.Logger;
 
@@ -38,14 +39,15 @@ public abstract class ProtobufResponseUtilities {
    * @param ex - exception which should be logged
    * @return An error response containing the first three parameters.
    */
-  public static BasicTypes.ErrorResponse createAndLogErrorResponse(String errorMessage,
-      Logger logger, Exception ex) {
+  public static BasicTypes.ErrorResponse createAndLogErrorResponse(ProtocolErrorCode errorCode,
+      String errorMessage, Logger logger, Exception ex) {
     if (ex != null) {
       logger.error(errorMessage, ex);
     } else {
       logger.error(errorMessage);
     }
-    return BasicTypes.ErrorResponse.newBuilder().setMessage(errorMessage).build();
+    return BasicTypes.ErrorResponse.newBuilder().setErrorCode(errorCode.codeValue)
+        .setMessage(errorMessage).build();
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRegionRequestOperationHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRegionRequestOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRegionRequestOperationHandlerJUnitTest.java
index 1392aec..a1f67df 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRegionRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRegionRequestOperationHandlerJUnitTest.java
@@ -14,17 +14,6 @@
  */
 package org.apache.geode.protocol.protobuf.operations;
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.nio.charset.Charset;
-import java.util.Collections;
-import java.util.HashSet;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.DataPolicy;
 import org.apache.geode.cache.Region;
@@ -34,6 +23,7 @@ import org.apache.geode.protocol.MessageUtil;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.ClientProtocol;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
@@ -41,6 +31,15 @@ import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredF
 import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
 import org.apache.geode.test.dunit.Assert;
 import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Collections;
+import java.util.HashSet;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 @Category(UnitTest.class)
 public class GetRegionRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTest
{
@@ -99,7 +98,7 @@ public class GetRegionRequestOperationHandlerJUnitTest extends OperationHandlerJ
     Result<RegionAPI.GetRegionResponse> result = operationHandler.process(serializationServiceStub,
         MessageUtil.makeGetRegionRequest(unknownRegionName), emptyCache);
     Assert.assertTrue(result instanceof Failure);
-    Assert.assertEquals("No region exists for name: " + unknownRegionName,
-        result.getErrorMessage().getMessage());
+    Assert.assertEquals(ProtocolErrorCode.REGION_NOT_FOUND.codeValue,
+        result.getErrorMessage().getErrorCode());
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandlerJUnitTest.java
index 6710f1a..a632532 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetRequestOperationHandlerJUnitTest.java
@@ -14,24 +14,11 @@
  */
 package org.apache.geode.protocol.protobuf.operations;
 
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyCollection;
-import static org.mockito.ArgumentMatchers.anyObject;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-
 import com.google.protobuf.ByteString;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
 import org.apache.geode.cache.Region;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.Success;
@@ -43,7 +30,15 @@ import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredF
 import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
 import org.apache.geode.test.dunit.Assert;
 import org.apache.geode.test.junit.categories.UnitTest;
-import org.mockito.internal.matchers.Any;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.UnsupportedEncodingException;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 @Category(UnitTest.class)
 public class GetRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTest {
@@ -96,7 +91,8 @@ public class GetRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
         operationHandler.process(serializationServiceStub, getRequest, cacheStub);
 
     Assert.assertTrue(response instanceof Failure);
-    Assert.assertEquals("Region not found", response.getErrorMessage().getMessage());
+    Assert.assertEquals(ProtocolErrorCode.REGION_NOT_FOUND.codeValue,
+        response.getErrorMessage().getErrorCode());
   }
 
   @Test
@@ -140,8 +136,8 @@ public class GetRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
         operationHandler.process(serializationServiceStub, getRequest, cacheStub);
 
     Assert.assertTrue(response instanceof Failure);
-    Assert.assertEquals("Codec error in protobuf deserialization.",
-        response.getErrorMessage().getMessage());
+    Assert.assertEquals(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue,
+        response.getErrorMessage().getErrorCode());
   }
 
   private RegionAPI.GetRequest generateTestRequest(boolean missingRegion, boolean missingKey,

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/PutAllRequestOperationHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/PutAllRequestOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/PutAllRequestOperationHandlerJUnitTest.java
index 0fde9e5..c13d542 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/PutAllRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/PutAllRequestOperationHandlerJUnitTest.java
@@ -21,7 +21,6 @@ import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.Success;
 import org.apache.geode.protocol.protobuf.utilities.ProtobufRequestUtilities;
 import org.apache.geode.protocol.protobuf.utilities.ProtobufUtilities;
-import org.apache.geode.serialization.SerializationService;
 import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
 import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
 import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
@@ -31,8 +30,6 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -84,7 +81,7 @@ public class PutAllRequestOperationHandlerJUnitTest extends OperationHandlerJUni
   }
 
   @Test
-  public void processWithInvalidEntryReturnsError() throws Exception {
+  public void processWithInvalidEntrySucceedsAndReturnsFailedKey() throws Exception {
     PutAllRequestOperationHandler operationHandler = new PutAllRequestOperationHandler();
 
     Result<RegionAPI.PutAllResponse> result = operationHandler.process(serializationServiceStub,

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/PutRequestOperationHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/PutRequestOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/PutRequestOperationHandlerJUnitTest.java
index 144f5b8..9fdadd8 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/PutRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/PutRequestOperationHandlerJUnitTest.java
@@ -18,6 +18,7 @@ import com.google.protobuf.ByteString;
 import org.apache.geode.cache.Region;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.Success;
@@ -26,15 +27,15 @@ import org.apache.geode.protocol.protobuf.utilities.ProtobufUtilities;
 import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
 import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
 import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
-import org.apache.geode.test.dunit.Assert;
 import org.apache.geode.test.junit.categories.UnitTest;
-import org.hamcrest.CoreMatchers;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 import java.io.UnsupportedEncodingException;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.anyString;
 import static org.mockito.Mockito.mock;
@@ -66,7 +67,7 @@ public class PutRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
     Result<RegionAPI.PutResponse> result =
         operationHandler.process(serializationServiceStub, generateTestRequest(), cacheStub);
 
-    Assert.assertTrue(result instanceof Success);
+    assertTrue(result instanceof Success);
 
     verify(regionMock).put(TEST_KEY, TEST_VALUE);
     verify(regionMock, times(1)).put(anyString(), anyString());
@@ -97,8 +98,9 @@ public class PutRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
     Result<RegionAPI.PutResponse> result =
         operationHandler.process(serializationServiceStub, putRequest, cacheStub);
 
-    Assert.assertTrue(result instanceof Failure);
-    org.junit.Assert.assertEquals(exceptionText, result.getErrorMessage().getMessage());
+    assertTrue(result instanceof Failure);
+    assertEquals(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue,
+        result.getErrorMessage().getErrorCode());
   }
 
   @Test
@@ -109,9 +111,9 @@ public class PutRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
     Result<RegionAPI.PutResponse> result =
         operationHandler.process(serializationServiceStub, generateTestRequest(), cacheStub);
 
-    Assert.assertTrue(result instanceof Failure);
-    org.junit.Assert.assertEquals("Region passed by client did not exist: test region",
-        result.getErrorMessage().getMessage());
+    assertTrue(result instanceof Failure);
+    assertEquals(ProtocolErrorCode.REGION_NOT_FOUND.codeValue,
+        result.getErrorMessage().getErrorCode());
   }
 
   @Test
@@ -123,9 +125,9 @@ public class PutRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
     Result<RegionAPI.PutResponse> result =
         operationHandler.process(serializationServiceStub, generateTestRequest(), cacheStub);
 
-    Assert.assertTrue(result instanceof Failure);
-    org.junit.Assert.assertThat(result.getErrorMessage().getMessage(),
-        CoreMatchers.containsString("invalid key or value type"));
+    assertTrue(result instanceof Failure);
+    assertEquals(ProtocolErrorCode.CONSTRAINT_VIOLATION.codeValue,
+        result.getErrorMessage().getErrorCode());
   }
 
   private RegionAPI.PutRequest generateTestRequest()

http://git-wip-us.apache.org/repos/asf/geode/blob/c8cc4e60/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/RemoveRequestOperationHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/RemoveRequestOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/RemoveRequestOperationHandlerJUnitTest.java
index 36982a1..797538c 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/RemoveRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/RemoveRequestOperationHandlerJUnitTest.java
@@ -14,25 +14,12 @@
  */
 package org.apache.geode.protocol.protobuf.operations;
 
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-
 import com.google.protobuf.ByteString;
-import org.hamcrest.CoreMatchers;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
 import org.apache.geode.cache.Region;
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.ClientProtocol;
 import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.ProtocolErrorCode;
 import org.apache.geode.protocol.protobuf.RegionAPI;
 import org.apache.geode.protocol.protobuf.Result;
 import org.apache.geode.protocol.protobuf.Success;
@@ -43,6 +30,18 @@ import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException
 import org.apache.geode.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
 import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
 import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.UnsupportedEncodingException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 @Category(UnitTest.class)
 public class RemoveRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTest {
@@ -90,8 +89,8 @@ public class RemoveRequestOperationHandlerJUnitTest extends OperationHandlerJUni
         operationHandler.process(serializationServiceStub, removeRequest, cacheStub);
 
     assertTrue(result instanceof Failure);
-    org.junit.Assert.assertThat(result.getErrorMessage().getMessage(),
-        CoreMatchers.containsString("Region"));
+    assertEquals(ProtocolErrorCode.REGION_NOT_FOUND.codeValue,
+        result.getErrorMessage().getErrorCode());
   }
 
   @Test
@@ -125,8 +124,8 @@ public class RemoveRequestOperationHandlerJUnitTest extends OperationHandlerJUni
         operationHandler.process(serializationServiceStub, removeRequest, cacheStub);
 
     assertTrue(result instanceof Failure);
-    org.junit.Assert.assertEquals("Codec error in protobuf deserialization.",
-        result.getErrorMessage().getMessage());
+    assertEquals(ProtocolErrorCode.VALUE_ENCODING_ERROR.codeValue,
+        result.getErrorMessage().getErrorCode());
   }
 
   private ClientProtocol.Request generateTestRequest(boolean missingRegion, boolean missingKey)


Mime
View raw message