You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2017/07/17 18:18:46 UTC
geode git commit: GEODE-3213: Initial refactor for Protobuf protocol
generic flow
Repository: geode
Updated Branches:
refs/heads/feature/GEODE-3213 [created] 2033ba7b4
GEODE-3213: Initial refactor for Protobuf protocol generic flow
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/2033ba7b
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/2033ba7b
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/2033ba7b
Branch: refs/heads/feature/GEODE-3213
Commit: 2033ba7b4198e9935fd0f4b40c708a359c4e4e65
Parents: 0bce1ea
Author: Udo Kohlmeyer <uk...@pivotal.io>
Authored: Mon Jul 17 11:18:57 2017 -0700
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Jul 17 11:18:57 2017 -0700
----------------------------------------------------------------------
.../protocol/operations/OperationHandler.java | 2 +
.../protocol/protobuf/ProtobufOpsProcessor.java | 80 +++++++++++++++++---
.../protobuf/ProtobufStreamProcessor.java | 37 ++-------
.../GetAllRequestOperationHandler.java | 34 ++++-----
.../GetRegionNamesRequestOperationHandler.java | 5 +-
.../operations/GetRequestOperationHandler.java | 36 ++++-----
.../PutAllRequestOperationHandler.java | 73 ++++++------------
.../operations/PutRequestOperationHandler.java | 46 +++++------
.../utilities/ProtobufRequestUtilities.java | 23 ++----
.../protobuf/utilities/ProtobufUtilities.java | 64 ++++++++++------
.../org/apache/geode/protocol/MessageUtil.java | 4 +-
.../RoundTripCacheConnectionJUnitTest.java | 62 ++++++++-------
.../protobuf/ProtobufOpsProcessorJUnitTest.java | 3 +-
.../GetAllRequestOperationHandlerJUnitTest.java | 43 +++++------
.../GetRequestOperationHandlerJUnitTest.java | 50 +++++-------
.../PutAllRequestOperationHandlerJUnitTest.java | 24 +++---
.../PutRequestOperationHandlerJUnitTest.java | 39 +++++-----
17 files changed, 317 insertions(+), 308 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
index 90fe177..2ebf2a3 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/operations/OperationHandler.java
@@ -15,6 +15,7 @@
package org.apache.geode.protocol.operations;
import org.apache.geode.cache.Cache;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
import org.apache.geode.protocol.protobuf.ProtobufOpsProcessor;
import org.apache.geode.serialization.SerializationService;
@@ -31,3 +32,4 @@ public interface OperationHandler<Req, Resp> {
*/
Resp process(SerializationService serializationService, Req request, Cache cache);
}
+
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
index 13f2b00..5e62c3d 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessor.java
@@ -15,32 +15,88 @@
package org.apache.geode.protocol.protobuf;
import org.apache.geode.cache.Cache;
-import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
import org.apache.geode.protocol.operations.OperationHandler;
-import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistry;
-import org.apache.geode.protocol.operations.registry.exception.OperationHandlerNotRegisteredException;
+import org.apache.geode.protocol.protobuf.operations.GetAllRequestOperationHandler;
+import org.apache.geode.protocol.protobuf.operations.GetRequestOperationHandler;
+import org.apache.geode.protocol.protobuf.operations.PutRequestOperationHandler;
import org.apache.geode.serialization.SerializationService;
+import java.util.HashMap;
+import java.util.function.Function;
+
/**
* This handles protobuf requests by determining the operation type of the request and dispatching
* it to the appropriate handler.
*/
public class ProtobufOpsProcessor {
- private final OperationsHandlerRegistry opsHandlerRegistry;
+
+ private HashMap<ClientProtocol.Request.RequestAPICase, Blah> operationHandlers = new HashMap<>();
private final SerializationService serializationService;
- public ProtobufOpsProcessor(OperationsHandlerRegistry opsHandlerRegistry,
- SerializationService serializationService) {
- this.opsHandlerRegistry = opsHandlerRegistry;
+ public ProtobufOpsProcessor(SerializationService serializationService) {
this.serializationService = serializationService;
+ addOperationHandlers();
}
- public ClientProtocol.Response process(ClientProtocol.Request request, Cache cache)
- throws OperationHandlerNotRegisteredException, InvalidProtocolMessageException {
+ public ClientProtocol.Response process(ClientProtocol.Request request, Cache cache) {
ClientProtocol.Request.RequestAPICase requestType = request.getRequestAPICase();
- OperationHandler opsHandler =
- opsHandlerRegistry.getOperationHandlerForOperationId(requestType.getNumber());
+ Blah blah = operationHandlers.get(requestType);
+
+ Object opResponse =
+ blah.opH.process(serializationService, blah.fromRequest.apply(request), cache);
+ ClientProtocol.Response.Builder builder =
+ (ClientProtocol.Response.Builder) blah.toResponse.apply(opResponse);
+ return builder.build();
+ }
+
+ private void addOperationHandlers(){
+// registry.registerOperationHandlerForOperationId(
+// ClientProtocol.Request.RequestAPICase.GETREQUEST,
+// new GetRequestOperationHandler());
+// registry.registerOperationHandlerForOperationId(
+// ClientProtocol.Request.RequestAPICase.PUTREQUEST,
+// new PutRequestOperationHandler());
+// registry.registerOperationHandlerForOperationId(
+// ClientProtocol.Request.RequestAPICase.GETREGIONNAMESREQUEST,
+// new GetRegionNamesRequestOperationHandler());
+// registry.registerOperationHandlerForOperationId(
+// ClientProtocol.Request.RequestAPICase.GETALLREQUEST,
+// new GetAllRequestOperationHandler());
+// registry.registerOperationHandlerForOperationId(
+// ClientProtocol.Request.RequestAPICase.PUTALLREQUEST,
+// new PutAllRequestOperationHandler());
+// registry.registerOperationHandlerForOperationId(
+// ClientProtocol.Request.RequestAPICase.REMOVEREQUEST,
+// new RemoveRequestOperationHandler());
+
+ operationHandlers.put(ClientProtocol.Request.RequestAPICase.GETALLREQUEST,
+ new Blah<>(new GetAllRequestOperationHandler(),
+ request -> request.getGetAllRequest(),
+ opsResp -> ClientProtocol.Response.newBuilder().setGetAllResponse(opsResp)));
+
+ operationHandlers.put(ClientProtocol.Request.RequestAPICase.PUTREQUEST,
+ new Blah<>(new PutRequestOperationHandler(),
+ request -> request.getPutRequest(),
+ opsResp -> ClientProtocol.Response.newBuilder().setPutResponse(opsResp)));
+
+ operationHandlers.put(ClientProtocol.Request.RequestAPICase.GETREQUEST,
+ new Blah<>(new GetRequestOperationHandler(),
+ request -> request.getGetRequest(),
+ opsResp -> ClientProtocol.Response.newBuilder().setGetResponse(opsResp)));
+ }
+
+ //TODO This needs to get a nicer name.
+ private class Blah<OperationReq, OpResp> {
+ private OperationHandler<OperationReq, OpResp> opH;
+ private Function<ClientProtocol.Request, OperationReq> fromRequest;
+ private Function<OpResp, ClientProtocol.Response.Builder> toResponse;
- return (ClientProtocol.Response) opsHandler.process(serializationService, request, cache);
+ public Blah(OperationHandler<OperationReq, OpResp> opH,
+ Function<ClientProtocol.Request, OperationReq> fromRequest,
+ Function<OpResp, ClientProtocol.Response.Builder> toResponse) {
+ this.opH = opH;
+ this.fromRequest = fromRequest;
+ this.toResponse = toResponse;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
index 980495a..6270c4c 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufStreamProcessor.java
@@ -37,44 +37,17 @@ import java.io.OutputStream;
* and then pushes it to the output stream.
*/
public class ProtobufStreamProcessor implements ClientProtocolMessageHandler {
- ProtobufProtocolSerializer protobufProtocolSerializer;
- OperationsHandlerRegistry registry;
- ProtobufSerializationService protobufSerializationService;
- ProtobufOpsProcessor protobufOpsProcessor;
+ private final ProtobufProtocolSerializer protobufProtocolSerializer;
+ private final ProtobufOpsProcessor protobufOpsProcessor;
public ProtobufStreamProcessor()
throws OperationHandlerAlreadyRegisteredException, CodecAlreadyRegisteredForTypeException {
protobufProtocolSerializer = new ProtobufProtocolSerializer();
- registry = new OperationsHandlerRegistry();
- addOperationHandlers(registry);
- protobufSerializationService = new ProtobufSerializationService();
- protobufOpsProcessor = new ProtobufOpsProcessor(registry, protobufSerializationService);
- }
-
- private void addOperationHandlers(OperationsHandlerRegistry registry)
- throws OperationHandlerAlreadyRegisteredException {
- registry.registerOperationHandlerForOperationId(
- ClientProtocol.Request.RequestAPICase.GETREQUEST.getNumber(),
- new GetRequestOperationHandler());
- registry.registerOperationHandlerForOperationId(
- ClientProtocol.Request.RequestAPICase.PUTREQUEST.getNumber(),
- new PutRequestOperationHandler());
- registry.registerOperationHandlerForOperationId(
- ClientProtocol.Request.RequestAPICase.GETREGIONNAMESREQUEST.getNumber(),
- new GetRegionNamesRequestOperationHandler());
- registry.registerOperationHandlerForOperationId(
- ClientProtocol.Request.RequestAPICase.GETALLREQUEST.getNumber(),
- new GetAllRequestOperationHandler());
- registry.registerOperationHandlerForOperationId(
- ClientProtocol.Request.RequestAPICase.PUTALLREQUEST.getNumber(),
- new PutAllRequestOperationHandler());
- registry.registerOperationHandlerForOperationId(
- ClientProtocol.Request.RequestAPICase.REMOVEREQUEST.getNumber(),
- new RemoveRequestOperationHandler());
+ protobufOpsProcessor = new ProtobufOpsProcessor(new ProtobufSerializationService());
}
public void processOneMessage(InputStream inputStream, OutputStream outputStream, Cache cache)
- throws InvalidProtocolMessageException, OperationHandlerNotRegisteredException, IOException {
+ throws InvalidProtocolMessageException, IOException {
ClientProtocol.Message message = protobufProtocolSerializer.deserialize(inputStream);
if (message == null) {
throw new EOFException("Tried to deserialize protobuf message at EOF");
@@ -94,7 +67,7 @@ public class ProtobufStreamProcessor implements ClientProtocolMessageHandler {
InternalCache cache) throws IOException {
try {
processOneMessage(inputStream, outputStream, cache);
- } catch (InvalidProtocolMessageException | OperationHandlerNotRegisteredException e) {
+ } catch (InvalidProtocolMessageException e) {
throw new IOException(e);
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/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 75ae842..c85bb58 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
@@ -33,27 +33,21 @@ import java.util.Map;
import java.util.Set;
public class GetAllRequestOperationHandler
- implements OperationHandler<ClientProtocol.Request, ClientProtocol.Response> {
+ implements OperationHandler<RegionAPI.GetAllRequest, RegionAPI.GetAllResponse> {
private static Logger logger = LogManager.getLogger();
@Override
- public ClientProtocol.Response process(SerializationService serializationService,
- ClientProtocol.Request request, Cache cache) {
- if (request.getRequestAPICase() != ClientProtocol.Request.RequestAPICase.GETALLREQUEST) {
- return ProtobufResponseUtilities
- .createAndLogErrorResponse("Improperly formatted getAll request message.", logger, null);
- }
- RegionAPI.GetAllRequest getAllRequest = request.getGetAllRequest();
-
- String regionName = getAllRequest.getRegionName();
+ public RegionAPI.GetAllResponse process(SerializationService serializationService,
+ RegionAPI.GetAllRequest request, Cache cache) {
+ String regionName = request.getRegionName();
Region region = cache.getRegion(regionName);
- if (region == null) {
- return ProtobufResponseUtilities.createErrorResponse("Region not found");
- }
+// if (region == null) {
+// return ProtobufResponseUtilities.createErrorResponse("Region not found");
+// }
try {
Set<Object> keys = new HashSet<>();
- for (BasicTypes.EncodedValue key : getAllRequest.getKeyList()) {
+ for (BasicTypes.EncodedValue key : request.getKeyList()) {
keys.add(ProtobufUtilities.decodeValue(serializationService, key));
}
Map<Object, Object> results = region.getAll(keys);
@@ -62,14 +56,16 @@ public class GetAllRequestOperationHandler
entries.add(
ProtobufUtilities.createEntry(serializationService, entry.getKey(), entry.getValue()));
}
- return ProtobufResponseUtilities.createGetAllResponse(entries);
+ return ProtobufResponseUtilities.createGetAllResponse(entries).getGetAllResponse();
} catch (UnsupportedEncodingTypeException ex) {
// can be thrown by encoding or decoding.
- return ProtobufResponseUtilities.createAndLogErrorResponse("Encoding not supported.", logger,
- ex);
+ return null;
+// return ProtobufResponseUtilities.createAndLogErrorResponse("Encoding not supported.", logger,
+// ex);
} catch (CodecNotRegisteredForTypeException ex) {
- return ProtobufResponseUtilities
- .createAndLogErrorResponse("Codec error in protobuf deserialization.", logger, ex);
+ return null;
+// return ProtobufResponseUtilities
+// .createAndLogErrorResponse("Codec error in protobuf deserialization.", logger, ex);
}
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRegionNamesRequestOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRegionNamesRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRegionNamesRequestOperationHandler.java
index 8befdd7..e0a11bf 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRegionNamesRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetRegionNamesRequestOperationHandler.java
@@ -18,16 +18,17 @@ import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
import org.apache.geode.protocol.operations.OperationHandler;
import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.RegionAPI;
import org.apache.geode.protocol.protobuf.utilities.ProtobufResponseUtilities;
import org.apache.geode.serialization.SerializationService;
import java.util.Set;
public class GetRegionNamesRequestOperationHandler
- implements OperationHandler<ClientProtocol.Request, ClientProtocol.Response> {
+ implements OperationHandler<RegionAPI.GetRegionNamesRequest, ClientProtocol.Response> {
@Override
public ClientProtocol.Response process(SerializationService serializationService,
- ClientProtocol.Request request, Cache cache) {
+ RegionAPI.GetRegionNamesRequest request, Cache cache) {
Set<Region<?, ?>> regions = cache.rootRegions();
return ProtobufResponseUtilities.createGetRegionNamesResponse(regions);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/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 d5bcfb9..e86b921 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
@@ -17,7 +17,8 @@ package org.apache.geode.protocol.protobuf.operations;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
import org.apache.geode.protocol.operations.OperationHandler;
-import org.apache.geode.protocol.protobuf.*;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.RegionAPI;
import org.apache.geode.protocol.protobuf.utilities.ProtobufResponseUtilities;
import org.apache.geode.protocol.protobuf.utilities.ProtobufUtilities;
import org.apache.geode.serialization.SerializationService;
@@ -27,42 +28,41 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class GetRequestOperationHandler
- implements OperationHandler<ClientProtocol.Request, ClientProtocol.Response> {
+ implements OperationHandler<RegionAPI.GetRequest, RegionAPI.GetResponse> {
private static Logger logger = LogManager.getLogger();
@Override
- public ClientProtocol.Response process(SerializationService serializationService,
- ClientProtocol.Request request, Cache cache) {
- if (request.getRequestAPICase() != ClientProtocol.Request.RequestAPICase.GETREQUEST) {
- return ProtobufResponseUtilities
- .createAndLogErrorResponse("Improperly formatted get request message.", logger, null);
- }
- RegionAPI.GetRequest getRequest = request.getGetRequest();
+ public RegionAPI.GetResponse process(SerializationService serializationService,
+ RegionAPI.GetRequest request, Cache cache) {
- String regionName = getRequest.getRegionName();
+ String regionName = request.getRegionName();
Region region = cache.getRegion(regionName);
if (region == null) {
- return ProtobufResponseUtilities.createErrorResponse("Region not found");
+ return null;
+// return ProtobufResponseUtilities.createErrorResponse("Region not found");
}
try {
- Object decodedKey = ProtobufUtilities.decodeValue(serializationService, getRequest.getKey());
+ Object decodedKey = ProtobufUtilities.decodeValue(serializationService, request.getKey());
Object resultValue = region.get(decodedKey);
if (resultValue == null) {
- return ProtobufResponseUtilities.createNullGetResponse();
+ return ProtobufResponseUtilities.createNullGetResponse().getGetResponse();
}
BasicTypes.EncodedValue encodedValue =
ProtobufUtilities.createEncodedValue(serializationService, resultValue);
- return ProtobufResponseUtilities.createGetResponse(encodedValue);
+ return ProtobufResponseUtilities.createGetResponse(encodedValue).getGetResponse();
} catch (UnsupportedEncodingTypeException ex) {
// can be thrown by encoding or decoding.
- return ProtobufResponseUtilities.createAndLogErrorResponse("Encoding not supported.", logger,
- ex);
+ return null;
+// return ProtobufResponseUtilities.createAndLogErrorResponse("Encoding not supported.", logger,
+// ex);
} catch (CodecNotRegisteredForTypeException ex) {
- return ProtobufResponseUtilities
- .createAndLogErrorResponse("Codec error in protobuf deserialization.", logger, ex);
+ return null;
+// return ProtobufResponseUtilities
+// .createAndLogErrorResponse("Codec error in protobuf deserialization.", logger, ex);
}
}
+
}
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/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 7e62bba..5d73a04 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
@@ -32,62 +32,37 @@ import java.util.HashMap;
import java.util.Map;
public class PutAllRequestOperationHandler
- implements OperationHandler<ClientProtocol.Request, ClientProtocol.Response> {
+ implements OperationHandler<RegionAPI.PutAllRequest, RegionAPI.PutAllResponse> {
private static Logger logger = LogManager.getLogger();
- private RegionAPI.PutAllRequest putAllRequest = null;
- private Region region = null;
- private Map<Object, Object> entries = null;
-
@Override
- public ClientProtocol.Response process(SerializationService serializationService,
- ClientProtocol.Request request, Cache cache) {
- ClientProtocol.Response errorResponse = validatePutAllRequest(request);
- if (errorResponse == null) {
- errorResponse = determinePutAllRegion(cache);
- }
- if (errorResponse == null) {
- errorResponse = extractPutAllEntries(serializationService);
- }
- if (errorResponse == null) {
- try {
- region.putAll(entries);
- } catch (Exception ex) {
- return ProtobufResponseUtilities.createAndLogErrorResponse(ex.getMessage(), logger, ex);
- }
+ public RegionAPI.PutAllResponse process(SerializationService serializationService,
+ RegionAPI.PutAllRequest request, Cache cache) {
+ String regionName = request.getRegionName();
+ Region region = cache.getRegion(regionName);
- return ProtobufResponseUtilities.createPutAllResponse();
- } else {
- return errorResponse;
+ if (region == null) {
+// return ProtobufResponseUtilities.createAndLogErrorResponse(
+// "Region passed by client did not exist: " + regionName, logger, null);
+ throw new RuntimeException("This exception still needs to be handled in an ErrorMessage");
}
- }
- private ClientProtocol.Response validatePutAllRequest(ClientProtocol.Request request) {
- if (request.getRequestAPICase() != ClientProtocol.Request.RequestAPICase.PUTALLREQUEST) {
- return ProtobufResponseUtilities
- .createAndLogErrorResponse("Improperly formatted put request message.", logger, null);
+ Map entries = extractPutAllEntries(serializationService, request);
+ try {
+ region.putAll(entries);
+ } catch (Exception ex) {
+// return ProtobufResponseUtilities.createAndLogErrorResponse(ex.getMessage(), logger, ex);
+ throw new RuntimeException("This exception still needs to be handled in an ErrorMessage");
}
- putAllRequest = request.getPutAllRequest();
- return null;
- }
-
- private ClientProtocol.Response determinePutAllRegion(Cache cache) {
- String regionName = putAllRequest.getRegionName();
- region = cache.getRegion(regionName);
-
- if (region == null) {
- return ProtobufResponseUtilities.createAndLogErrorResponse(
- "Region passed by client did not exist: " + regionName, logger, null);
- } else {
- return null;
- }
+ return ProtobufResponseUtilities.createPutAllResponse().getPutAllResponse();
}
// Read all of the entries out of the protobuf and return an error (without performing any puts)
// if any of the entries can't be decoded
- private ClientProtocol.Response extractPutAllEntries(SerializationService serializationService) {
- entries = new HashMap();
+ private Map extractPutAllEntries(SerializationService serializationService,
+ RegionAPI.PutAllRequest putAllRequest) {
+ Map entries = new HashMap();
try {
for (BasicTypes.Entry entry : putAllRequest.getEntryList()) {
Object decodedValue = ProtobufUtilities.decodeValue(serializationService, entry.getValue());
@@ -96,11 +71,13 @@ public class PutAllRequestOperationHandler
entries.put(decodedKey, decodedValue);
}
} catch (UnsupportedEncodingTypeException ex) {
- return ProtobufResponseUtilities.createAndLogErrorResponse("Encoding not supported ", logger,
- ex);
+// return ProtobufResponseUtilities.createAndLogErrorResponse("Encoding not supported ", logger,
+// ex);
+ throw new RuntimeException("This exception still needs to be handled in an ErrorMessage");
} catch (CodecNotRegisteredForTypeException ex) {
- return ProtobufResponseUtilities
- .createAndLogErrorResponse("Codec error in protobuf deserialization ", logger, ex);
+// return ProtobufResponseUtilities
+// .createAndLogErrorResponse("Codec error in protobuf deserialization ", logger, ex);
+ throw new RuntimeException("This exception still needs to be handled in an ErrorMessage");
}
return null;
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/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 195aa7a..c383bf7 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
@@ -17,7 +17,9 @@ package org.apache.geode.protocol.protobuf.operations;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
import org.apache.geode.protocol.operations.OperationHandler;
-import org.apache.geode.protocol.protobuf.*;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.RegionAPI;
import org.apache.geode.protocol.protobuf.utilities.ProtobufResponseUtilities;
import org.apache.geode.protocol.protobuf.utilities.ProtobufUtilities;
import org.apache.geode.serialization.SerializationService;
@@ -27,45 +29,43 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class PutRequestOperationHandler
- implements OperationHandler<ClientProtocol.Request, ClientProtocol.Response> {
+ implements OperationHandler<RegionAPI.PutRequest, RegionAPI.PutResponse> {
private static Logger logger = LogManager.getLogger();
@Override
- public ClientProtocol.Response process(SerializationService serializationService,
- ClientProtocol.Request request, Cache cache) {
- if (request.getRequestAPICase() != ClientProtocol.Request.RequestAPICase.PUTREQUEST) {
- return ProtobufResponseUtilities
- .createAndLogErrorResponse("Improperly formatted put request message.", logger, null);
- }
- RegionAPI.PutRequest putRequest = request.getPutRequest();
-
- String regionName = putRequest.getRegionName();
+ public RegionAPI.PutResponse process(SerializationService serializationService,
+ RegionAPI.PutRequest request, Cache cache) {
+ String regionName = request.getRegionName();
Region region = cache.getRegion(regionName);
if (region == null) {
- return ProtobufResponseUtilities.createAndLogErrorResponse(
- "Region passed by client did not exist: " + regionName, logger, null);
+// return ProtobufResponseUtilities.createAndLogErrorResponse(
+// "Region passed by client did not exist: " + regionName, logger, null);
+ return null;
}
try {
- BasicTypes.Entry entry = putRequest.getEntry();
+ BasicTypes.Entry entry = request.getEntry();
Object decodedValue = ProtobufUtilities.decodeValue(serializationService, entry.getValue());
Object decodedKey = ProtobufUtilities.decodeValue(serializationService, entry.getKey());
try {
region.put(decodedKey, decodedValue);
- return ProtobufResponseUtilities.createPutResponse();
+ return ProtobufResponseUtilities.createPutResponse().getPutResponse();
} catch (ClassCastException ex) {
- return ProtobufResponseUtilities
- .createAndLogErrorResponse("invalid key or value type for region " + regionName
- + ",passed key: " + entry.getKey().getEncodingType() + " value: "
- + entry.getValue().getEncodingType(), logger, ex);
+ return null;
+// return ProtobufResponseUtilities
+// .createAndLogErrorResponse("invalid key or value type for region " + regionName
+// + ",passed key: " + entry.getKey().getEncodingType() + " value: "
+// + entry.getValue().getEncodingType(), logger, ex);
}
} catch (UnsupportedEncodingTypeException ex) {
- return ProtobufResponseUtilities.createAndLogErrorResponse("encoding not supported ", logger,
- ex);
+ return null;
+// return ProtobufResponseUtilities.createAndLogErrorResponse("encoding not supported ", logger,
+// ex);
} catch (CodecNotRegisteredForTypeException ex) {
- return ProtobufResponseUtilities
- .createAndLogErrorResponse("codec error in protobuf deserialization ", logger, ex);
+ return null;
+// return ProtobufResponseUtilities
+// .createAndLogErrorResponse("codec error in protobuf deserialization ", logger, ex);
}
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufRequestUtilities.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufRequestUtilities.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufRequestUtilities.java
index b0f4795..b6e7c28 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufRequestUtilities.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufRequestUtilities.java
@@ -29,13 +29,12 @@ import java.util.Set;
public abstract class ProtobufRequestUtilities {
/**
* Creates a request object containing a RegionAPI.GetRequest
- *
* @param regionName - Name of the region being fetched from
* @param key - Encoded key, see createEncodedValue in {@link ProtobufRequestUtilities}
* @return Request object containing the passed params.
*/
public static ClientProtocol.Request createGetRequest(String regionName,
- BasicTypes.EncodedValue key) {
+ BasicTypes.EncodedValue key) {
RegionAPI.GetRequest getRequest =
RegionAPI.GetRequest.newBuilder().setRegionName(regionName).setKey(key).build();
return ClientProtocol.Request.newBuilder().setGetRequest(getRequest).build();
@@ -43,13 +42,12 @@ public abstract class ProtobufRequestUtilities {
/**
* Creates a request object containing a RegionAPI.RemoveRequest
- *
* @param regionName - Name of the region being deleted from
* @param key - Encoded key, see createEncodedValue in {@link ProtobufRequestUtilities}
* @return Request object containing the passed params.
*/
public static ClientProtocol.Request createRemoveRequest(String regionName,
- BasicTypes.EncodedValue key) {
+ BasicTypes.EncodedValue key) {
RegionAPI.RemoveRequest removeRequest =
RegionAPI.RemoveRequest.newBuilder().setRegionName(regionName).setKey(key).build();
return ClientProtocol.Request.newBuilder().setRemoveRequest(removeRequest).build();
@@ -57,17 +55,14 @@ public abstract class ProtobufRequestUtilities {
/**
* Creates a request object containing a RegionAPI.GetRegionNamesRequest
- *
* @return Request object for a getRegionNames operation
*/
- public static ClientProtocol.Request createGetRegionNamesRequest() {
- return ClientProtocol.Request.newBuilder()
- .setGetRegionNamesRequest(RegionAPI.GetRegionNamesRequest.newBuilder()).build();
+ public static RegionAPI.GetRegionNamesRequest createGetRegionNamesRequest() {
+ return RegionAPI.GetRegionNamesRequest.newBuilder().build();
}
/**
* Creates a request object containing a RegionAPI.PutRequest
- *
* @param region - Name of the region to put data in
* @param entry - Encoded key,value pair, see createEntry in {@link ProtobufRequestUtilities}
* @return Request object containing the passed params.
@@ -80,28 +75,26 @@ public abstract class ProtobufRequestUtilities {
/**
* Create a request to get the values for multiple keys
- *
* @param regionName - Name of the region to fetch from
* @param keys - Set of keys being fetched
* @return Request object containing the getAll request
*/
- public static ClientProtocol.Request createGetAllRequest(String regionName,
- Set<BasicTypes.EncodedValue> keys) {
+ public static RegionAPI.GetAllRequest createGetAllRequest(String regionName,
+ Set<BasicTypes.EncodedValue> keys) {
RegionAPI.GetAllRequest.Builder getAllRequestBuilder =
RegionAPI.GetAllRequest.newBuilder().setRegionName(regionName);
getAllRequestBuilder.addAllKey(keys);
- return ClientProtocol.Request.newBuilder().setGetAllRequest(getAllRequestBuilder).build();
+ return getAllRequestBuilder.build();
}
/**
* Create a request to insert multiple entries in a region
- *
* @param regionName - Region to which entries are being added
* @param entries - key, value pairs to add to the region
* @return Request object containing the putAll request for the passed parameters
*/
public static ClientProtocol.Request createPutAllRequest(String regionName,
- Set<BasicTypes.Entry> entries) {
+ Set<BasicTypes.Entry> entries) {
RegionAPI.PutAllRequest.Builder putAllRequestBuilder =
RegionAPI.PutAllRequest.newBuilder().setRegionName(regionName);
putAllRequestBuilder.addAllEntry(entries);
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufUtilities.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufUtilities.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufUtilities.java
index b632037..dfebc56 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufUtilities.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufUtilities.java
@@ -15,7 +15,12 @@
package org.apache.geode.protocol.protobuf.utilities;
import com.google.protobuf.ByteString;
-import org.apache.geode.protocol.protobuf.*;
+
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.EncodingTypeTranslator;
+import org.apache.geode.protocol.protobuf.ProtobufSerializationService;
+import org.apache.geode.protocol.protobuf.RegionAPI;
import org.apache.geode.serialization.SerializationService;
import org.apache.geode.serialization.exception.UnsupportedEncodingTypeException;
import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTypeException;
@@ -25,22 +30,21 @@ import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTy
* mainly focused on helper functions which can be used in building BasicTypes for use in other
* messages or those used to create the top level Message objects.
*
- * Helper functions specific to creating ClientProtocol.Responses can be found at
- * {@link ProtobufResponseUtilities} Helper functions specific to creating ClientProtocol.Requests
- * can be found at {@link ProtobufRequestUtilities}
+ * Helper functions specific to creating ClientProtocol.Responses can be found at {@link
+ * ProtobufResponseUtilities} Helper functions specific to creating ClientProtocol.Requests can be
+ * found at {@link ProtobufRequestUtilities}
*/
public abstract class ProtobufUtilities {
/**
* Creates a object containing the type and value encoding of a piece of data
- *
* @param serializationService - object which knows how to encode objects for the protobuf
- * protocol {@link ProtobufSerializationService}
+ * protocol {@link ProtobufSerializationService}
* @param unencodedValue - the value object which is to be encoded
* @return a protobuf EncodedValue object
* @throws UnsupportedEncodingTypeException - The object passed doesn't have a corresponding
- * SerializationType
+ * SerializationType
* @throws CodecNotRegisteredForTypeException - There isn't a protobuf codec for the
- * SerializationType of the passed object
+ * SerializationType of the passed object
*/
public static BasicTypes.EncodedValue createEncodedValue(
SerializationService serializationService, Object unencodedValue)
@@ -54,31 +58,29 @@ public abstract class ProtobufUtilities {
/**
* Creates a protobuf key,value pair from an encoded key and value
- *
* @param key - an EncodedValue containing the key of the entry
* @param value - an EncodedValue containing the value of the entry
* @return a protobuf Entry object containing the passed key and value
*/
public static BasicTypes.Entry createEntry(BasicTypes.EncodedValue key,
- BasicTypes.EncodedValue value) {
+ BasicTypes.EncodedValue value) {
return BasicTypes.Entry.newBuilder().setKey(key).setValue(value).build();
}
/**
* Creates a protobuf key,value pair from unencoded data
- *
* @param serializationService - object which knows how to encode objects for the protobuf
- * protocol {@link ProtobufSerializationService}
+ * protocol {@link ProtobufSerializationService}
* @param unencodedKey - the unencoded key for the entry
* @param unencodedValue - the unencoded value for the entry
* @return a protobuf Entry containing the encoded key and value
* @throws UnsupportedEncodingTypeException - The key or value passed doesn't have a corresponding
- * SerializationType
+ * SerializationType
* @throws CodecNotRegisteredForTypeException - There isn't a protobuf codec for the
- * SerializationType of the passed key or value
+ * SerializationType of the passed key or value
*/
public static BasicTypes.Entry createEntry(SerializationService serializationService,
- Object unencodedKey, Object unencodedValue)
+ Object unencodedKey, Object unencodedValue)
throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
return createEntry(createEncodedValue(serializationService, unencodedKey),
createEncodedValue(serializationService, unencodedValue));
@@ -86,7 +88,6 @@ public abstract class ProtobufUtilities {
/**
* This creates a protobuf message containing a ClientProtocol.Response
- *
* @param messageHeader - The header for the message
* @param response - The response for the message
* @return a protobuf Message containing the above parameters
@@ -99,20 +100,29 @@ public abstract class ProtobufUtilities {
/**
* This creates a protobuf message containing a ClientProtocol.Request
- *
* @param messageHeader - The header for the message
* @param request - The request for the message
* @return a protobuf Message containing the above parameters
*/
- public static ClientProtocol.Message createProtobufRequest(
+ public static ClientProtocol.Message createProtobufMessage(
ClientProtocol.MessageHeader messageHeader, ClientProtocol.Request request) {
return ClientProtocol.Message.newBuilder().setMessageHeader(messageHeader).setRequest(request)
.build();
}
/**
+ * This creates a protobuf message containing a ClientProtocol.Request
+ * @param messageHeader - The header for the message
+ * @param request - The request for the message
+ * @return a protobuf Message containing the above parameters
+ */
+ public static ClientProtocol.Request createProtobufRequestWithGetAllRequest(
+ RegionAPI.GetAllRequest getAllRequest) {
+ return ClientProtocol.Request.newBuilder().setGetAllRequest(getAllRequest).build();
+ }
+
+ /**
* This builds the MessageHeader for a response which matches an incoming request
- *
* @param request - The request message that we're responding to.
* @return the MessageHeader the response to the passed request
*/
@@ -123,7 +133,6 @@ public abstract class ProtobufUtilities {
/**
* This creates a MessageHeader
- *
* @param correlationId - An identifier used to correlate requests and responses
* @return a MessageHeader containing the above parameters
*/
@@ -133,21 +142,26 @@ public abstract class ProtobufUtilities {
/**
* This will return the object encoded in a protobuf EncodedValue
- *
* @param serializationService - object which knows how to encode objects for the protobuf
- * protocol {@link ProtobufSerializationService}
+ * protocol {@link ProtobufSerializationService}
* @param encodedValue - The value to be decoded
* @return the object encoded in the passed encodedValue
* @throws UnsupportedEncodingTypeException - There isn't a SerializationType matching the
- * encodedValues type
+ * encodedValues type
* @throws CodecNotRegisteredForTypeException - There isn't a protobuf codec for the
- * SerializationType matching the encodedValues type
+ * SerializationType matching the encodedValues type
*/
public static Object decodeValue(SerializationService serializationService,
- BasicTypes.EncodedValue encodedValue)
+ BasicTypes.EncodedValue encodedValue)
throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
BasicTypes.EncodingType encoding = encodedValue.getEncodingType();
byte[] bytes = encodedValue.getValue().toByteArray();
return serializationService.decode(encoding, bytes);
}
+
+ public static ClientProtocol.Request createProtobufRequestWithGetRegionNamesRequest(
+ RegionAPI.GetRegionNamesRequest getRegionNamesRequest) {
+ return ClientProtocol.Request.newBuilder().setGetRegionNamesRequest(getRegionNamesRequest)
+ .build();
+ }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/geode-protobuf/src/test/java/org/apache/geode/protocol/MessageUtil.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/MessageUtil.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/MessageUtil.java
index 174ccfa..cd1d224 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/MessageUtil.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/MessageUtil.java
@@ -43,7 +43,7 @@ public class MessageUtil {
ClientProtocol.Request request =
ProtobufRequestUtilities.createPutRequest(requestRegion, entry);
- return ProtobufUtilities.createProtobufRequest(header, request);
+ return ProtobufUtilities.createProtobufMessage(header, request);
}
public static ClientProtocol.Message makeGetRequestMessage(
@@ -52,7 +52,7 @@ public class MessageUtil {
UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
ClientProtocol.Request request = ProtobufRequestUtilities.createGetRequest(requestRegion,
ProtobufUtilities.createEncodedValue(serializationService, requestKey));
- return ProtobufUtilities.createProtobufRequest(header, request);
+ return ProtobufUtilities.createProtobufMessage(header, request);
}
private static ClientProtocol.Request.Builder getRequestBuilder() {
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/geode-protobuf/src/test/java/org/apache/geode/protocol/RoundTripCacheConnectionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/RoundTripCacheConnectionJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/RoundTripCacheConnectionJUnitTest.java
index 74c1b0e..a98f876 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/RoundTripCacheConnectionJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/RoundTripCacheConnectionJUnitTest.java
@@ -15,6 +15,16 @@
package org.apache.geode.protocol;
+import static org.apache.geode.distributed.ConfigurationProperties.SSL_ENABLED_COMPONENTS;
+import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE;
+import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_PASSWORD;
+import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_TYPE;
+import static org.apache.geode.distributed.ConfigurationProperties.SSL_REQUIRE_AUTHENTICATION;
+import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE;
+import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE_PASSWORD;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.RegionFactory;
@@ -57,19 +67,8 @@ import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-import static org.apache.geode.distributed.ConfigurationProperties.SSL_ENABLED_COMPONENTS;
-import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE;
-import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_PASSWORD;
-import static org.apache.geode.distributed.ConfigurationProperties.SSL_KEYSTORE_TYPE;
-import static org.apache.geode.distributed.ConfigurationProperties.SSL_REQUIRE_AUTHENTICATION;
-import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE;
-import static org.apache.geode.distributed.ConfigurationProperties.SSL_TRUSTSTORE_PASSWORD;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
/**
- * Test that switching on the header byte makes instances of
- * {@link GenericProtocolServerConnection}.
+ * Test that switching on the header byte makes instances of {@link GenericProtocolServerConnection}.
*/
@Category(IntegrationTest.class)
public class RoundTripCacheConnectionJUnitTest {
@@ -178,7 +177,7 @@ public class RoundTripCacheConnectionJUnitTest {
TEST_MULTIOP_VALUE2));
putEntries.add(ProtobufUtilities.createEntry(serializationService, TEST_MULTIOP_KEY3,
TEST_MULTIOP_VALUE3));
- ClientProtocol.Message putAllMessage = ProtobufUtilities.createProtobufRequest(
+ ClientProtocol.Message putAllMessage = ProtobufUtilities.createProtobufMessage(
ProtobufUtilities.createMessageHeader(TEST_PUT_CORRELATION_ID),
ProtobufRequestUtilities.createPutAllRequest(TEST_REGION, putEntries));
protobufProtocolSerializer.serialize(putAllMessage, outputStream);
@@ -189,9 +188,13 @@ public class RoundTripCacheConnectionJUnitTest {
getEntries.add(ProtobufUtilities.createEncodedValue(serializationService, TEST_MULTIOP_KEY1));
getEntries.add(ProtobufUtilities.createEncodedValue(serializationService, TEST_MULTIOP_KEY2));
getEntries.add(ProtobufUtilities.createEncodedValue(serializationService, TEST_MULTIOP_KEY3));
- ClientProtocol.Message getAllMessage = ProtobufUtilities.createProtobufRequest(
+
+ RegionAPI.GetAllRequest getAllRequest =
+ ProtobufRequestUtilities.createGetAllRequest(TEST_REGION, getEntries);
+
+ ClientProtocol.Message getAllMessage = ProtobufUtilities.createProtobufMessage(
ProtobufUtilities.createMessageHeader(TEST_GET_CORRELATION_ID),
- ProtobufRequestUtilities.createGetAllRequest(TEST_REGION, getEntries));
+ ProtobufUtilities.createProtobufRequestWithGetAllRequest(getAllRequest));
protobufProtocolSerializer.serialize(getAllMessage, outputStream);
validateGetAllResponse(socket, protobufProtocolSerializer);
}
@@ -217,7 +220,7 @@ public class RoundTripCacheConnectionJUnitTest {
TEST_MULTIOP_VALUE2));
putEntries.add(ProtobufUtilities.createEntry(serializationService, TEST_MULTIOP_KEY3,
TEST_MULTIOP_VALUE3));
- ClientProtocol.Message putAllMessage = ProtobufUtilities.createProtobufRequest(
+ ClientProtocol.Message putAllMessage = ProtobufUtilities.createProtobufMessage(
ProtobufUtilities.createMessageHeader(TEST_PUT_CORRELATION_ID),
ProtobufRequestUtilities.createPutAllRequest(regionName, putEntries));
protobufProtocolSerializer.serialize(putAllMessage, outputStream);
@@ -229,7 +232,7 @@ public class RoundTripCacheConnectionJUnitTest {
protobufProtocolSerializer.serialize(getMessage, outputStream);
validateGetResponse(socket, protobufProtocolSerializer, TEST_MULTIOP_VALUE1);
- ClientProtocol.Message removeMessage = ProtobufUtilities.createProtobufRequest(
+ ClientProtocol.Message removeMessage = ProtobufUtilities.createProtobufMessage(
ProtobufUtilities.createMessageHeader(TEST_REMOVE_CORRELATION_ID),
ProtobufRequestUtilities.createRemoveRequest(TEST_REGION,
ProtobufUtilities.createEncodedValue(serializationService, TEST_KEY)));
@@ -266,9 +269,12 @@ public class RoundTripCacheConnectionJUnitTest {
int correlationId = TEST_GET_CORRELATION_ID; // reuse this value for this test
ProtobufProtocolSerializer protobufProtocolSerializer = new ProtobufProtocolSerializer();
- ClientProtocol.Message getRegionsMessage = ProtobufUtilities.createProtobufRequest(
+ RegionAPI.GetRegionNamesRequest getRegionNamesRequest =
+ ProtobufRequestUtilities.createGetRegionNamesRequest();
+
+ ClientProtocol.Message getRegionsMessage = ProtobufUtilities.createProtobufMessage(
ProtobufUtilities.createMessageHeader(correlationId),
- ProtobufRequestUtilities.createGetRegionNamesRequest());
+ ProtobufUtilities.createProtobufRequestWithGetRegionNamesRequest(getRegionNamesRequest));
protobufProtocolSerializer.serialize(getRegionsMessage, outputStream);
validateGetRegionNamesResponse(socket, correlationId, protobufProtocolSerializer);
}
@@ -279,7 +285,8 @@ public class RoundTripCacheConnectionJUnitTest {
}
private void validatePutResponse(Socket socket,
- ProtobufProtocolSerializer protobufProtocolSerializer) throws Exception {
+ ProtobufProtocolSerializer protobufProtocolSerializer)
+ throws Exception {
ClientProtocol.Message message =
protobufProtocolSerializer.deserialize(socket.getInputStream());
assertEquals(TEST_PUT_CORRELATION_ID, message.getMessageHeader().getCorrelationId());
@@ -290,7 +297,8 @@ public class RoundTripCacheConnectionJUnitTest {
}
private void validateGetResponse(Socket socket,
- ProtobufProtocolSerializer protobufProtocolSerializer, Object expectedValue)
+ ProtobufProtocolSerializer protobufProtocolSerializer,
+ Object expectedValue)
throws InvalidProtocolMessageException, IOException, UnsupportedEncodingTypeException,
CodecNotRegisteredForTypeException, CodecAlreadyRegisteredForTypeException {
ClientProtocol.Message message =
@@ -308,7 +316,7 @@ public class RoundTripCacheConnectionJUnitTest {
}
private void validateGetRegionNamesResponse(Socket socket, int correlationId,
- ProtobufProtocolSerializer protobufProtocolSerializer)
+ ProtobufProtocolSerializer protobufProtocolSerializer)
throws InvalidProtocolMessageException, IOException {
ClientProtocol.Message message =
protobufProtocolSerializer.deserialize(socket.getInputStream());
@@ -323,8 +331,9 @@ public class RoundTripCacheConnectionJUnitTest {
}
private void validatePutAllResponse(Socket socket,
- ProtobufProtocolSerializer protobufProtocolSerializer,
- ClientProtocol.Response.ResponseAPICase responseCase) throws Exception {
+ ProtobufProtocolSerializer protobufProtocolSerializer,
+ ClientProtocol.Response.ResponseAPICase responseCase)
+ throws Exception {
ClientProtocol.Message message =
protobufProtocolSerializer.deserialize(socket.getInputStream());
assertEquals(TEST_PUT_CORRELATION_ID, message.getMessageHeader().getCorrelationId());
@@ -334,7 +343,7 @@ public class RoundTripCacheConnectionJUnitTest {
}
private void validateGetAllResponse(Socket socket,
- ProtobufProtocolSerializer protobufProtocolSerializer)
+ ProtobufProtocolSerializer protobufProtocolSerializer)
throws InvalidProtocolMessageException, IOException, UnsupportedEncodingTypeException,
CodecNotRegisteredForTypeException, CodecAlreadyRegisteredForTypeException {
ClientProtocol.Message message =
@@ -367,7 +376,8 @@ public class RoundTripCacheConnectionJUnitTest {
}
private void validateRemoveResponse(Socket socket,
- ProtobufProtocolSerializer protobufProtocolSerializer) throws Exception {
+ ProtobufProtocolSerializer protobufProtocolSerializer)
+ throws Exception {
ClientProtocol.Message message =
protobufProtocolSerializer.deserialize(socket.getInputStream());
assertEquals(TEST_REMOVE_CORRELATION_ID, message.getMessageHeader().getCorrelationId());
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorJUnitTest.java
index f2a76b9..8b3c6e5 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufOpsProcessorJUnitTest.java
@@ -51,8 +51,7 @@ public class ProtobufOpsProcessorJUnitTest {
when(operationHandlerStub.process(serializationServiceStub, messageRequest, dummyCache))
.thenReturn(expectedResponse);
- ProtobufOpsProcessor processor =
- new ProtobufOpsProcessor(opsHandlerRegistryStub, serializationServiceStub);
+ ProtobufOpsProcessor processor = new ProtobufOpsProcessor(serializationServiceStub);
ClientProtocol.Response response = processor.process(messageRequest, dummyCache);
Assert.assertEquals(expectedResponse, response);
}
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandlerJUnitTest.java
index 0e716fb..b50a616 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetAllRequestOperationHandlerJUnitTest.java
@@ -14,10 +14,13 @@
*/
package org.apache.geode.protocol.protobuf.operations;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
+import org.apache.geode.protocol.operations.registry.OperationsHandlerRegistryJUnitTest;
import org.apache.geode.protocol.protobuf.BasicTypes;
-import org.apache.geode.protocol.protobuf.ClientProtocol;
import org.apache.geode.protocol.protobuf.RegionAPI;
import org.apache.geode.protocol.protobuf.utilities.ProtobufRequestUtilities;
import org.apache.geode.protocol.protobuf.utilities.ProtobufUtilities;
@@ -33,13 +36,13 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.nio.charset.Charset;
-import java.util.*;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
@Category(UnitTest.class)
-public class GetAllRequestOperationHandlerJUnitTest {
+public class GetAllRequestOperationHandlerJUnitTest extends OperationsHandlerRegistryJUnitTest {
private static final String TEST_KEY1 = "my key1";
private static final String TEST_VALUE1 = "my value1";
private static final String TEST_KEY2 = "my key2";
@@ -84,7 +87,7 @@ public class GetAllRequestOperationHandlerJUnitTest {
}
private void addStringMockEncoding(SerializationService mock, String s, boolean add_encoding,
- boolean add_decoding) throws Exception {
+ boolean add_decoding) throws Exception {
if (add_encoding) {
when(mock.encode(BasicTypes.EncodingType.STRING, s))
.thenReturn(s.getBytes(Charset.forName("UTF-8")));
@@ -99,16 +102,13 @@ public class GetAllRequestOperationHandlerJUnitTest {
public void processReturnsExpectedValuesForValidKeys()
throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
CodecNotRegisteredForTypeException {
- ClientProtocol.Request getRequest = generateTestRequest(true);
- ClientProtocol.Response response =
- operationHandler.process(serializationServiceStub, getRequest, cacheStub);
+ RegionAPI.GetAllResponse response =
+ operationHandler.process(serializationServiceStub, generateTestRequest(true), cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.GETALLRESPONSE,
- response.getResponseAPICase());
- RegionAPI.GetAllResponse getAllResponse = response.getGetAllResponse();
- Assert.assertEquals(3, getAllResponse.getEntriesCount());
+ Assert.assertNotNull(response);
+ Assert.assertEquals(3, response.getEntriesCount());
- List<BasicTypes.Entry> entriesList = getAllResponse.getEntriesList();
+ List<BasicTypes.Entry> entriesList = response.getEntriesList();
Map<String, String> responseEntries = convertEntryListToMap(entriesList);
Assert.assertEquals(TEST_VALUE1, responseEntries.get(TEST_KEY1));
@@ -119,20 +119,17 @@ public class GetAllRequestOperationHandlerJUnitTest {
@Test
public void processReturnsNoEntriesForNoKeysRequested()
throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- ClientProtocol.Request getRequest = generateTestRequest(false);
- ClientProtocol.Response response =
- operationHandler.process(serializationServiceStub, getRequest, cacheStub);
+ RegionAPI.GetAllResponse response =
+ operationHandler.process(serializationServiceStub, generateTestRequest(false), cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.GETALLRESPONSE,
- response.getResponseAPICase());
+ Assert.assertNotNull(response);
- RegionAPI.GetAllResponse getAllResponse = response.getGetAllResponse();
- List<BasicTypes.Entry> entriesList = getAllResponse.getEntriesList();
+ List<BasicTypes.Entry> entriesList = response.getEntriesList();
Map<String, String> responseEntries = convertEntryListToMap(entriesList);
Assert.assertEquals(0, responseEntries.size());
}
- private ClientProtocol.Request generateTestRequest(boolean addKeys)
+ private RegionAPI.GetAllRequest generateTestRequest(boolean addKeys)
throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
HashSet<BasicTypes.EncodedValue> testKeys = new HashSet<>();
if (addKeys) {
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/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 2f2e47e..d12d0d9 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
@@ -86,15 +86,13 @@ public class GetRequestOperationHandlerJUnitTest {
public void processReturnsTheEncodedValueFromTheRegion()
throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
CodecNotRegisteredForTypeException {
- ClientProtocol.Request getRequest = generateTestRequest(false, false, false);
- ClientProtocol.Response response =
+ RegionAPI.GetRequest getRequest = generateTestRequest(false, false, false);
+ RegionAPI.GetResponse response =
operationHandler.process(serializationServiceStub, getRequest, cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.GETRESPONSE,
- response.getResponseAPICase());
- RegionAPI.GetResponse getResponse = response.getGetResponse();
- Assert.assertEquals(BasicTypes.EncodingType.STRING, getResponse.getResult().getEncodingType());
- String actualValue = stringDecoder.decode(getResponse.getResult().getValue().toByteArray());
+ Assert.assertNotNull(response);
+ Assert.assertEquals(BasicTypes.EncodingType.STRING, response.getResult().getEncodingType());
+ String actualValue = stringDecoder.decode(response.getResult().getValue().toByteArray());
Assert.assertEquals(TEST_VALUE, actualValue);
}
@@ -102,40 +100,35 @@ public class GetRequestOperationHandlerJUnitTest {
public void processReturnsUnsucessfulResponseForInvalidRegion()
throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
CodecNotRegisteredForTypeException {
- ClientProtocol.Request getRequest = generateTestRequest(true, false, false);
- ClientProtocol.Response response =
+ RegionAPI.GetRequest getRequest = generateTestRequest(true, false, false);
+ RegionAPI.GetResponse response =
operationHandler.process(serializationServiceStub, getRequest, cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
- response.getResponseAPICase());
+ Assert.assertNull(response);
}
@Test
public void processReturnsKeyNotFoundWhenKeyIsNotFound()
throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
CodecNotRegisteredForTypeException {
- ClientProtocol.Request getRequest = generateTestRequest(false, true, false);
- ClientProtocol.Response response =
+ RegionAPI.GetRequest getRequest = generateTestRequest(false, true, false);
+ RegionAPI.GetResponse response =
operationHandler.process(serializationServiceStub, getRequest, cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.GETRESPONSE,
- response.getResponseAPICase());
- RegionAPI.GetResponse getResponse = response.getGetResponse();
- Assert.assertFalse(getResponse.hasResult());
+ Assert.assertNotNull(response);
+ Assert.assertFalse(response.hasResult());
}
@Test
public void processReturnsLookupFailureWhenKeyFoundWithNoValue()
throws CodecAlreadyRegisteredForTypeException, UnsupportedEncodingTypeException,
CodecNotRegisteredForTypeException {
- ClientProtocol.Request getRequest = generateTestRequest(false, false, true);
- ClientProtocol.Response response =
+ RegionAPI.GetRequest getRequest = generateTestRequest(false, false, true);
+ RegionAPI.GetResponse response =
operationHandler.process(serializationServiceStub, getRequest, cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.GETRESPONSE,
- response.getResponseAPICase());
- RegionAPI.GetResponse getResponse = response.getGetResponse();
- Assert.assertFalse(getResponse.hasResult());
+ Assert.assertNotNull(response);
+ Assert.assertFalse(response.hasResult());
}
@Test
@@ -147,21 +140,20 @@ public class GetRequestOperationHandlerJUnitTest {
when(serializationServiceStub.decode(BasicTypes.EncodingType.STRING,
TEST_KEY.getBytes(Charset.forName("UTF-8")))).thenThrow(exception);
- ClientProtocol.Request getRequest = generateTestRequest(false, false, false);
- ClientProtocol.Response response =
+ RegionAPI.GetRequest getRequest = generateTestRequest(false, false, false);
+ RegionAPI.GetResponse response =
operationHandler.process(serializationServiceStub, getRequest, cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
- response.getResponseAPICase());
+ Assert.assertNull(response);
}
- private ClientProtocol.Request generateTestRequest(boolean missingRegion, boolean missingKey,
+ private RegionAPI.GetRequest generateTestRequest(boolean missingRegion, boolean missingKey,
boolean nulledKey)
throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
String region = missingRegion ? MISSING_REGION : TEST_REGION;
String key = missingKey ? MISSING_KEY : (nulledKey ? NULLED_KEY : TEST_KEY);
BasicTypes.EncodedValue testKey =
ProtobufUtilities.createEncodedValue(serializationServiceStub, key);
- return ProtobufRequestUtilities.createGetRequest(region, testKey);
+ return ProtobufRequestUtilities.createGetRequest(region, testKey).getGetRequest();
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/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 1b9648e..0a345cf 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
@@ -18,6 +18,7 @@ import org.apache.geode.cache.Cache;
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.RegionAPI;
import org.apache.geode.protocol.protobuf.utilities.ProtobufRequestUtilities;
import org.apache.geode.protocol.protobuf.utilities.ProtobufUtilities;
import org.apache.geode.serialization.SerializationService;
@@ -101,11 +102,10 @@ public class PutAllRequestOperationHandlerJUnitTest {
CodecNotRegisteredForTypeException, CodecAlreadyRegisteredForTypeException {
PutAllRequestOperationHandler operationHandler = new PutAllRequestOperationHandler();
- ClientProtocol.Response response = operationHandler.process(serializationServiceStub,
+ RegionAPI.PutAllResponse response = operationHandler.process(serializationServiceStub,
generateTestRequest(false, true), cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.PUTALLRESPONSE,
- response.getResponseAPICase());
+ Assert.assertNotNull(response);
HashMap<Object, Object> expectedValues = new HashMap<>();
expectedValues.put(TEST_KEY1, TEST_VALUE1);
@@ -119,13 +119,12 @@ public class PutAllRequestOperationHandlerJUnitTest {
public void processWithInvalidEntryReturnsError() throws Exception {
PutAllRequestOperationHandler operationHandler = new PutAllRequestOperationHandler();
- ClientProtocol.Response response = operationHandler.process(serializationServiceStub,
+ RegionAPI.PutAllResponse response = operationHandler.process(serializationServiceStub,
generateTestRequest(true, true), cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
- response.getResponseAPICase());
- Assert.assertThat(response.getErrorResponse().getMessage(),
- CoreMatchers.containsString(EXCEPTION_TEXT));
+ Assert.assertNull(response);
+// Assert.assertThat(response.getErrorResponse().getMessage(),
+// CoreMatchers.containsString(EXCEPTION_TEXT));
// can't verify anything about put keys because we make no guarantees.
}
@@ -133,16 +132,15 @@ public class PutAllRequestOperationHandlerJUnitTest {
public void processWithNoEntriesPasses() throws Exception {
PutAllRequestOperationHandler operationHandler = new PutAllRequestOperationHandler();
- ClientProtocol.Response response = operationHandler.process(serializationServiceStub,
+ RegionAPI.PutAllResponse response = operationHandler.process(serializationServiceStub,
generateTestRequest(false, false), cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.PUTALLRESPONSE,
- response.getResponseAPICase());
+ Assert.assertNotNull(response);
verify(regionMock, times(0)).put(any(), any());
}
- private ClientProtocol.Request generateTestRequest(boolean addInvalidKey, boolean addValidKeys)
+ private RegionAPI.PutAllRequest generateTestRequest(boolean addInvalidKey, boolean addValidKeys)
throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
Set<BasicTypes.Entry> entries = new HashSet<>();
if (addInvalidKey) {
@@ -161,6 +159,6 @@ public class PutAllRequestOperationHandlerJUnitTest {
ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_KEY3),
ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_VALUE3)));
}
- return ProtobufRequestUtilities.createPutAllRequest(TEST_REGION, entries);
+ return ProtobufRequestUtilities.createPutAllRequest(TEST_REGION, entries).getPutAllRequest();
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/2033ba7b/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 10108ef..8e0c95f 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
@@ -14,10 +14,18 @@
*/
package org.apache.geode.protocol.protobuf.operations;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import org.apache.geode.cache.Cache;
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.RegionAPI;
import org.apache.geode.protocol.protobuf.utilities.ProtobufRequestUtilities;
import org.apache.geode.protocol.protobuf.utilities.ProtobufUtilities;
import org.apache.geode.serialization.SerializationService;
@@ -32,8 +40,6 @@ import org.junit.experimental.categories.Category;
import java.nio.charset.Charset;
-import static org.mockito.Mockito.*;
-
@Category(UnitTest.class)
public class PutRequestOperationHandlerJUnitTest {
public static final String TEST_KEY = "my key";
@@ -66,11 +72,10 @@ public class PutRequestOperationHandlerJUnitTest {
public void test_puttingTheEncodedEntryIntoRegion() throws UnsupportedEncodingTypeException,
CodecNotRegisteredForTypeException, CodecAlreadyRegisteredForTypeException {
PutRequestOperationHandler operationHandler = new PutRequestOperationHandler();
- ClientProtocol.Response response =
+ RegionAPI.PutResponse response =
operationHandler.process(serializationServiceStub, generateTestRequest(), cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.PUTRESPONSE,
- response.getResponseAPICase());
+ Assert.assertNotNull(response);
verify(regionMock).put(TEST_KEY, TEST_VALUE);
verify(regionMock, times(1)).put(anyString(), anyString());
@@ -85,11 +90,10 @@ public class PutRequestOperationHandlerJUnitTest {
TEST_KEY.getBytes(Charset.forName("UTF-8")))).thenThrow(exception);
PutRequestOperationHandler operationHandler = new PutRequestOperationHandler();
- ClientProtocol.Response response =
+ RegionAPI.PutResponse response =
operationHandler.process(serializationServiceStub, generateTestRequest(), cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
- response.getResponseAPICase());
+ Assert.assertNull(response);
}
@Test
@@ -101,11 +105,10 @@ public class PutRequestOperationHandlerJUnitTest {
TEST_KEY.getBytes(Charset.forName("UTF-8")))).thenThrow(exception);
PutRequestOperationHandler operationHandler = new PutRequestOperationHandler();
- ClientProtocol.Response response =
+ RegionAPI.PutResponse response =
operationHandler.process(serializationServiceStub, generateTestRequest(), cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
- response.getResponseAPICase());
+ Assert.assertNull(response);
}
@Test
@@ -113,11 +116,10 @@ public class PutRequestOperationHandlerJUnitTest {
UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
when(cacheStub.getRegion(TEST_REGION)).thenReturn(null);
PutRequestOperationHandler operationHandler = new PutRequestOperationHandler();
- ClientProtocol.Response response =
+ RegionAPI.PutResponse response =
operationHandler.process(serializationServiceStub, generateTestRequest(), cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
- response.getResponseAPICase());
+ Assert.assertNull(response);
}
@Test
@@ -126,20 +128,19 @@ public class PutRequestOperationHandlerJUnitTest {
when(regionMock.put(any(), any())).thenThrow(ClassCastException.class);
PutRequestOperationHandler operationHandler = new PutRequestOperationHandler();
- ClientProtocol.Response response =
+ RegionAPI.PutResponse response =
operationHandler.process(serializationServiceStub, generateTestRequest(), cacheStub);
- Assert.assertEquals(ClientProtocol.Response.ResponseAPICase.ERRORRESPONSE,
- response.getResponseAPICase());
+ Assert.assertNull(response);
}
- private ClientProtocol.Request generateTestRequest()
+ private RegionAPI.PutRequest generateTestRequest()
throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
BasicTypes.EncodedValue testKey =
ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_KEY);
BasicTypes.EncodedValue testValue =
ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_VALUE);
BasicTypes.Entry testEntry = ProtobufUtilities.createEntry(testKey, testValue);
- return ProtobufRequestUtilities.createPutRequest(TEST_REGION, testEntry);
+ return ProtobufRequestUtilities.createPutRequest(TEST_REGION, testEntry).getPutRequest();
}
}