You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by go...@apache.org on 2017/12/20 17:51:38 UTC
[geode] branch develop updated: GEODE-4080: Protobuf JSON objects
are in a proto string (#1171)
This is an automated email from the ASF dual-hosted git repository.
gosullivan pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new e24e038 GEODE-4080: Protobuf JSON objects are in a proto string (#1171)
e24e038 is described below
commit e24e038e69244cc655779634945896411e678080
Author: Galen O'Sullivan <go...@pivotal.io>
AuthorDate: Wed Dec 20 09:51:35 2017 -0800
GEODE-4080: Protobuf JSON objects are in a proto string (#1171)
* GEODE-4080: Protobuf JSON objects are in a proto string
In the process, remove a couple of serialization-related classes that
are no longer really applicable.
* Catch `JSONFormatterException` and return it as a `EncodingException`.
* Change some names and add ProtobufSerializationService, which is the big
reason for all this churn.
* Get rid of the codec package
* Inline the serialization type enum
* Make encoding methods throw EncodingException.
* Don't use exceptions for control flow.
This meant renaming ProtobufPrimitiveTypes to ProtobufEncodingTypes.
Signed-off-by: Brian Rowe <br...@pivotal.io>
---
.../geode/internal/protocol/OperationContext.java | 9 +-
.../v1/serializer => }/ProtocolSerializer.java | 2 +-
.../protocol/operations/OperationHandler.java | 11 +-
.../JSONCodec.java => JsonPdxConverter.java} | 24 ++-
.../serialization/SerializationService.java | 9 +-
.../{TypeCodec.java => TypeConverter.java} | 7 +-
...ngTypeException.java => EncodingException.java} | 6 +-
.../registry/SerializationCodecRegistry.java | 67 ---------
.../CodecAlreadyRegisteredForTypeException.java | 28 ----
.../CodecNotRegisteredForTypeException.java | 27 ----
...geode.internal.protocol.serialization.TypeCodec | 1 -
.../experimental/driver/ValueEncoderTest.java | 11 +-
.../src/main/proto/v1/basicTypes.proto | 13 +-
.../operations/ProtobufOperationHandler.java | 24 +--
.../protobuf/v1/EncodingTypeTranslator.java | 68 ---------
.../protobuf/v1/ProtobufOperationContext.java | 6 +-
.../protobuf/v1/ProtobufSerializationService.java | 155 ++++++++++++++++---
.../operations/GetAllRequestOperationHandler.java | 19 ++-
.../GetAvailableServersOperationHandler.java | 7 +-
.../GetRegionNamesRequestOperationHandler.java | 6 +-
.../GetRegionRequestOperationHandler.java | 8 +-
.../v1/operations/GetRequestOperationHandler.java | 25 ++-
.../operations/PutAllRequestOperationHandler.java | 21 ++-
.../v1/operations/PutRequestOperationHandler.java | 20 ++-
.../operations/RemoveRequestOperationHandler.java | 22 +--
.../AuthenticationRequestOperationHandler.java | 10 +-
.../v1/serializer/ProtobufProtocolSerializer.java | 1 +
.../v1/utilities/ProtobufPrimitiveTypes.java | 49 ------
.../protobuf/v1/utilities/ProtobufUtilities.java | 167 +--------------------
...eType.java => UnknownProtobufEncodingType.java} | 4 +-
...TypeToSerializationTypeTranslatorJUnitTest.java | 56 -------
.../protobuf/v1/AuthorizationIntegrationTest.java | 2 +-
.../internal/protocol/protobuf/v1/MessageUtil.java | 18 +--
.../v1/acceptance/CacheConnectionJUnitTest.java | 2 +-
.../CacheConnectionTimeoutJUnitTest.java | 2 +-
.../v1/acceptance/CacheOperationsJUnitTest.java | 33 ++--
.../GetAllRequestOperationHandlerJUnitTest.java | 32 ++--
...tAvailableServersOperationHandlerJUnitTest.java | 4 +-
...egionNamesRequestOperationHandlerJUnitTest.java | 5 +-
.../GetRegionRequestOperationHandlerJUnitTest.java | 4 +-
.../GetRequestOperationHandlerJUnitTest.java | 33 ++--
.../v1/operations/OperationHandlerJUnitTest.java | 6 +-
.../PutAllRequestOperationHandlerJUnitTest.java | 38 ++---
.../PutRequestOperationHandlerJUnitTest.java | 35 ++---
.../RemoveRequestOperationHandlerJUnitTest.java | 29 ++--
...nitTest.java => JsonPdxConverterJUnitTest.java} | 15 +-
.../registry/CodecRegistryJUnitTest.java | 49 ------
.../ProtobufProtocolSerializerJUnitTest.java | 1 +
.../v1/utilities/ProtobufUtilitiesJUnitTest.java | 78 +++++-----
49 files changed, 408 insertions(+), 861 deletions(-)
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/OperationContext.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/OperationContext.java
index 370d501..3ff500c 100644
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/OperationContext.java
+++ b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/OperationContext.java
@@ -17,20 +17,21 @@ package org.apache.geode.internal.protocol;
import java.util.function.Function;
+import org.apache.geode.SerializationException;
import org.apache.geode.annotations.Experimental;
import org.apache.geode.internal.protocol.operations.OperationHandler;
import org.apache.geode.security.ResourcePermission;
@Experimental
-public abstract class OperationContext<OperationRequest, OperationResponse, ErrorResponse, ProtocolRequest, ProtocolResponse> {
- private final OperationHandler<OperationRequest, OperationResponse, ErrorResponse> operationHandler;
+public abstract class OperationContext<OperationRequest, OperationResponse, ErrorResponse, ProtocolRequest, ProtocolResponse, Serializer> {
+ private final OperationHandler<OperationRequest, OperationResponse, ErrorResponse, Serializer> operationHandler;
private final Function<ProtocolRequest, OperationRequest> fromRequest;
private final Function<OperationResponse, ProtocolResponse> toResponse;
private final Function<ErrorResponse, ProtocolResponse> toErrorResponse;
private final ResourcePermission accessPermissionRequired;
public OperationContext(Function<ProtocolRequest, OperationRequest> fromRequest,
- OperationHandler<OperationRequest, OperationResponse, ErrorResponse> operationHandler,
+ OperationHandler<OperationRequest, OperationResponse, ErrorResponse, Serializer> operationHandler,
Function<OperationResponse, ProtocolResponse> toResponse,
ResourcePermission permissionRequired) {
this.operationHandler = operationHandler;
@@ -42,7 +43,7 @@ public abstract class OperationContext<OperationRequest, OperationResponse, Erro
protected abstract ProtocolResponse makeErrorBuilder(ErrorResponse errorResponse);
- public OperationHandler<OperationRequest, OperationResponse, ErrorResponse> getOperationHandler() {
+ public OperationHandler<OperationRequest, OperationResponse, ErrorResponse, Serializer> getOperationHandler() {
return operationHandler;
}
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtocolSerializer.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/ProtocolSerializer.java
similarity index 95%
rename from geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtocolSerializer.java
rename to geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/ProtocolSerializer.java
index 6fd566a..456d0e2 100644
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtocolSerializer.java
+++ b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/ProtocolSerializer.java
@@ -12,7 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-package org.apache.geode.internal.protocol.protobuf.v1.serializer;
+package org.apache.geode.internal.protocol;
import java.io.IOException;
import java.io.InputStream;
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/operations/OperationHandler.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/operations/OperationHandler.java
index dc1fe2e..3697d6b 100644
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/operations/OperationHandler.java
+++ b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/operations/OperationHandler.java
@@ -18,16 +18,17 @@ import org.apache.geode.annotations.Experimental;
import org.apache.geode.internal.exception.InvalidExecutionContextException;
import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.Result;
-import org.apache.geode.internal.protocol.serialization.SerializationService;
import org.apache.geode.internal.protocol.state.exception.ConnectionStateException;
/**
- * This interface is implemented by a object capable of handling request types 'Req' and returning
- * an a response of type 'Resp'
+ * This interface is implemented by a object capable of handling request types 'Req' and returning a
+ * response of type 'Resp'.
+ *
+ * The Serializer deserializes and serializes values in 'Req' and 'Resp'.
*
*/
@Experimental
-public interface OperationHandler<Req, Resp, ErrorResp> {
+public interface OperationHandler<Req, Resp, ErrorResp, Serializer> {
/**
* Decode the message, deserialize contained values using the serialization service, do the work
* indicated on the provided cache, and return a response.
@@ -35,7 +36,7 @@ public interface OperationHandler<Req, Resp, ErrorResp> {
* @throws ConnectionStateException if the connection is in an invalid state for the operation in
* question.
*/
- Result<Resp, ErrorResp> process(SerializationService serializationService, Req request,
+ Result<Resp, ErrorResp> process(Serializer serializationService, Req request,
MessageExecutionContext messageExecutionContext)
throws InvalidExecutionContextException, ConnectionStateException;
}
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/codec/JSONCodec.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/JsonPdxConverter.java
similarity index 57%
rename from geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/codec/JSONCodec.java
rename to geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/JsonPdxConverter.java
index a27f146..88e242e 100644
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/codec/JSONCodec.java
+++ b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/JsonPdxConverter.java
@@ -12,24 +12,34 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
-package org.apache.geode.internal.protocol.serialization.codec;
+package org.apache.geode.internal.protocol.serialization;
import org.apache.geode.annotations.Experimental;
import org.apache.geode.internal.protocol.serialization.SerializationType;
-import org.apache.geode.internal.protocol.serialization.TypeCodec;
+import org.apache.geode.internal.protocol.serialization.TypeConverter;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
import org.apache.geode.pdx.JSONFormatter;
+import org.apache.geode.pdx.JSONFormatterException;
import org.apache.geode.pdx.PdxInstance;
@Experimental
-public class JSONCodec implements TypeCodec<PdxInstance> {
+public class JsonPdxConverter implements TypeConverter<String, PdxInstance> {
@Override
- public PdxInstance decode(byte[] incoming) {
- return JSONFormatter.fromJSON(incoming);
+ public PdxInstance decode(String incoming) throws EncodingException {
+ try {
+ return JSONFormatter.fromJSON(incoming);
+ } catch (JSONFormatterException ex) {
+ throw new EncodingException("Could not decode JSON-encoded object ", ex);
+ }
}
@Override
- public byte[] encode(PdxInstance incoming) {
- return JSONFormatter.toJSONByteArray(incoming);
+ public String encode(PdxInstance incoming) throws EncodingException {
+ try {
+ return JSONFormatter.toJSON(incoming);
+ } catch (JSONFormatterException ex) {
+ throw new EncodingException("Could not encode PDX object as JSON", ex);
+ }
}
@Override
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/SerializationService.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/SerializationService.java
index 8e6a265..4544735 100644
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/SerializationService.java
+++ b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/SerializationService.java
@@ -15,8 +15,7 @@
package org.apache.geode.internal.protocol.serialization;
import org.apache.geode.annotations.Experimental;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
/**
* This interface takes an protocol specific encodingTypeValue enum and converts between objects and
@@ -26,9 +25,7 @@ import org.apache.geode.internal.protocol.serialization.registry.exception.Codec
*/
@Experimental
public interface SerializationService<T> {
- Object decode(T encodingTypeValue, byte[] value)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException;
+ Object decode(T encodedValue) throws EncodingException;
- byte[] encode(T encodingTypeValue, Object value)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException;
+ T encode(Object value) throws EncodingException;
}
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/TypeCodec.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/TypeConverter.java
similarity index 85%
rename from geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/TypeCodec.java
rename to geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/TypeConverter.java
index 55fce2a..b86d4dc 100644
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/TypeCodec.java
+++ b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/TypeConverter.java
@@ -15,6 +15,7 @@
package org.apache.geode.internal.protocol.serialization;
import org.apache.geode.annotations.Experimental;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
/**
* This interface converts a particular type to and from its binary representation.
@@ -24,10 +25,10 @@ import org.apache.geode.annotations.Experimental;
* @param <T> the type this codec knows how to convert
*/
@Experimental
-public interface TypeCodec<T> {
- T decode(byte[] incoming);
+public interface TypeConverter<F, T> {
+ T decode(F incoming) throws EncodingException;
- byte[] encode(T incoming);
+ F encode(T incoming) throws EncodingException;
/**
* @return the SerializationType corresponding to T
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/exception/UnsupportedEncodingTypeException.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/exception/EncodingException.java
similarity index 83%
rename from geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/exception/UnsupportedEncodingTypeException.java
rename to geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/exception/EncodingException.java
index c7b425e..776846e 100644
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/exception/UnsupportedEncodingTypeException.java
+++ b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/exception/EncodingException.java
@@ -20,12 +20,12 @@ import org.apache.geode.annotations.Experimental;
* This indicates an encoding type that we don't know how to handle.
*/
@Experimental
-public class UnsupportedEncodingTypeException extends Exception {
- public UnsupportedEncodingTypeException(String message) {
+public class EncodingException extends Exception {
+ public EncodingException(String message) {
super(message);
}
- public UnsupportedEncodingTypeException(String message, Throwable cause) {
+ public EncodingException(String message, Throwable cause) {
super(message, cause);
}
}
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/registry/SerializationCodecRegistry.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/registry/SerializationCodecRegistry.java
deleted file mode 100644
index 045cd36..0000000
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/registry/SerializationCodecRegistry.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.internal.protocol.serialization.registry;
-
-import java.util.HashMap;
-import java.util.ServiceLoader;
-
-import org.apache.geode.GemFireConfigException;
-import org.apache.geode.annotations.Experimental;
-import org.apache.geode.internal.protocol.serialization.SerializationType;
-import org.apache.geode.internal.protocol.serialization.TypeCodec;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecAlreadyRegisteredForTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
-
-@Experimental
-public class SerializationCodecRegistry {
- private final HashMap<SerializationType, TypeCodec> codecRegistry = new HashMap<>();
-
- public SerializationCodecRegistry() {
- ServiceLoader<TypeCodec> typeCodecs = ServiceLoader.load(TypeCodec.class);
- try {
- for (TypeCodec typeCodec : typeCodecs) {
- register(typeCodec.getSerializationType(), typeCodec);
- }
- } catch (CodecAlreadyRegisteredForTypeException ex) {
- throw new GemFireConfigException("Multiple implementations found for the same TypeCodec", ex);
- }
- }
-
- private void register(SerializationType serializationType, TypeCodec<?> typeCodec) {
- if (codecRegistry.containsKey(serializationType)) {
- throw new CodecAlreadyRegisteredForTypeException(
- "There is already a codec registered for type: " + serializationType);
- }
- codecRegistry.put(serializationType, typeCodec);
- }
-
- public int getRegisteredCodecCount() {
- return codecRegistry.size();
- }
-
- public TypeCodec getCodecForType(SerializationType serializationType)
- throws CodecNotRegisteredForTypeException {
- TypeCodec typeCodec = codecRegistry.get(serializationType);
- if (typeCodec == null) {
- throw new CodecNotRegisteredForTypeException(
- "There is no codec registered for type: " + serializationType);
- }
- return typeCodec;
- }
-
- public void shutdown() {
- codecRegistry.clear();
- }
-}
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
deleted file mode 100644
index 45284ba..0000000
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/registry/exception/CodecAlreadyRegisteredForTypeException.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.internal.protocol.serialization.registry.exception;
-
-import org.apache.geode.annotations.Experimental;
-
-/**
- * This indicates that we're attempting to register a codec for a type which we already have a
- * handler for.
- */
-@Experimental
-public class CodecAlreadyRegisteredForTypeException extends RuntimeException {
- public CodecAlreadyRegisteredForTypeException(String message) {
- super(message);
- }
-}
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/registry/exception/CodecNotRegisteredForTypeException.java b/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/registry/exception/CodecNotRegisteredForTypeException.java
deleted file mode 100644
index 3d554db..0000000
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/serialization/registry/exception/CodecNotRegisteredForTypeException.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.internal.protocol.serialization.registry.exception;
-
-import org.apache.geode.annotations.Experimental;
-
-/**
- * This indicates we're attempting to handle a type for which we don't have a registered codec.
- */
-@Experimental
-public class CodecNotRegisteredForTypeException extends Exception {
- public CodecNotRegisteredForTypeException(String message) {
- super(message);
- }
-}
diff --git a/geode-client-protocol/src/main/resources/META-INF/services/org.apache.geode.internal.protocol.serialization.TypeCodec b/geode-client-protocol/src/main/resources/META-INF/services/org.apache.geode.internal.protocol.serialization.TypeCodec
deleted file mode 100644
index fcbbeaf..0000000
--- a/geode-client-protocol/src/main/resources/META-INF/services/org.apache.geode.internal.protocol.serialization.TypeCodec
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.geode.internal.protocol.serialization.codec.JSONCodec
diff --git a/geode-experimental-driver/src/test/java/org/apache/geode/experimental/driver/ValueEncoderTest.java b/geode-experimental-driver/src/test/java/org/apache/geode/experimental/driver/ValueEncoderTest.java
index 2afe472..827a0a7 100644
--- a/geode-experimental-driver/src/test/java/org/apache/geode/experimental/driver/ValueEncoderTest.java
+++ b/geode-experimental-driver/src/test/java/org/apache/geode/experimental/driver/ValueEncoderTest.java
@@ -17,9 +17,6 @@ package org.apache.geode.experimental.driver;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import java.io.UnsupportedEncodingException;
-
-import com.google.protobuf.ByteString;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -40,11 +37,11 @@ public class ValueEncoderTest {
}
@Test(expected = IllegalStateException.class)
- public void cantDecodeJson() throws UnsupportedEncodingException {
+ public void cantDecodeJson() throws Exception {
BasicTypes.EncodedValue.Builder builder = BasicTypes.EncodedValue.newBuilder();
- BasicTypes.CustomEncodedValue.Builder customEncodedValue =
- BasicTypes.CustomEncodedValue.newBuilder().setValue(ByteString.copyFrom("hello", "UTF-8"));
- builder.setCustomEncodedValue(customEncodedValue);
+
+ builder.setJsonObjectResult("hello").build();
+
ValueEncoder.decodeValue(builder.build());
}
}
diff --git a/geode-protobuf-messages/src/main/proto/v1/basicTypes.proto b/geode-protobuf-messages/src/main/proto/v1/basicTypes.proto
index 9ab7d2f..410c563 100644
--- a/geode-protobuf-messages/src/main/proto/v1/basicTypes.proto
+++ b/geode-protobuf-messages/src/main/proto/v1/basicTypes.proto
@@ -38,18 +38,9 @@ message EncodedValue {
float floatResult = 7;
bytes binaryResult = 8;
string stringResult = 9;
- CustomEncodedValue customEncodedValue = 50;
- }
-}
-message CustomEncodedValue {
- EncodingType encodingType = 1;
- bytes value = 2;
-}
-
-enum EncodingType {
- INVALID = 0;
- JSON = 10;
+ string jsonObjectResult = 10;
+ }
}
message Region {
diff --git a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/operations/OperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/operations/ProtobufOperationHandler.java
similarity index 63%
copy from geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/operations/OperationHandler.java
copy to geode-protobuf/src/main/java/org/apache/geode/internal/protocol/operations/ProtobufOperationHandler.java
index dc1fe2e..b4bc817 100644
--- a/geode-client-protocol/src/main/java/org/apache/geode/internal/protocol/operations/OperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/operations/ProtobufOperationHandler.java
@@ -14,28 +14,18 @@
*/
package org.apache.geode.internal.protocol.operations;
-import org.apache.geode.annotations.Experimental;
import org.apache.geode.internal.exception.InvalidExecutionContextException;
import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.Result;
-import org.apache.geode.internal.protocol.serialization.SerializationService;
+import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.state.exception.ConnectionStateException;
-/**
- * This interface is implemented by a object capable of handling request types 'Req' and returning
- * an a response of type 'Resp'
- *
- */
-@Experimental
-public interface OperationHandler<Req, Resp, ErrorResp> {
- /**
- * Decode the message, deserialize contained values using the serialization service, do the work
- * indicated on the provided cache, and return a response.
- *
- * @throws ConnectionStateException if the connection is in an invalid state for the operation in
- * question.
- */
- Result<Resp, ErrorResp> process(SerializationService serializationService, Req request,
+public interface ProtobufOperationHandler<Req, Resp> extends
+ OperationHandler<Req, Resp, ClientProtocol.ErrorResponse, ProtobufSerializationService> {
+ @Override
+ Result<Resp, ClientProtocol.ErrorResponse> process(
+ ProtobufSerializationService serializationService, Req request,
MessageExecutionContext messageExecutionContext)
throws InvalidExecutionContextException, ConnectionStateException;
}
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/EncodingTypeTranslator.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/EncodingTypeTranslator.java
deleted file mode 100644
index 0764f54..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/EncodingTypeTranslator.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.internal.protocol.protobuf.v1;
-
-import static org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodingType.JSON;
-
-import java.util.HashMap;
-
-import org.apache.geode.annotations.Experimental;
-import org.apache.geode.internal.protocol.serialization.SerializationType;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.pdx.JSONFormatter;
-import org.apache.geode.pdx.PdxInstance;
-
-/**
- * This class maps protobuf specific encoding types and the corresponding serialization types.
- */
-@Experimental
-public abstract class EncodingTypeTranslator {
- static final HashMap<Class, BasicTypes.EncodingType> typeToEncodingMap = intializeTypeMap();
-
- private static HashMap<Class, BasicTypes.EncodingType> intializeTypeMap() {
- HashMap<Class, BasicTypes.EncodingType> result = new HashMap<>();
- result.put(PdxInstance.class, JSON);
- return result;
- }
-
- public static SerializationType getSerializationTypeForEncodingType(
- BasicTypes.EncodingType encodingType) throws UnsupportedEncodingTypeException {
- switch (encodingType) {
- case JSON:
- return SerializationType.JSON;
- default:
- throw new UnsupportedEncodingTypeException(
- "No serialization type found for protobuf encoding type: " + encodingType);
- }
- }
-
- public static BasicTypes.EncodingType getEncodingTypeForObject(Object resultValue)
- throws UnsupportedEncodingTypeException {
- if (resultValue instanceof PdxInstance) {
- String pdxClassName = ((PdxInstance) resultValue).getClassName();
- if (pdxClassName.equals(JSONFormatter.JSON_CLASSNAME)) {
- return JSON;
- }
- }
-
- BasicTypes.EncodingType encodingType = typeToEncodingMap.get(resultValue.getClass());
- if (encodingType == null) {
- throw new UnsupportedEncodingTypeException(
- "We cannot translate: " + resultValue.getClass() + " into a specific Protobuf Encoding");
- } else {
- return encodingType;
- }
- }
-}
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ProtobufOperationContext.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ProtobufOperationContext.java
index c534444..de01e5c 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ProtobufOperationContext.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ProtobufOperationContext.java
@@ -17,14 +17,14 @@ package org.apache.geode.internal.protocol.protobuf.v1;
import java.util.function.Function;
import org.apache.geode.internal.protocol.OperationContext;
-import org.apache.geode.internal.protocol.operations.OperationHandler;
+import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
import org.apache.geode.security.ResourcePermission;
public class ProtobufOperationContext<OperationRequest, OperationResponse> extends
- OperationContext<OperationRequest, OperationResponse, ClientProtocol.ErrorResponse, ClientProtocol.Request, ClientProtocol.Response.Builder> {
+ OperationContext<OperationRequest, OperationResponse, ClientProtocol.ErrorResponse, ClientProtocol.Request, ClientProtocol.Response.Builder, ProtobufSerializationService> {
public ProtobufOperationContext(Function<ClientProtocol.Request, OperationRequest> fromRequest,
- OperationHandler<OperationRequest, OperationResponse, ClientProtocol.ErrorResponse> operationHandler,
+ ProtobufOperationHandler<OperationRequest, OperationResponse> operationHandler,
Function<OperationResponse, ClientProtocol.Response.Builder> toResponse,
ResourcePermission permissionRequired) {
super(fromRequest, operationHandler, toResponse, permissionRequired);
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ProtobufSerializationService.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ProtobufSerializationService.java
index 783c64c..c052f44 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ProtobufSerializationService.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/ProtobufSerializationService.java
@@ -14,42 +14,153 @@
*/
package org.apache.geode.internal.protocol.protobuf.v1;
+import com.google.protobuf.ByteString;
+
import org.apache.geode.annotations.Experimental;
+import org.apache.geode.internal.protocol.protobuf.v1.utilities.exception.UnknownProtobufEncodingType;
+import org.apache.geode.internal.protocol.serialization.JsonPdxConverter;
import org.apache.geode.internal.protocol.serialization.SerializationService;
-import org.apache.geode.internal.protocol.serialization.SerializationType;
-import org.apache.geode.internal.protocol.serialization.TypeCodec;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.SerializationCodecRegistry;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
+import org.apache.geode.pdx.PdxInstance;
@Experimental
-public class ProtobufSerializationService implements SerializationService<BasicTypes.EncodingType> {
- private SerializationCodecRegistry serializationCodecRegistry = new SerializationCodecRegistry();
+public class ProtobufSerializationService implements SerializationService<BasicTypes.EncodedValue> {
+ private final JsonPdxConverter jsonPdxConverter = new JsonPdxConverter();
public ProtobufSerializationService() {}
+ /**
+ * @param value the value to be encoded
+ *
+ * @return EncodedValue message with the serialized value
+ * @throws EncodingException
+ */
@Override
- public byte[] encode(BasicTypes.EncodingType encodingTypeValue, Object value)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- TypeCodec codecForType = getTypeCodecForProtobufType(encodingTypeValue);
- return codecForType.encode(value);
+ public BasicTypes.EncodedValue encode(Object value) throws EncodingException {
+ BasicTypes.EncodedValue.Builder builder = BasicTypes.EncodedValue.newBuilder();
+ try {
+ ProtobufEncodingTypes protobufEncodingTypes = ProtobufEncodingTypes.valueOf(value.getClass());
+ switch (protobufEncodingTypes) {
+ case INT: {
+ builder.setIntResult((Integer) value);
+ break;
+ }
+ case LONG: {
+ builder.setLongResult((Long) value);
+ break;
+ }
+ case SHORT: {
+ builder.setShortResult((Short) value);
+ break;
+ }
+ case BYTE: {
+ builder.setByteResult((Byte) value);
+ break;
+ }
+ case DOUBLE: {
+ builder.setDoubleResult((Double) value);
+ break;
+ }
+ case FLOAT: {
+ builder.setFloatResult((Float) value);
+ break;
+ }
+ case BINARY: {
+ builder.setBinaryResult(ByteString.copyFrom((byte[]) value));
+ break;
+ }
+ case BOOLEAN: {
+ builder.setBooleanResult((Boolean) value);
+ break;
+ }
+ case STRING: {
+ builder.setStringResult((String) value);
+ break;
+ }
+ case PDX_OBJECT: {
+ builder.setJsonObjectResult(jsonPdxConverter.encode((PdxInstance) value));
+ break;
+ }
+ }
+ } catch (UnknownProtobufEncodingType unknownProtobufEncodingType) {
+ throw new EncodingException("No protobuf encoding for type " + value.getClass().getName());
+ }
+ return builder.build();
}
+ /**
+ * @param encodedValue - The value to be decoded
+ * @return A decoded object representing encodedValue
+ * @throws EncodingException if the value cannot be decoded.
+ */
@Override
- public Object decode(BasicTypes.EncodingType encodingTypeValue, byte[] value)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- if (encodingTypeValue == BasicTypes.EncodingType.INVALID) {
- return null;
+ public Object decode(BasicTypes.EncodedValue encodedValue) throws EncodingException {
+ switch (encodedValue.getValueCase()) {
+ case BINARYRESULT:
+ return encodedValue.getBinaryResult().toByteArray();
+ case BOOLEANRESULT:
+ return encodedValue.getBooleanResult();
+ case BYTERESULT:
+ return (byte) encodedValue.getByteResult();
+ case DOUBLERESULT:
+ return encodedValue.getDoubleResult();
+ case FLOATRESULT:
+ return encodedValue.getFloatResult();
+ case INTRESULT:
+ return encodedValue.getIntResult();
+ case LONGRESULT:
+ return encodedValue.getLongResult();
+ case SHORTRESULT:
+ return (short) encodedValue.getShortResult();
+ case STRINGRESULT:
+ return encodedValue.getStringResult();
+ case JSONOBJECTRESULT:
+ return jsonPdxConverter.decode(encodedValue.getJsonObjectResult());
+ case VALUE_NOT_SET:
+ return null;
+ default:
+ throw new EncodingException(
+ "Unknown Protobuf encoding type: " + encodedValue.getValueCase());
}
- TypeCodec codecForType = getTypeCodecForProtobufType(encodingTypeValue);
- return codecForType.decode(value);
}
- private TypeCodec getTypeCodecForProtobufType(BasicTypes.EncodingType encodingTypeValue)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- SerializationType serializationTypeForEncodingType =
- EncodingTypeTranslator.getSerializationTypeForEncodingType(encodingTypeValue);
+ /**
+ * Maps classes to encoding for protobuf.
+ *
+ * This currently conflates object type with serialization, which may be an issue if we add more
+ * types of object serialization.
+ */
+ private enum ProtobufEncodingTypes {
+
+ STRING(String.class),
+ INT(Integer.class),
+ LONG(Long.class),
+ SHORT(Short.class),
+ BYTE(Byte.class),
+ BOOLEAN(Boolean.class),
+ DOUBLE(Double.class),
+ FLOAT(Float.class),
+ BINARY(byte[].class),
+
+ // This will probably have to change once the protocol supports multiple object encodings.
+ PDX_OBJECT(PdxInstance.class);
+
+ private Class clazz;
- return serializationCodecRegistry.getCodecForType(serializationTypeForEncodingType);
+ ProtobufEncodingTypes(Class clazz) {
+ this.clazz = clazz;
+ }
+
+ public static ProtobufEncodingTypes valueOf(Class unencodedValueClass)
+ throws UnknownProtobufEncodingType {
+ for (ProtobufEncodingTypes protobufEncodingTypes : values()) {
+ if (protobufEncodingTypes.clazz.equals(unencodedValueClass)) {
+ return protobufEncodingTypes;
+ }
+ }
+ throw new UnknownProtobufEncodingType(
+ "There is no primitive protobuf type mapping for class:" + unencodedValueClass);
+ }
}
+
}
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java
index 2b717fc..1d5319c 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandler.java
@@ -38,24 +38,23 @@ import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.ProtocolErrorCode;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
-import org.apache.geode.internal.protocol.operations.OperationHandler;
+import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufResponseUtilities;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.SerializationService;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
@Experimental
-public class GetAllRequestOperationHandler implements
- OperationHandler<RegionAPI.GetAllRequest, RegionAPI.GetAllResponse, ClientProtocol.ErrorResponse> {
+public class GetAllRequestOperationHandler
+ implements ProtobufOperationHandler<RegionAPI.GetAllRequest, RegionAPI.GetAllResponse> {
private static final Logger logger = LogService.getLogger();
@Override
public Result<RegionAPI.GetAllResponse, ClientProtocol.ErrorResponse> process(
- SerializationService serializationService, RegionAPI.GetAllRequest request,
+ ProtobufSerializationService serializationService, RegionAPI.GetAllRequest request,
MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException {
String regionName = request.getRegionName();
Region region = messageExecutionContext.getCache().getRegion(regionName);
@@ -81,13 +80,13 @@ public class GetAllRequestOperationHandler implements
return Success.of(responseBuilder.build());
}
- private Object processOneMessage(SerializationService serializationService, Region region,
+ private Object processOneMessage(ProtobufSerializationService serializationService, Region region,
BasicTypes.EncodedValue key) {
try {
- Object decodedKey = ProtobufUtilities.decodeValue(serializationService, key);
+ Object decodedKey = serializationService.decode(key);
Object value = region.get(decodedKey);
return ProtobufUtilities.createEntry(serializationService, decodedKey, value);
- } catch (CodecNotRegisteredForTypeException | UnsupportedEncodingTypeException ex) {
+ } catch (EncodingException ex) {
logger.error("Encoding not supported: {}", ex);
return createKeyedError(key, "Encoding not supported.", VALUE_ENCODING_ERROR);
} catch (org.apache.geode.distributed.LeaseExpiredException | TimeoutException e) {
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAvailableServersOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAvailableServersOperationHandler.java
index c97b73b..c6f68c6 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAvailableServersOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAvailableServersOperationHandler.java
@@ -26,18 +26,21 @@ import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
import org.apache.geode.internal.protocol.operations.OperationHandler;
+import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
import org.apache.geode.internal.protocol.protobuf.v1.LocatorAPI;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.serialization.SerializationService;
@Experimental
public class GetAvailableServersOperationHandler implements
- OperationHandler<LocatorAPI.GetAvailableServersRequest, LocatorAPI.GetAvailableServersResponse, ClientProtocol.ErrorResponse> {
+ ProtobufOperationHandler<LocatorAPI.GetAvailableServersRequest, LocatorAPI.GetAvailableServersResponse> {
@Override
public Result<LocatorAPI.GetAvailableServersResponse, ClientProtocol.ErrorResponse> process(
- SerializationService serializationService, LocatorAPI.GetAvailableServersRequest request,
+ ProtobufSerializationService serializationService,
+ LocatorAPI.GetAvailableServersRequest request,
MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException {
InternalLocator internalLocator = (InternalLocator) messageExecutionContext.getLocator();
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandler.java
index 2a8c095..9e63966 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandler.java
@@ -23,18 +23,20 @@ import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
import org.apache.geode.internal.protocol.operations.OperationHandler;
+import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufResponseUtilities;
import org.apache.geode.internal.protocol.serialization.SerializationService;
@Experimental
public class GetRegionNamesRequestOperationHandler implements
- OperationHandler<RegionAPI.GetRegionNamesRequest, RegionAPI.GetRegionNamesResponse, ClientProtocol.ErrorResponse> {
+ ProtobufOperationHandler<RegionAPI.GetRegionNamesRequest, RegionAPI.GetRegionNamesResponse> {
@Override
public Result<RegionAPI.GetRegionNamesResponse, ClientProtocol.ErrorResponse> process(
- SerializationService serializationService, RegionAPI.GetRegionNamesRequest request,
+ ProtobufSerializationService serializationService, RegionAPI.GetRegionNamesRequest request,
MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException {
Set<Region<?, ?>> regions = messageExecutionContext.getCache().rootRegions();
return Success.of(ProtobufResponseUtilities.createGetRegionNamesResponse(regions));
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandler.java
index cef71fd..ed5daae 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandler.java
@@ -27,21 +27,23 @@ import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
import org.apache.geode.internal.protocol.operations.OperationHandler;
+import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufResponseUtilities;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
import org.apache.geode.internal.protocol.serialization.SerializationService;
@Experimental
-public class GetRegionRequestOperationHandler implements
- OperationHandler<RegionAPI.GetRegionRequest, RegionAPI.GetRegionResponse, ClientProtocol.ErrorResponse> {
+public class GetRegionRequestOperationHandler
+ implements ProtobufOperationHandler<RegionAPI.GetRegionRequest, RegionAPI.GetRegionResponse> {
private static final Logger logger = LogService.getLogger();
@Override
public Result<RegionAPI.GetRegionResponse, ClientProtocol.ErrorResponse> process(
- SerializationService serializationService, RegionAPI.GetRegionRequest request,
+ ProtobufSerializationService serializationService, RegionAPI.GetRegionRequest request,
MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException {
String regionName = request.getRegionName();
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandler.java
index eb4d7fc..5b62b07 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandler.java
@@ -27,24 +27,22 @@ import org.apache.geode.internal.protocol.Failure;
import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
-import org.apache.geode.internal.protocol.operations.OperationHandler;
+import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufResponseUtilities;
-import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.SerializationService;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
@Experimental
-public class GetRequestOperationHandler implements
- OperationHandler<RegionAPI.GetRequest, RegionAPI.GetResponse, ClientProtocol.ErrorResponse> {
+public class GetRequestOperationHandler
+ implements ProtobufOperationHandler<RegionAPI.GetRequest, RegionAPI.GetResponse> {
private static final Logger logger = LogService.getLogger();
@Override
public Result<RegionAPI.GetResponse, ClientProtocol.ErrorResponse> process(
- SerializationService serializationService, RegionAPI.GetRequest request,
+ ProtobufSerializationService serializationService, RegionAPI.GetRequest request,
MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException {
String regionName = request.getRegionName();
Region region = messageExecutionContext.getCache().getRegion(regionName);
@@ -55,24 +53,19 @@ public class GetRequestOperationHandler implements
}
try {
- Object decodedKey = ProtobufUtilities.decodeValue(serializationService, request.getKey());
+ Object decodedKey = serializationService.decode(request.getKey());
Object resultValue = region.get(decodedKey);
if (resultValue == null) {
return Success.of(RegionAPI.GetResponse.newBuilder().build());
}
- BasicTypes.EncodedValue encodedValue =
- ProtobufUtilities.createEncodedValue(serializationService, resultValue);
+ BasicTypes.EncodedValue encodedValue = serializationService.encode(resultValue);
return Success.of(RegionAPI.GetResponse.newBuilder().setResult(encodedValue).build());
- } catch (UnsupportedEncodingTypeException ex) {
+ } catch (EncodingException ex) {
logger.error("Received Get request with unsupported encoding: {}", ex);
return Failure.of(ProtobufResponseUtilities.makeErrorResponse(VALUE_ENCODING_ERROR,
"Encoding not supported."));
- } catch (CodecNotRegisteredForTypeException ex) {
- logger.error("Got codec error when decoding Get request: {}", ex);
- return Failure.of(ProtobufResponseUtilities.makeErrorResponse(VALUE_ENCODING_ERROR,
- "Codec error in protobuf deserialization."));
}
}
}
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java
index 0af9ab8..7a2426c 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandler.java
@@ -32,24 +32,24 @@ import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.ProtocolErrorCode;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
-import org.apache.geode.internal.protocol.operations.OperationHandler;
+import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufResponseUtilities;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
import org.apache.geode.internal.protocol.serialization.SerializationService;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
@Experimental
-public class PutAllRequestOperationHandler implements
- OperationHandler<RegionAPI.PutAllRequest, RegionAPI.PutAllResponse, ClientProtocol.ErrorResponse> {
+public class PutAllRequestOperationHandler
+ implements ProtobufOperationHandler<RegionAPI.PutAllRequest, RegionAPI.PutAllResponse> {
private static final Logger logger = LogManager.getLogger();
@Override
public Result<RegionAPI.PutAllResponse, ClientProtocol.ErrorResponse> process(
- SerializationService serializationService, RegionAPI.PutAllRequest putAllRequest,
+ ProtobufSerializationService serializationService, RegionAPI.PutAllRequest putAllRequest,
MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException {
String regionName = putAllRequest.getRegionName();
Region region = messageExecutionContext.getCache().getRegion(regionName);
@@ -70,15 +70,12 @@ public class PutAllRequestOperationHandler implements
private BasicTypes.KeyedError singlePut(SerializationService serializationService, Region region,
BasicTypes.Entry entry) {
try {
- Object decodedValue = ProtobufUtilities.decodeValue(serializationService, entry.getValue());
- Object decodedKey = ProtobufUtilities.decodeValue(serializationService, entry.getKey());
+ Object decodedValue = serializationService.decode(entry.getValue());
+ Object decodedKey = serializationService.decode(entry.getKey());
region.put(decodedKey, decodedValue);
- } catch (UnsupportedEncodingTypeException ex) {
+ } catch (EncodingException ex) {
return buildAndLogKeyedError(entry, VALUE_ENCODING_ERROR, "Encoding not supported", ex);
- } catch (CodecNotRegisteredForTypeException ex) {
- return buildAndLogKeyedError(entry, VALUE_ENCODING_ERROR,
- "Codec error in protobuf deserialization", ex);
} catch (ClassCastException ex) {
return buildAndLogKeyedError(entry, CONSTRAINT_VIOLATION,
"Invalid key or value type for region", ex);
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandler.java
index 06cfd35..8f0ed28 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandler.java
@@ -28,24 +28,22 @@ import org.apache.geode.internal.protocol.Failure;
import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
-import org.apache.geode.internal.protocol.operations.OperationHandler;
+import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufResponseUtilities;
-import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.SerializationService;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
@Experimental
-public class PutRequestOperationHandler implements
- OperationHandler<RegionAPI.PutRequest, RegionAPI.PutResponse, ClientProtocol.ErrorResponse> {
+public class PutRequestOperationHandler
+ implements ProtobufOperationHandler<RegionAPI.PutRequest, RegionAPI.PutResponse> {
private static final Logger logger = LogService.getLogger();
@Override
public Result<RegionAPI.PutResponse, ClientProtocol.ErrorResponse> process(
- SerializationService serializationService, RegionAPI.PutRequest request,
+ ProtobufSerializationService serializationService, RegionAPI.PutRequest request,
MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException {
String regionName = request.getRegionName();
Region region = messageExecutionContext.getCache().getRegion(regionName);
@@ -58,8 +56,8 @@ public class PutRequestOperationHandler implements
try {
BasicTypes.Entry entry = request.getEntry();
- Object decodedValue = ProtobufUtilities.decodeValue(serializationService, entry.getValue());
- Object decodedKey = ProtobufUtilities.decodeValue(serializationService, entry.getKey());
+ Object decodedValue = serializationService.decode(entry.getValue());
+ Object decodedKey = serializationService.decode(entry.getKey());
try {
region.put(decodedKey, decodedValue);
return Success.of(RegionAPI.PutResponse.newBuilder().build());
@@ -68,7 +66,7 @@ public class PutRequestOperationHandler implements
return Failure.of(ProtobufResponseUtilities.makeErrorResponse(CONSTRAINT_VIOLATION,
"invalid key or value type for region " + regionName));
}
- } catch (UnsupportedEncodingTypeException | CodecNotRegisteredForTypeException ex) {
+ } catch (EncodingException ex) {
logger.error("Got codec error when decoding Put request: {}", ex);
return Failure
.of(ProtobufResponseUtilities.makeErrorResponse(VALUE_ENCODING_ERROR, ex.getMessage()));
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandler.java
index 720e7c7..a3c99cf 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandler.java
@@ -27,23 +27,21 @@ import org.apache.geode.internal.protocol.Failure;
import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
-import org.apache.geode.internal.protocol.operations.OperationHandler;
+import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufResponseUtilities;
-import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.SerializationService;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
@Experimental
-public class RemoveRequestOperationHandler implements
- OperationHandler<RegionAPI.RemoveRequest, RegionAPI.RemoveResponse, ClientProtocol.ErrorResponse> {
+public class RemoveRequestOperationHandler
+ implements ProtobufOperationHandler<RegionAPI.RemoveRequest, RegionAPI.RemoveResponse> {
private static final Logger logger = LogManager.getLogger();
@Override
public Result<RegionAPI.RemoveResponse, ClientProtocol.ErrorResponse> process(
- SerializationService serializationService, RegionAPI.RemoveRequest request,
+ ProtobufSerializationService serializationService, RegionAPI.RemoveRequest request,
MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException {
String regionName = request.getRegionName();
@@ -55,19 +53,15 @@ public class RemoveRequestOperationHandler implements
}
try {
- Object decodedKey = ProtobufUtilities.decodeValue(serializationService, request.getKey());
+ Object decodedKey = serializationService.decode(request.getKey());
region.remove(decodedKey);
return Success.of(RegionAPI.RemoveResponse.newBuilder().build());
- } catch (UnsupportedEncodingTypeException ex) {
+ } catch (EncodingException ex) {
// can be thrown by encoding or decoding.
logger.error("Received Remove request with unsupported encoding: {}", ex);
return Failure.of(ProtobufResponseUtilities.makeErrorResponse(VALUE_ENCODING_ERROR,
"Encoding not supported: " + ex.getMessage()));
- } catch (CodecNotRegisteredForTypeException ex) {
- logger.error("Got codec error when decoding Remove request: {}", ex);
- return Failure.of(ProtobufResponseUtilities.makeErrorResponse(VALUE_ENCODING_ERROR,
- "Codec error in protobuf deserialization: " + ex.getMessage()));
}
}
}
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/security/AuthenticationRequestOperationHandler.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/security/AuthenticationRequestOperationHandler.java
index 727a693..44eb1ba 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/security/AuthenticationRequestOperationHandler.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/operations/security/AuthenticationRequestOperationHandler.java
@@ -24,8 +24,10 @@ import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
import org.apache.geode.internal.protocol.operations.OperationHandler;
+import org.apache.geode.internal.protocol.operations.ProtobufOperationHandler;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
import org.apache.geode.internal.protocol.protobuf.v1.ConnectionAPI;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.serialization.SerializationService;
import org.apache.geode.internal.protocol.state.ConnectionAuthenticatingStateProcessor;
import org.apache.geode.internal.protocol.state.ConnectionStateProcessor;
@@ -34,14 +36,14 @@ import org.apache.geode.internal.protocol.state.exception.ConnectionStateExcepti
import org.apache.geode.security.AuthenticationFailedException;
public class AuthenticationRequestOperationHandler implements
- OperationHandler<ConnectionAPI.AuthenticationRequest, ConnectionAPI.AuthenticationResponse, ClientProtocol.ErrorResponse> {
+ ProtobufOperationHandler<ConnectionAPI.AuthenticationRequest, ConnectionAPI.AuthenticationResponse> {
private static final Logger logger = LogManager.getLogger();
@Override
public Result<ConnectionAPI.AuthenticationResponse, ClientProtocol.ErrorResponse> process(
- SerializationService serializationService, ConnectionAPI.AuthenticationRequest request,
- MessageExecutionContext messageExecutionContext)
- throws InvalidExecutionContextException, ConnectionStateException {
+ ProtobufSerializationService serializationService,
+ ConnectionAPI.AuthenticationRequest request, MessageExecutionContext messageExecutionContext)
+ throws ConnectionStateException {
ConnectionAuthenticatingStateProcessor stateProcessor;
// If authentication not allowed by this state this will throw a ConnectionStateException
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtobufProtocolSerializer.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtobufProtocolSerializer.java
index 0cdb39e..84742e8 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtobufProtocolSerializer.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtobufProtocolSerializer.java
@@ -19,6 +19,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import org.apache.geode.annotations.Experimental;
+import org.apache.geode.internal.protocol.ProtocolSerializer;
import org.apache.geode.internal.protocol.exception.InvalidProtocolMessageException;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufPrimitiveTypes.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufPrimitiveTypes.java
deleted file mode 100644
index b7ad0a7..0000000
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufPrimitiveTypes.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.internal.protocol.protobuf.v1.utilities;
-
-import org.apache.geode.annotations.Experimental;
-import org.apache.geode.internal.protocol.protobuf.v1.utilities.exception.UnknownProtobufPrimitiveType;
-
-@Experimental
-public enum ProtobufPrimitiveTypes {
-
- STRING(String.class),
- INT(Integer.class),
- LONG(Long.class),
- SHORT(Short.class),
- BYTE(Byte.class),
- BOOLEAN(Boolean.class),
- DOUBLE(Double.class),
- FLOAT(Float.class),
- BINARY(byte[].class);
-
- private Class clazzType;
-
- ProtobufPrimitiveTypes(Class clazz) {
- this.clazzType = clazz;
- }
-
- public static ProtobufPrimitiveTypes valueOf(Class unencodedValueClass)
- throws UnknownProtobufPrimitiveType {
- for (ProtobufPrimitiveTypes protobufPrimitiveTypes : values()) {
- if (protobufPrimitiveTypes.clazzType.equals(unencodedValueClass)) {
- return protobufPrimitiveTypes;
- }
- }
- throw new UnknownProtobufPrimitiveType(
- "There is no primitive protobuf type mapping for class:" + unencodedValueClass);
- }
-}
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilities.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilities.java
index 3b900ea..4c523d2 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilities.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilities.java
@@ -14,21 +14,15 @@
*/
package org.apache.geode.internal.protocol.protobuf.v1.utilities;
-import com.google.protobuf.ByteString;
-
import org.apache.geode.annotations.Experimental;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.internal.protocol.ProtocolErrorCode;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
-import org.apache.geode.internal.protocol.protobuf.v1.EncodingTypeTranslator;
import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
-import org.apache.geode.internal.protocol.protobuf.v1.utilities.exception.UnknownProtobufPrimitiveType;
-import org.apache.geode.internal.protocol.serialization.SerializationService;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
/**
* This class contains helper functions for assistance in creating protobuf objects. This class is
@@ -42,36 +36,6 @@ import org.apache.geode.internal.protocol.serialization.registry.exception.Codec
@Experimental
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}
- * @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
- * @throws CodecNotRegisteredForTypeException - There isn't a protobuf codec for the
- * SerializationType of the passed object
- */
- public static BasicTypes.EncodedValue createEncodedValue(
- SerializationService serializationService, Object unencodedValue)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
-
- try {
- return createPrimitiveEncodedValue(unencodedValue);
- } catch (UnknownProtobufPrimitiveType e) {
- BasicTypes.EncodingType resultEncodingType =
- EncodingTypeTranslator.getEncodingTypeForObject(unencodedValue);
- byte[] encodedValue = serializationService.encode(resultEncodingType, unencodedValue);
- BasicTypes.CustomEncodedValue.Builder customEncodedValueBuilder =
- BasicTypes.CustomEncodedValue.newBuilder().setEncodingType(resultEncodingType)
- .setValue(ByteString.copyFrom(encodedValue));
- return BasicTypes.EncodedValue.newBuilder().setCustomEncodedValue(customEncodedValueBuilder)
- .build();
- }
- }
-
- /**
* Creates a protobuf key,value pair from an encoded key and value
*
* @param key - an EncodedValue containing the key of the entry
@@ -94,20 +58,17 @@ public abstract class ProtobufUtilities {
* @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
+ * @throws EncodingException - The key or value passed doesn't have a corresponding
* SerializationType
- * @throws CodecNotRegisteredForTypeException - There isn't a protobuf codec for the
- * SerializationType of the passed key or value
*/
- public static BasicTypes.Entry createEntry(SerializationService serializationService,
- Object unencodedKey, Object unencodedValue)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ public static BasicTypes.Entry createEntry(ProtobufSerializationService serializationService,
+ Object unencodedKey, Object unencodedValue) throws EncodingException {
if (unencodedValue == null) {
- return BasicTypes.Entry.newBuilder()
- .setKey(createEncodedValue(serializationService, unencodedKey)).build();
+ return BasicTypes.Entry.newBuilder().setKey(serializationService.encode(unencodedKey))
+ .build();
}
- return createEntry(createEncodedValue(serializationService, unencodedKey),
- createEncodedValue(serializationService, unencodedValue));
+ return createEntry(serializationService.encode(unencodedKey),
+ serializationService.encode(unencodedValue));
}
/**
@@ -142,36 +103,6 @@ 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}
- * @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
- * @throws CodecNotRegisteredForTypeException - There isn't a protobuf codec for the
- * SerializationType matching the encodedValues type
- */
- public static Object decodeValue(SerializationService serializationService,
- BasicTypes.EncodedValue encodedValue)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
-
- if (encodedValue.getValueCase() == BasicTypes.EncodedValue.ValueCase.CUSTOMENCODEDVALUE) {
- BasicTypes.CustomEncodedValue customEncodedValue = encodedValue.getCustomEncodedValue();
- return serializationService.decode(customEncodedValue.getEncodingType(),
- customEncodedValue.getValue().toByteArray());
- } else {
- try {
- return getPrimitiveValueFromEncodedValue(encodedValue);
- } catch (UnknownProtobufPrimitiveType unknownProtobufPrimitiveType) {
- throw new UnsupportedEncodingTypeException("Unknown primitive type encoding",
- unknownProtobufPrimitiveType);
- }
- }
- }
-
- /**
* This will convert a ProtocolErrorCode to a BasicTypes.ErrorCode for protobuf
*
* @param errorCode - incoming ProtocolErrorCode
@@ -208,86 +139,4 @@ public abstract class ProtobufUtilities {
public static ClientProtocol.Request.Builder createProtobufRequestBuilder() {
return ClientProtocol.Request.newBuilder();
}
-
- /**
- * This will create an EncodedValue message for a primitive type.
- *
- * @param valueToEncode this represents the potential primitive value that needs to be encoded in
- * an EncodedValue
- * @return EncodedValue message with the correct primitive value populated
- * @throws UnknownProtobufPrimitiveType
- */
- static BasicTypes.EncodedValue createPrimitiveEncodedValue(Object valueToEncode)
- throws UnknownProtobufPrimitiveType {
- ProtobufPrimitiveTypes protobufPrimitiveTypes =
- ProtobufPrimitiveTypes.valueOf(valueToEncode.getClass());
- BasicTypes.EncodedValue.Builder builder = BasicTypes.EncodedValue.newBuilder();
- switch (protobufPrimitiveTypes) {
- case INT: {
- builder.setIntResult((Integer) valueToEncode);
- break;
- }
- case LONG: {
- builder.setLongResult((Long) valueToEncode);
- break;
- }
- case SHORT: {
- builder.setShortResult((Short) valueToEncode);
- break;
- }
- case BYTE: {
- builder.setByteResult((Byte) valueToEncode);
- break;
- }
- case DOUBLE: {
- builder.setDoubleResult((Double) valueToEncode);
- break;
- }
- case FLOAT: {
- builder.setFloatResult((Float) valueToEncode);
- break;
- }
- case BINARY: {
- builder.setBinaryResult(ByteString.copyFrom((byte[]) valueToEncode));
- break;
- }
- case BOOLEAN: {
- builder.setBooleanResult((Boolean) valueToEncode);
- break;
- }
- case STRING: {
- builder.setStringResult((String) valueToEncode);
- break;
- }
-
- }
- return builder.build();
- }
-
- static Object getPrimitiveValueFromEncodedValue(BasicTypes.EncodedValue encodedValue)
- throws UnknownProtobufPrimitiveType {
- switch (encodedValue.getValueCase()) {
- case BINARYRESULT:
- return encodedValue.getBinaryResult().toByteArray();
- case BOOLEANRESULT:
- return encodedValue.getBooleanResult();
- case BYTERESULT:
- return (byte) encodedValue.getByteResult();
- case DOUBLERESULT:
- return encodedValue.getDoubleResult();
- case FLOATRESULT:
- return encodedValue.getFloatResult();
- case INTRESULT:
- return encodedValue.getIntResult();
- case LONGRESULT:
- return encodedValue.getLongResult();
- case SHORTRESULT:
- return (short) encodedValue.getShortResult();
- case STRINGRESULT:
- return encodedValue.getStringResult();
- default:
- throw new UnknownProtobufPrimitiveType(
- "Unknown primitive type for: " + encodedValue.getValueCase());
- }
- }
}
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/exception/UnknownProtobufPrimitiveType.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/exception/UnknownProtobufEncodingType.java
similarity index 89%
rename from geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/exception/UnknownProtobufPrimitiveType.java
rename to geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/exception/UnknownProtobufEncodingType.java
index f5d665c..3b246de 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/exception/UnknownProtobufPrimitiveType.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/exception/UnknownProtobufEncodingType.java
@@ -17,8 +17,8 @@ package org.apache.geode.internal.protocol.protobuf.v1.utilities.exception;
import org.apache.geode.annotations.Experimental;
@Experimental
-public class UnknownProtobufPrimitiveType extends Exception {
- public UnknownProtobufPrimitiveType(String message) {
+public class UnknownProtobufEncodingType extends Exception {
+ public UnknownProtobufEncodingType(String message) {
super(message);
}
}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/EncodingTypeToSerializationTypeTranslatorJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
deleted file mode 100644
index 167d3b4..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/EncodingTypeToSerializationTypeTranslatorJUnitTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.internal.protocol.protobuf;
-
-import static org.junit.Assert.assertSame;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
-import org.apache.geode.internal.protocol.protobuf.v1.EncodingTypeTranslator;
-import org.apache.geode.internal.protocol.serialization.SerializationType;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.test.junit.categories.UnitTest;
-
-@Category(UnitTest.class)
-public class EncodingTypeToSerializationTypeTranslatorJUnitTest {
-
- @Test
- public void testTranslateEncodingTypes() throws UnsupportedEncodingTypeException {
- assertSame(SerializationType.JSON,
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.JSON));
- }
-
- @Test(expected = UnsupportedEncodingTypeException.class)
- public void testTranslateInvalidEncoding_throwsException()
- throws UnsupportedEncodingTypeException {
- EncodingTypeTranslator.getSerializationTypeForEncodingType(BasicTypes.EncodingType.INVALID);
- }
-
- @Test
- public void testAllEncodingTypeTranslations() {
- for (BasicTypes.EncodingType encodingType : BasicTypes.EncodingType.values()) {
- if (!(encodingType.equals(BasicTypes.EncodingType.UNRECOGNIZED)
- || encodingType.equals(BasicTypes.EncodingType.INVALID))) {
- try {
- EncodingTypeTranslator.getSerializationTypeForEncodingType(encodingType);
- } catch (UnsupportedEncodingTypeException e) {
- e.printStackTrace();
- }
- }
- }
- }
-}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
index bc3a515..d8fd4de 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/AuthorizationIntegrationTest.java
@@ -192,7 +192,7 @@ public class AuthorizationIntegrationTest {
ClientProtocol.Message removeMessage = ClientProtocol.Message.newBuilder()
.setRequest(ClientProtocol.Request.newBuilder()
.setRemoveRequest(RegionAPI.RemoveRequest.newBuilder().setRegionName(TEST_REGION)
- .setKey(ProtobufUtilities.createEncodedValue(serializationService, "TEST_KEY"))))
+ .setKey(serializationService.encode("TEST_KEY"))))
.build();
validateOperationAuthorized(removeMessage, inputStream, outputStream,
writeAllowed ? ClientProtocol.Response.ResponseAPICase.REMOVERESPONSE
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/MessageUtil.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/MessageUtil.java
index 56ecdbb..aa76bb2 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/MessageUtil.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/MessageUtil.java
@@ -26,9 +26,7 @@ import com.google.protobuf.MessageLite;
import org.apache.geode.internal.protocol.protobuf.ProtocolVersion;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufRequestUtilities;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.SerializationService;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
public class MessageUtil {
@@ -69,12 +67,10 @@ public class MessageUtil {
}
public static ClientProtocol.Message makePutRequestMessage(
- SerializationService serializationService, String requestKey, String requestValue,
- String requestRegion)
- throws CodecNotRegisteredForTypeException, UnsupportedEncodingTypeException {
- BasicTypes.Entry entry = ProtobufUtilities.createEntry(
- ProtobufUtilities.createEncodedValue(serializationService, requestKey),
- ProtobufUtilities.createEncodedValue(serializationService, requestValue));
+ ProtobufSerializationService serializationService, String requestKey, String requestValue,
+ String requestRegion) throws EncodingException {
+ BasicTypes.Entry entry = ProtobufUtilities.createEntry(serializationService.encode(requestKey),
+ serializationService.encode(requestValue));
ClientProtocol.Request request =
ProtobufRequestUtilities.createPutRequest(requestRegion, entry);
@@ -82,10 +78,10 @@ public class MessageUtil {
}
public static ClientProtocol.Message makeGetRequestMessage(
- SerializationService serializationService, Object requestKey, String requestRegion)
+ ProtobufSerializationService serializationService, Object requestKey, String requestRegion)
throws Exception {
ClientProtocol.Request request = ProtobufRequestUtilities.createGetRequest(requestRegion,
- ProtobufUtilities.createEncodedValue(serializationService, requestKey));
+ serializationService.encode(requestKey));
return ProtobufUtilities.createProtobufMessage(request);
}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheConnectionJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheConnectionJUnitTest.java
index 7f6327d..d565935 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheConnectionJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheConnectionJUnitTest.java
@@ -91,7 +91,7 @@ public class CacheConnectionJUnitTest {
private Cache cache;
private int cacheServerPort;
- private SerializationService serializationService;
+ private ProtobufSerializationService serializationService;
private Socket socket;
private OutputStream outputStream;
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheConnectionTimeoutJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheConnectionTimeoutJUnitTest.java
index 4adf37e..6b266d3 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheConnectionTimeoutJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheConnectionTimeoutJUnitTest.java
@@ -67,7 +67,7 @@ public class CacheConnectionTimeoutJUnitTest {
private final String TEST_REGION = "testRegion";
private Cache cache;
- private SerializationService serializationService;
+ private ProtobufSerializationService serializationService;
private Socket socket;
private OutputStream outputStream;
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheOperationsJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheOperationsJUnitTest.java
index a828fa5..def4fba 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheOperationsJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/acceptance/CacheOperationsJUnitTest.java
@@ -55,22 +55,18 @@ import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.distributed.ConfigurationProperties;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.admin.SSLConfig;
-import org.apache.geode.internal.cache.tier.CommunicationMode;
import org.apache.geode.internal.net.SocketCreator;
import org.apache.geode.internal.net.SocketCreatorFactory;
import org.apache.geode.internal.protocol.exception.InvalidProtocolMessageException;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
-import org.apache.geode.internal.protocol.protobuf.v1.ConnectionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.MessageUtil;
import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.serializer.ProtobufProtocolSerializer;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufRequestUtilities;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.SerializationService;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.apache.geode.util.test.TestUtil;
@@ -95,7 +91,7 @@ public class CacheOperationsJUnitTest {
private Cache cache;
private int cacheServerPort;
- private SerializationService serializationService;
+ private ProtobufSerializationService serializationService;
private Socket socket;
private OutputStream outputStream;
@@ -169,9 +165,9 @@ public class CacheOperationsJUnitTest {
validatePutAllResponse(socket, protobufProtocolSerializer, new HashSet<>());
Set<BasicTypes.EncodedValue> getEntries = new HashSet<>();
- getEntries.add(ProtobufUtilities.createEncodedValue(serializationService, TEST_MULTIOP_KEY1));
- getEntries.add(ProtobufUtilities.createEncodedValue(serializationService, TEST_MULTIOP_KEY2));
- getEntries.add(ProtobufUtilities.createEncodedValue(serializationService, TEST_MULTIOP_KEY3));
+ getEntries.add(serializationService.encode(TEST_MULTIOP_KEY1));
+ getEntries.add(serializationService.encode(TEST_MULTIOP_KEY2));
+ getEntries.add(serializationService.encode(TEST_MULTIOP_KEY3));
RegionAPI.GetAllRequest getAllRequest =
ProtobufRequestUtilities.createGetAllRequest(TEST_REGION, getEntries);
@@ -202,10 +198,8 @@ public class CacheOperationsJUnitTest {
protobufProtocolSerializer.serialize(putAllMessage, outputStream);
HashSet<BasicTypes.EncodedValue> expectedFailedKeys = new HashSet<BasicTypes.EncodedValue>();
- expectedFailedKeys
- .add(ProtobufUtilities.createEncodedValue(serializationService, TEST_MULTIOP_KEY2));
- expectedFailedKeys
- .add(ProtobufUtilities.createEncodedValue(serializationService, TEST_MULTIOP_KEY3));
+ expectedFailedKeys.add(serializationService.encode(TEST_MULTIOP_KEY2));
+ expectedFailedKeys.add(serializationService.encode(TEST_MULTIOP_KEY3));
validatePutAllResponse(socket, protobufProtocolSerializer, expectedFailedKeys);
ClientProtocol.Message getMessage =
@@ -214,8 +208,8 @@ public class CacheOperationsJUnitTest {
validateGetResponse(socket, protobufProtocolSerializer, TEST_MULTIOP_VALUE1);
ClientProtocol.Message removeMessage =
- ProtobufUtilities.createProtobufMessage(ProtobufRequestUtilities.createRemoveRequest(
- TEST_REGION, ProtobufUtilities.createEncodedValue(serializationService, TEST_KEY)));
+ ProtobufUtilities.createProtobufMessage(ProtobufRequestUtilities
+ .createRemoveRequest(TEST_REGION, serializationService.encode(TEST_KEY)));
protobufProtocolSerializer.serialize(removeMessage, outputStream);
validateRemoveResponse(socket, protobufProtocolSerializer);
}
@@ -324,17 +318,16 @@ public class CacheOperationsJUnitTest {
}
private void validateGetAllResponse(Socket socket,
- ProtobufProtocolSerializer protobufProtocolSerializer) throws InvalidProtocolMessageException,
- IOException, UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ ProtobufProtocolSerializer protobufProtocolSerializer)
+ throws InvalidProtocolMessageException, IOException, EncodingException {
ClientProtocol.Response response = deserializeResponse(socket, protobufProtocolSerializer);
assertEquals(ClientProtocol.Response.ResponseAPICase.GETALLRESPONSE,
response.getResponseAPICase());
RegionAPI.GetAllResponse getAllResponse = response.getGetAllResponse();
assertEquals(3, getAllResponse.getEntriesCount());
for (BasicTypes.Entry result : getAllResponse.getEntriesList()) {
- String key = (String) ProtobufUtilities.decodeValue(serializationService, result.getKey());
- String value =
- (String) ProtobufUtilities.decodeValue(serializationService, result.getValue());
+ String key = (String) serializationService.decode(result.getKey());
+ String value = (String) serializationService.decode(result.getValue());
switch (key) {
case TEST_MULTIOP_KEY1:
assertEquals(TEST_MULTIOP_VALUE1, value);
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandlerJUnitTest.java
index 592e8df..7630927 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAllRequestOperationHandlerJUnitTest.java
@@ -39,9 +39,7 @@ import org.apache.geode.internal.protocol.TestExecutionContext;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufRequestUtilities;
-import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
@@ -75,9 +73,8 @@ public class GetAllRequestOperationHandlerJUnitTest extends OperationHandlerJUni
@Test
public void processReturnsExpectedValuesForValidKeys() throws Exception {
- Result result =
- operationHandler.process(serializationServiceStub, generateTestRequest(true, false),
- TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
+ Result result = operationHandler.process(serializationService, generateTestRequest(true, false),
+ TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Success);
@@ -96,7 +93,7 @@ public class GetAllRequestOperationHandlerJUnitTest extends OperationHandlerJUni
@Test
public void processReturnsNoEntriesForNoKeysRequested() throws Exception {
Result result =
- operationHandler.process(serializationServiceStub, generateTestRequest(false, false),
+ operationHandler.process(serializationService, generateTestRequest(false, false),
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Success);
@@ -110,11 +107,10 @@ public class GetAllRequestOperationHandlerJUnitTest extends OperationHandlerJUni
@Test
public void singeNullKey() throws Exception {
HashSet<BasicTypes.EncodedValue> testKeys = new HashSet<>();
- testKeys.add(ProtobufUtilities.createEncodedValue(serializationServiceStub,
- NO_VALUE_PRESENT_FOR_THIS_KEY));
+ testKeys.add(serializationService.encode(NO_VALUE_PRESENT_FOR_THIS_KEY));
RegionAPI.GetAllRequest getAllRequest =
ProtobufRequestUtilities.createGetAllRequest(TEST_REGION, testKeys);
- Result result = operationHandler.process(serializationServiceStub, getAllRequest,
+ Result result = operationHandler.process(serializationService, getAllRequest,
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Success);
@@ -128,9 +124,8 @@ public class GetAllRequestOperationHandlerJUnitTest extends OperationHandlerJUni
@Test
public void multipleKeysWhereOneThrows() throws Exception {
- Result result =
- operationHandler.process(serializationServiceStub, generateTestRequest(true, true),
- TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
+ Result result = operationHandler.process(serializationService, generateTestRequest(true, true),
+ TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Success);
@@ -150,15 +145,14 @@ public class GetAllRequestOperationHandlerJUnitTest extends OperationHandlerJUni
}
private RegionAPI.GetAllRequest generateTestRequest(boolean addKeys, boolean useInvalid)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ throws EncodingException {
HashSet<BasicTypes.EncodedValue> testKeys = new HashSet<>();
if (addKeys) {
- testKeys.add(ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_KEY1));
- testKeys.add(ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_KEY2));
- testKeys.add(ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_KEY3));
+ testKeys.add(serializationService.encode(TEST_KEY1));
+ testKeys.add(serializationService.encode(TEST_KEY2));
+ testKeys.add(serializationService.encode(TEST_KEY3));
if (useInvalid) {
- testKeys
- .add(ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_INVALID_KEY));
+ testKeys.add(serializationService.encode(TEST_INVALID_KEY));
}
}
return ProtobufRequestUtilities.createGetAllRequest(TEST_REGION, testKeys);
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAvailableServersOperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAvailableServersOperationHandlerJUnitTest.java
index 61f72d1..1babc8b 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAvailableServersOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetAvailableServersOperationHandlerJUnitTest.java
@@ -30,7 +30,6 @@ import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.distributed.internal.LocatorLoadSnapshot;
import org.apache.geode.distributed.internal.ServerLocation;
import org.apache.geode.distributed.internal.ServerLocator;
-import org.apache.geode.internal.exception.InvalidExecutionContextException;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
import org.apache.geode.internal.protocol.TestExecutionContext;
@@ -38,7 +37,6 @@ import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.LocatorAPI;
import org.apache.geode.internal.protocol.protobuf.v1.LocatorAPI.GetAvailableServersResponse;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufRequestUtilities;
-import org.apache.geode.internal.protocol.state.exception.ConnectionStateException;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
@@ -96,7 +94,7 @@ public class GetAvailableServersOperationHandlerJUnitTest extends OperationHandl
private Result getOperationHandlerResult(
LocatorAPI.GetAvailableServersRequest getAvailableServersRequest) throws Exception {
- return operationHandler.process(serializationServiceStub, getAvailableServersRequest,
+ return operationHandler.process(serializationService, getAvailableServersRequest,
TestExecutionContext.getLocatorExecutionContext(internalLocatorMock));
}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandlerJUnitTest.java
index 4913e4b..3cada96 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionNamesRequestOperationHandlerJUnitTest.java
@@ -31,7 +31,6 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
-import org.apache.geode.internal.exception.InvalidExecutionContextException;
import org.apache.geode.internal.protocol.Result;
import org.apache.geode.internal.protocol.Success;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
@@ -62,7 +61,7 @@ public class GetRegionNamesRequestOperationHandlerJUnitTest extends OperationHan
@Test
public void processReturnsCacheRegions() throws Exception {
- Result result = operationHandler.process(serializationServiceStub,
+ Result result = operationHandler.process(serializationService,
ProtobufRequestUtilities.createGetRegionNamesRequest(),
getNoAuthCacheExecutionContext(cacheStub));
Assert.assertTrue(result instanceof Success);
@@ -92,7 +91,7 @@ public class GetRegionNamesRequestOperationHandlerJUnitTest extends OperationHan
Cache emptyCache = mock(Cache.class);;
when(emptyCache.rootRegions())
.thenReturn(Collections.unmodifiableSet(new HashSet<Region<String, String>>()));
- Result result = operationHandler.process(serializationServiceStub,
+ Result result = operationHandler.process(serializationService,
ProtobufRequestUtilities.createGetRegionNamesRequest(),
getNoAuthCacheExecutionContext(emptyCache));
Assert.assertTrue(result instanceof Success);
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandlerJUnitTest.java
index bdcec29..53509b0 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRegionRequestOperationHandlerJUnitTest.java
@@ -69,7 +69,7 @@ public class GetRegionRequestOperationHandlerJUnitTest extends OperationHandlerJ
when(regionAttributesStub.getScope()).thenReturn(Scope.DISTRIBUTED_ACK);
- Result result = operationHandler.process(serializationServiceStub,
+ Result result = operationHandler.process(serializationService,
MessageUtil.makeGetRegionRequest(TEST_REGION1), getNoAuthCacheExecutionContext(cacheStub));
RegionAPI.GetRegionResponse response = (RegionAPI.GetRegionResponse) result.getMessage();
BasicTypes.Region region = response.getRegion();
@@ -92,7 +92,7 @@ public class GetRegionRequestOperationHandlerJUnitTest extends OperationHandlerJ
when(emptyCache.rootRegions())
.thenReturn(Collections.unmodifiableSet(new HashSet<Region<String, String>>()));
String unknownRegionName = "UNKNOWN_REGION";
- Result result = operationHandler.process(serializationServiceStub,
+ Result result = operationHandler.process(serializationService,
MessageUtil.makeGetRegionRequest(unknownRegionName),
getNoAuthCacheExecutionContext(emptyCache));
Assert.assertTrue(result instanceof Failure);
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandlerJUnitTest.java
index 72f2759..ac2e196 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/GetRequestOperationHandlerJUnitTest.java
@@ -18,7 +18,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import com.google.protobuf.ByteString;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -32,11 +31,10 @@ import org.apache.geode.internal.protocol.Success;
import org.apache.geode.internal.protocol.TestExecutionContext;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufRequestUtilities;
-import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
@@ -67,7 +65,7 @@ public class GetRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
@Test
public void processReturnsTheEncodedValueFromTheRegion() throws Exception {
RegionAPI.GetRequest getRequest = generateTestRequest(false, false, false);
- Result result = operationHandler.process(serializationServiceStub, getRequest,
+ Result result = operationHandler.process(serializationService, getRequest,
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
Assert.assertTrue(result instanceof Success);
@@ -81,7 +79,7 @@ public class GetRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
@Test
public void processReturnsUnsucessfulResponseForInvalidRegion() throws Exception {
RegionAPI.GetRequest getRequest = generateTestRequest(true, false, false);
- Result response = operationHandler.process(serializationServiceStub, getRequest,
+ Result response = operationHandler.process(serializationService, getRequest,
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
Assert.assertTrue(response instanceof Failure);
@@ -94,7 +92,7 @@ public class GetRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
@Test
public void processReturnsKeyNotFoundWhenKeyIsNotFound() throws Exception {
RegionAPI.GetRequest getRequest = generateTestRequest(false, true, false);
- Result response = operationHandler.process(serializationServiceStub, getRequest,
+ Result response = operationHandler.process(serializationService, getRequest,
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
Assert.assertTrue(response instanceof Success);
@@ -103,7 +101,7 @@ public class GetRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
@Test
public void processReturnsLookupFailureWhenKeyFoundWithNoValue() throws Exception {
RegionAPI.GetRequest getRequest = generateTestRequest(false, false, true);
- Result response = operationHandler.process(serializationServiceStub, getRequest,
+ Result response = operationHandler.process(serializationService, getRequest,
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
Assert.assertTrue(response instanceof Success);
@@ -111,17 +109,16 @@ public class GetRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
@Test
public void processReturnsErrorWhenUnableToDecodeRequest() throws Exception {
- CodecNotRegisteredForTypeException exception =
- new CodecNotRegisteredForTypeException("error finding codec for type");
- when(serializationServiceStub.decode(any(), any())).thenThrow(exception);
+ EncodingException exception = new EncodingException("error finding codec for type");
+ ProtobufSerializationService serializationServiceStub =
+ mock(ProtobufSerializationService.class);
+ when(serializationServiceStub.decode(any())).thenThrow(exception);
- ByteString byteString = ByteString.copyFrom("{\"someKey\":\"someValue\"}", "UTF-8");
- BasicTypes.CustomEncodedValue.Builder customEncodedValueBuilder = BasicTypes.CustomEncodedValue
- .newBuilder().setEncodingType(BasicTypes.EncodingType.JSON).setValue(byteString);
BasicTypes.EncodedValue encodedKey = BasicTypes.EncodedValue.newBuilder()
- .setCustomEncodedValue(customEncodedValueBuilder).build();
+ .setJsonObjectResult("{\"someKey\":\"someValue\"}").build();
RegionAPI.GetRequest getRequest =
ProtobufRequestUtilities.createGetRequest(TEST_REGION, encodedKey).getGetRequest();
+
Result response = operationHandler.process(serializationServiceStub, getRequest,
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
@@ -133,12 +130,10 @@ public class GetRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
}
private RegionAPI.GetRequest generateTestRequest(boolean missingRegion, boolean missingKey,
- boolean nulledKey)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ boolean nulledKey) throws EncodingException {
String region = missingRegion ? MISSING_REGION : TEST_REGION;
String key = missingKey ? MISSING_KEY : (nulledKey ? NULLED_KEY : TEST_KEY);
- BasicTypes.EncodedValue testKey =
- ProtobufUtilities.createEncodedValue(serializationServiceStub, key);
+ BasicTypes.EncodedValue testKey = serializationService.encode(key);
return ProtobufRequestUtilities.createGetRequest(region, testKey).getGetRequest();
}
}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/OperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/OperationHandlerJUnitTest.java
index 7a94afa..b1fb399 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/OperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/OperationHandlerJUnitTest.java
@@ -21,18 +21,18 @@ import org.junit.experimental.categories.Category;
import org.apache.geode.cache.Cache;
import org.apache.geode.internal.protocol.operations.OperationHandler;
-import org.apache.geode.internal.protocol.serialization.SerializationService;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
public class OperationHandlerJUnitTest {
protected Cache cacheStub;
- protected SerializationService serializationServiceStub;
+ protected ProtobufSerializationService serializationService;
protected OperationHandler operationHandler;
@Before
public void setUp() throws Exception {
cacheStub = mock(Cache.class);
- serializationServiceStub = mock(SerializationService.class);
+ serializationService = new ProtobufSerializationService();
}
}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandlerJUnitTest.java
index 41081ab..010fca8 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutAllRequestOperationHandlerJUnitTest.java
@@ -37,8 +37,7 @@ import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufRequestUtilities;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
import org.apache.geode.test.dunit.Assert;
import org.apache.geode.test.junit.categories.UnitTest;
@@ -70,8 +69,8 @@ public class PutAllRequestOperationHandlerJUnitTest extends OperationHandlerJUni
public void processInsertsMultipleValidEntriesInCache() throws Exception {
PutAllRequestOperationHandler operationHandler = new PutAllRequestOperationHandler();
- Result result = operationHandler.process(serializationServiceStub,
- generateTestRequest(false, true), getNoAuthCacheExecutionContext(cacheStub));
+ Result result = operationHandler.process(serializationService, generateTestRequest(false, true),
+ getNoAuthCacheExecutionContext(cacheStub));
Assert.assertTrue(result instanceof Success);
@@ -84,8 +83,8 @@ public class PutAllRequestOperationHandlerJUnitTest extends OperationHandlerJUni
public void processWithInvalidEntrySucceedsAndReturnsFailedKey() throws Exception {
PutAllRequestOperationHandler operationHandler = new PutAllRequestOperationHandler();
- Result result = operationHandler.process(serializationServiceStub,
- generateTestRequest(true, true), getNoAuthCacheExecutionContext(cacheStub));
+ Result result = operationHandler.process(serializationService, generateTestRequest(true, true),
+ getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Success);
verify(regionMock).put(TEST_KEY1, TEST_VALUE1);
@@ -95,15 +94,14 @@ public class PutAllRequestOperationHandlerJUnitTest extends OperationHandlerJUni
RegionAPI.PutAllResponse putAllResponse = (RegionAPI.PutAllResponse) result.getMessage();
assertEquals(1, putAllResponse.getFailedKeysCount());
BasicTypes.KeyedError error = putAllResponse.getFailedKeys(0);
- assertEquals(TEST_INVALID_KEY,
- ProtobufUtilities.decodeValue(serializationServiceStub, error.getKey()));
+ assertEquals(TEST_INVALID_KEY, serializationService.decode(error.getKey()));
}
@Test
public void processWithNoEntriesPasses() throws Exception {
PutAllRequestOperationHandler operationHandler = new PutAllRequestOperationHandler();
- Result result = operationHandler.process(serializationServiceStub,
+ Result result = operationHandler.process(serializationService,
generateTestRequest(false, false), getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Success);
@@ -112,23 +110,19 @@ public class PutAllRequestOperationHandlerJUnitTest extends OperationHandlerJUni
}
private RegionAPI.PutAllRequest generateTestRequest(boolean addInvalidKey, boolean addValidKeys)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ throws EncodingException {
Set<BasicTypes.Entry> entries = new HashSet<>();
if (addInvalidKey) {
- entries.add(ProtobufUtilities.createEntry(
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_INVALID_KEY),
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_INVALID_VALUE)));
+ entries.add(ProtobufUtilities.createEntry(serializationService.encode(TEST_INVALID_KEY),
+ serializationService.encode(TEST_INVALID_VALUE)));
}
if (addValidKeys) {
- entries.add(ProtobufUtilities.createEntry(
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_KEY1),
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_VALUE1)));
- entries.add(ProtobufUtilities.createEntry(
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_KEY2),
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_VALUE2)));
- entries.add(ProtobufUtilities.createEntry(
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_KEY3),
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_VALUE3)));
+ entries.add(ProtobufUtilities.createEntry(serializationService.encode(TEST_KEY1),
+ serializationService.encode(TEST_VALUE1)));
+ entries.add(ProtobufUtilities.createEntry(serializationService.encode(TEST_KEY2),
+ serializationService.encode(TEST_VALUE2)));
+ entries.add(ProtobufUtilities.createEntry(serializationService.encode(TEST_KEY3),
+ serializationService.encode(TEST_VALUE3)));
}
return ProtobufRequestUtilities.createPutAllRequest(TEST_REGION, entries).getPutAllRequest();
}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandlerJUnitTest.java
index ef07fca..0b7a85c 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/PutRequestOperationHandlerJUnitTest.java
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.protobuf.ByteString;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -36,11 +35,11 @@ import org.apache.geode.internal.protocol.Success;
import org.apache.geode.internal.protocol.TestExecutionContext;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufRequestUtilities;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
@@ -63,7 +62,7 @@ public class PutRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
@Test
public void test_puttingTheEncodedEntryIntoRegion() throws Exception {
PutRequestOperationHandler operationHandler = new PutRequestOperationHandler();
- Result result = operationHandler.process(serializationServiceStub, generateTestRequest(),
+ Result result = operationHandler.process(serializationService, generateTestRequest(),
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Success);
@@ -75,20 +74,17 @@ public class PutRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
@Test
public void test_invalidEncodingType() throws Exception {
String exceptionText = "unsupported type!";
- UnsupportedEncodingTypeException exception =
- new UnsupportedEncodingTypeException(exceptionText);
- when(serializationServiceStub.decode(any(), any())).thenThrow(exception);
+ EncodingException exception = new EncodingException(exceptionText);
+ ProtobufSerializationService serializationServiceStub =
+ mock(ProtobufSerializationService.class);
+ when(serializationServiceStub.decode(any())).thenThrow(exception);
- ByteString byteString = ByteString.copyFrom("{\"someKey\":\"someValue\"}", "UTF-8");
- BasicTypes.CustomEncodedValue.Builder customEncodedValueBuilder = BasicTypes.CustomEncodedValue
- .newBuilder().setEncodingType(BasicTypes.EncodingType.JSON).setValue(byteString);
BasicTypes.EncodedValue encodedKey = BasicTypes.EncodedValue.newBuilder()
- .setCustomEncodedValue(customEncodedValueBuilder).build();
+ .setJsonObjectResult("{\"someKey\":\"someValue\"}").build();
PutRequestOperationHandler operationHandler = new PutRequestOperationHandler();
- BasicTypes.EncodedValue testValue =
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_VALUE);
+ BasicTypes.EncodedValue testValue = serializationService.encode(TEST_VALUE);
BasicTypes.Entry testEntry = ProtobufUtilities.createEntry(encodedKey, testValue);
RegionAPI.PutRequest putRequest =
ProtobufRequestUtilities.createPutRequest(TEST_REGION, testEntry).getPutRequest();
@@ -105,7 +101,7 @@ public class PutRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
public void test_RegionNotFound() throws Exception {
when(cacheStub.getRegion(TEST_REGION)).thenReturn(null);
PutRequestOperationHandler operationHandler = new PutRequestOperationHandler();
- Result result = operationHandler.process(serializationServiceStub, generateTestRequest(),
+ Result result = operationHandler.process(serializationService, generateTestRequest(),
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Failure);
@@ -119,7 +115,7 @@ public class PutRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
when(regionMock.put(any(), any())).thenThrow(ClassCastException.class);
PutRequestOperationHandler operationHandler = new PutRequestOperationHandler();
- Result result = operationHandler.process(serializationServiceStub, generateTestRequest(),
+ Result result = operationHandler.process(serializationService, generateTestRequest(),
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Failure);
@@ -128,12 +124,9 @@ public class PutRequestOperationHandlerJUnitTest extends OperationHandlerJUnitTe
assertEquals(BasicTypes.ErrorCode.CONSTRAINT_VIOLATION, errorMessage.getError().getErrorCode());
}
- private RegionAPI.PutRequest generateTestRequest()
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
- BasicTypes.EncodedValue testKey =
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_KEY);
- BasicTypes.EncodedValue testValue =
- ProtobufUtilities.createEncodedValue(serializationServiceStub, TEST_VALUE);
+ private RegionAPI.PutRequest generateTestRequest() throws EncodingException {
+ BasicTypes.EncodedValue testKey = serializationService.encode(TEST_KEY);
+ BasicTypes.EncodedValue testValue = serializationService.encode(TEST_VALUE);
BasicTypes.Entry testEntry = ProtobufUtilities.createEntry(testKey, testValue);
return ProtobufRequestUtilities.createPutRequest(TEST_REGION, testEntry).getPutRequest();
}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandlerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandlerJUnitTest.java
index e8bd857..6835b85 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandlerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/operations/RemoveRequestOperationHandlerJUnitTest.java
@@ -21,7 +21,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.protobuf.ByteString;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -34,11 +33,10 @@ import org.apache.geode.internal.protocol.Success;
import org.apache.geode.internal.protocol.TestExecutionContext;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufRequestUtilities;
-import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
-import org.apache.geode.internal.protocol.serialization.exception.UnsupportedEncodingTypeException;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
@@ -67,7 +65,7 @@ public class RemoveRequestOperationHandlerJUnitTest extends OperationHandlerJUni
@Test
public void processValidKeyRemovesTheEntryAndReturnSuccess() throws Exception {
RegionAPI.RemoveRequest removeRequest = generateTestRequest(false, false).getRemoveRequest();
- Result result = operationHandler.process(serializationServiceStub, removeRequest,
+ Result result = operationHandler.process(serializationService, removeRequest,
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Success);
@@ -77,7 +75,7 @@ public class RemoveRequestOperationHandlerJUnitTest extends OperationHandlerJUni
@Test
public void processReturnsUnsucessfulResponseForInvalidRegion() throws Exception {
RegionAPI.RemoveRequest removeRequest = generateTestRequest(true, false).getRemoveRequest();
- Result result = operationHandler.process(serializationServiceStub, removeRequest,
+ Result result = operationHandler.process(serializationService, removeRequest,
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Failure);
@@ -89,7 +87,7 @@ public class RemoveRequestOperationHandlerJUnitTest extends OperationHandlerJUni
@Test
public void processReturnsSuccessWhenKeyIsNotFound() throws Exception {
RegionAPI.RemoveRequest removeRequest = generateTestRequest(false, true).getRemoveRequest();
- Result result = operationHandler.process(serializationServiceStub, removeRequest,
+ Result result = operationHandler.process(serializationService, removeRequest,
TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub));
assertTrue(result instanceof Success);
@@ -97,15 +95,13 @@ public class RemoveRequestOperationHandlerJUnitTest extends OperationHandlerJUni
@Test
public void processReturnsErrorWhenUnableToDecodeRequest() throws Exception {
- CodecNotRegisteredForTypeException exception =
- new CodecNotRegisteredForTypeException("error finding codec for type");
- when(serializationServiceStub.decode(any(), any())).thenThrow(exception);
+ EncodingException exception = new EncodingException("error finding codec for type");
+ ProtobufSerializationService serializationServiceStub =
+ mock(ProtobufSerializationService.class);
+ when(serializationServiceStub.decode(any())).thenThrow(exception);
- ByteString byteString = ByteString.copyFrom("{\"someKey\":\"someValue\"}", "UTF-8");
- BasicTypes.CustomEncodedValue.Builder customEncodedValueBuilder = BasicTypes.CustomEncodedValue
- .newBuilder().setEncodingType(BasicTypes.EncodingType.JSON).setValue(byteString);
BasicTypes.EncodedValue encodedKey = BasicTypes.EncodedValue.newBuilder()
- .setCustomEncodedValue(customEncodedValueBuilder).build();
+ .setJsonObjectResult("{\"someKey\":\"someValue\"}").build();
RegionAPI.RemoveRequest removeRequest =
ProtobufRequestUtilities.createRemoveRequest(TEST_REGION, encodedKey).getRemoveRequest();;
@@ -119,11 +115,10 @@ public class RemoveRequestOperationHandlerJUnitTest extends OperationHandlerJUni
}
private ClientProtocol.Request generateTestRequest(boolean missingRegion, boolean missingKey)
- throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
+ throws EncodingException {
String region = missingRegion ? MISSING_REGION : TEST_REGION;
String key = missingKey ? MISSING_KEY : TEST_KEY;
- BasicTypes.EncodedValue testKey =
- ProtobufUtilities.createEncodedValue(serializationServiceStub, key);
+ BasicTypes.EncodedValue testKey = serializationService.encode(key);
return ProtobufRequestUtilities.createRemoveRequest(region, testKey);
}
}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serialization/codec/JSONCodecJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serialization/codec/JsonPdxConverterJUnitTest.java
similarity index 95%
rename from geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serialization/codec/JSONCodecJUnitTest.java
rename to geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serialization/codec/JsonPdxConverterJUnitTest.java
index 944b038..33e0731 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serialization/codec/JSONCodecJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serialization/codec/JsonPdxConverterJUnitTest.java
@@ -15,7 +15,6 @@
package org.apache.geode.internal.protocol.protobuf.v1.serialization.codec;
import static java.util.Arrays.asList;
-import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -34,7 +33,7 @@ import org.apache.geode.cache.CacheFactory;
import org.apache.geode.distributed.ConfigurationProperties;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.internal.protocol.serialization.codec.JSONCodec;
+import org.apache.geode.internal.protocol.serialization.JsonPdxConverter;
import org.apache.geode.pdx.JSONFormatter;
import org.apache.geode.pdx.PdxInstance;
import org.apache.geode.pdx.PdxInstanceFactory;
@@ -42,7 +41,7 @@ import org.apache.geode.pdx.WritablePdxInstance;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
-public class JSONCodecJUnitTest {
+public class JsonPdxConverterJUnitTest {
private String complexJSONString = "{\n" + " \"_id\": \"599c7d885df276ac3e0bf10a\",\n"
+ " \"index\": 0,\n" + " \"guid\": \"395902d8-36ed-4178-ad70-2f720c557c55\",\n"
@@ -91,18 +90,18 @@ public class JSONCodecJUnitTest {
pdxInstanceFactory.writeBoolean("boolean", true);
PdxInstance pdxInstance = pdxInstanceFactory.create();
- byte[] encodedJSONByte = new JSONCodec().encode(pdxInstance);
+ String encodedJSON = new JsonPdxConverter().encode(pdxInstance);
String lineSeparator = System.lineSeparator();
String expectedJsonString = "{" + lineSeparator + "" + " \"string\" : \"someString\","
+ lineSeparator + "" + " \"boolean\" : true" + lineSeparator + "}";
- assertArrayEquals(expectedJsonString.getBytes(), encodedJSONByte);
+ assertEquals(expectedJsonString, encodedJSON);
}
@Test
- public void testComplexJSONEncode() {
+ public void testComplexJSONEncode() throws Exception {
PdxInstance pdxInstanceForComplexJSONString = createPDXInstanceForComplexJSONString();
- PdxInstance decodedJSONPdxInstance = new JSONCodec().decode(complexJSONString.getBytes());
+ PdxInstance decodedJSONPdxInstance = new JsonPdxConverter().decode(complexJSONString);
pdxInstanceEquals(pdxInstanceForComplexJSONString, decodedJSONPdxInstance);
}
@@ -219,7 +218,7 @@ public class JSONCodecJUnitTest {
@Test
public void testJSONDecode() throws Exception {
- PdxInstance pdxInstance = new JSONCodec().decode(complexJSONString.getBytes());
+ PdxInstance pdxInstance = new JsonPdxConverter().decode(complexJSONString);
assertNotNull(pdxInstance);
List<String> fieldNames = asList("_id", "index", "guid", "isActive", "balance", "picture",
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serialization/registry/CodecRegistryJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serialization/registry/CodecRegistryJUnitTest.java
deleted file mode 100644
index c421baf..0000000
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serialization/registry/CodecRegistryJUnitTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.internal.protocol.protobuf.v1.serialization.registry;
-
-import static junit.framework.TestCase.assertNotNull;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.internal.protocol.serialization.SerializationType;
-import org.apache.geode.internal.protocol.serialization.registry.SerializationCodecRegistry;
-import org.apache.geode.internal.protocol.serialization.registry.exception.CodecNotRegisteredForTypeException;
-import org.apache.geode.test.junit.categories.UnitTest;
-
-@Category(UnitTest.class)
-public class CodecRegistryJUnitTest {
- private SerializationCodecRegistry codecRegistry;
-
- @Before
- public void startup() {
- codecRegistry = new SerializationCodecRegistry();
- }
-
- @After
- public void tearDown() {
- codecRegistry.shutdown();
- }
-
- @Test
- public void loadingWorks() throws CodecNotRegisteredForTypeException {
- // This test relies on the serializer being present and registered in META-INF, which it is in
- // this package.
- assertNotNull(codecRegistry.getCodecForType(SerializationType.JSON));
- }
-}
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtobufProtocolSerializerJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtobufProtocolSerializerJUnitTest.java
index b9671b8..b0b76e4 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtobufProtocolSerializerJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/serializer/ProtobufProtocolSerializerJUnitTest.java
@@ -24,6 +24,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.apache.geode.internal.protocol.ProtocolSerializer;
import org.apache.geode.internal.protocol.exception.InvalidProtocolMessageException;
import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
import org.apache.geode.internal.protocol.protobuf.v1.MessageUtil;
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilitiesJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilitiesJUnitTest.java
index c1a0743..77e9bf3 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilitiesJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/protobuf/v1/utilities/ProtobufUtilitiesJUnitTest.java
@@ -25,136 +25,132 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
-import org.apache.geode.internal.protocol.protobuf.v1.utilities.exception.UnknownProtobufPrimitiveType;
+import org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
+import org.apache.geode.internal.protocol.serialization.exception.EncodingException;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
public class ProtobufUtilitiesJUnitTest {
+
+ private ProtobufSerializationService protobufSerializationService =
+ new ProtobufSerializationService();;
+
@Test
- public void getIntPrimitiveFromEncodedValue() throws UnknownProtobufPrimitiveType {
+ public void getIntPrimitiveFromEncodedValue() throws Exception {
BasicTypes.EncodedValue.Builder builder = BasicTypes.EncodedValue.newBuilder();
BasicTypes.EncodedValue encodedValue = builder.setIntResult(1).build();
- assertEquals(1, ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ assertEquals(1, protobufSerializationService.decode(encodedValue));
}
@Test
- public void getLongPrimitiveFromEncodedValue() throws UnknownProtobufPrimitiveType {
+ public void getLongPrimitiveFromEncodedValue() throws Exception {
BasicTypes.EncodedValue encodedValue =
BasicTypes.EncodedValue.newBuilder().setLongResult(1).build();
- assertEquals(1l, ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ assertEquals(1l, protobufSerializationService.decode(encodedValue));
}
@Test
- public void getShortPrimitiveFromEncodedValue() throws UnknownProtobufPrimitiveType {
+ public void getShortPrimitiveFromEncodedValue() throws Exception {
BasicTypes.EncodedValue encodedValue =
BasicTypes.EncodedValue.newBuilder().setShortResult(1).build();
- assertEquals((short) 1, ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ assertEquals((short) 1, protobufSerializationService.decode(encodedValue));
}
@Test
- public void getBytePrimitiveFromEncodedValue() throws UnknownProtobufPrimitiveType {
+ public void getBytePrimitiveFromEncodedValue() throws Exception {
BasicTypes.EncodedValue encodedValue =
BasicTypes.EncodedValue.newBuilder().setByteResult(1).build();
- assertEquals((byte) 1, ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ assertEquals((byte) 1, protobufSerializationService.decode(encodedValue));
}
@Test
- public void getBooleanPrimitiveFromEncodedValue() throws UnknownProtobufPrimitiveType {
+ public void getBooleanPrimitiveFromEncodedValue() throws Exception {
BasicTypes.EncodedValue encodedValue =
BasicTypes.EncodedValue.newBuilder().setBooleanResult(true).build();
- assertEquals(true, ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ assertEquals(true, protobufSerializationService.decode(encodedValue));
}
@Test
- public void getDoublePrimitiveFromEncodedValue() throws UnknownProtobufPrimitiveType {
+ public void getDoublePrimitiveFromEncodedValue() throws Exception {
BasicTypes.EncodedValue encodedValue =
BasicTypes.EncodedValue.newBuilder().setDoubleResult(1.0).build();
- assertEquals(1.0, ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ assertEquals(1.0, protobufSerializationService.decode(encodedValue));
}
@Test
- public void getFloatPrimitiveFromEncodedValue() throws UnknownProtobufPrimitiveType {
+ public void getFloatPrimitiveFromEncodedValue() throws Exception {
BasicTypes.EncodedValue encodedValue =
BasicTypes.EncodedValue.newBuilder().setFloatResult(1).build();
- assertEquals(1f, ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ assertEquals(1f, protobufSerializationService.decode(encodedValue));
}
@Test
- public void getByteArrayPrimitiveFromEncodedValue() throws UnknownProtobufPrimitiveType {
+ public void getByteArrayPrimitiveFromEncodedValue() throws Exception {
BasicTypes.EncodedValue encodedValue = BasicTypes.EncodedValue.newBuilder()
.setBinaryResult(ByteString.copyFrom("SomeBinary".getBytes())).build();
assertArrayEquals("SomeBinary".getBytes(Charset.forName("UTF-8")),
- (byte[]) ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ (byte[]) protobufSerializationService.decode(encodedValue));
}
@Test
- public void getStringPrimitiveFromEncodedValue() throws UnknownProtobufPrimitiveType {
+ public void getStringPrimitiveFromEncodedValue() throws Exception {
BasicTypes.EncodedValue encodedValue =
BasicTypes.EncodedValue.newBuilder().setStringResult("SomeString").build();
- assertEquals("SomeString", ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ assertEquals("SomeString", protobufSerializationService.decode(encodedValue));
}
@Test
- public void doesAIntValueSuccessfullyEncodeIntoPrimitiveEncodedValues()
- throws UnknownProtobufPrimitiveType {
+ public void doesAIntValueSuccessfullyEncodeIntoPrimitiveEncodedValues() throws Exception {
createAndVerifyEncodedValue(1);
}
@Test
- public void doesALongValueSuccessfullyEncodeIntoPrimitiveEncodedValues()
- throws UnknownProtobufPrimitiveType {
+ public void doesALongValueSuccessfullyEncodeIntoPrimitiveEncodedValues() throws Exception {
createAndVerifyEncodedValue(1l);
}
@Test
- public void doesAShortValueSuccessfullyEncodeIntoPrimitiveEncodedValues()
- throws UnknownProtobufPrimitiveType {
+ public void doesAShortValueSuccessfullyEncodeIntoPrimitiveEncodedValues() throws Exception {
createAndVerifyEncodedValue((short) 1);
}
@Test
- public void doesAByteValueSuccessfullyEncodeIntoPrimitiveEncodedValues()
- throws UnknownProtobufPrimitiveType {
+ public void doesAByteValueSuccessfullyEncodeIntoPrimitiveEncodedValues() throws Exception {
createAndVerifyEncodedValue((byte) 1);
}
@Test
- public void doesABooleanValueSuccessfullyEncodeIntoPrimitiveEncodedValues()
- throws UnknownProtobufPrimitiveType {
+ public void doesABooleanValueSuccessfullyEncodeIntoPrimitiveEncodedValues() throws Exception {
createAndVerifyEncodedValue(true);
}
@Test
- public void doesADoubleValueSuccessfullyEncodeIntoPrimitiveEncodedValues()
- throws UnknownProtobufPrimitiveType {
+ public void doesADoubleValueSuccessfullyEncodeIntoPrimitiveEncodedValues() throws Exception {
createAndVerifyEncodedValue((double) 1);
}
@Test
- public void doesAFloatValueSuccessfullyEncodeIntoPrimitiveEncodedValues()
- throws UnknownProtobufPrimitiveType {
+ public void doesAFloatValueSuccessfullyEncodeIntoPrimitiveEncodedValues() throws Exception {
createAndVerifyEncodedValue((float) 1);
}
@Test
- public void doesABinaryValueSuccessfullyEncodeIntoPrimitiveEncodedValues()
- throws UnknownProtobufPrimitiveType {
+ public void doesABinaryValueSuccessfullyEncodeIntoPrimitiveEncodedValues() throws Exception {
createAndVerifyEncodedValue("Some Text to Binary".getBytes());
}
@Test
- public void doesAStringValueSuccessfullyEncodeIntoPrimitiveEncodedValues()
- throws UnknownProtobufPrimitiveType {
+ public void doesAStringValueSuccessfullyEncodeIntoPrimitiveEncodedValues() throws Exception {
createAndVerifyEncodedValue("Some String text to test");
}
- private <T> void createAndVerifyEncodedValue(T testObj) throws UnknownProtobufPrimitiveType {
- BasicTypes.EncodedValue encodedValue = ProtobufUtilities.createPrimitiveEncodedValue(testObj);
+ private <T> void createAndVerifyEncodedValue(T testObj) throws EncodingException {
+ BasicTypes.EncodedValue encodedValue = protobufSerializationService.encode(testObj);
if (testObj instanceof byte[]) {
assertArrayEquals((byte[]) testObj,
- (byte[]) ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ (byte[]) protobufSerializationService.decode(encodedValue));
} else {
- assertEquals(testObj, ProtobufUtilities.getPrimitiveValueFromEncodedValue(encodedValue));
+ assertEquals(testObj, protobufSerializationService.decode(encodedValue));
}
}
}
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].