[
https://issues.apache.org/jira/browse/GEODE-4080?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16298811#comment-16298811
]
ASF GitHub Bot commented on GEODE-4080:
---------------------------------------
galen-pivotal closed pull request #1171: GEODE-4080: Protobuf JSON objects are
in a proto string
URL: https://github.com/apache/geode/pull/1171
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 370d50180a..3ff500c54b 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 @@
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 OperationContext(Function<ProtocolRequest,
OperationRequest> fromRequest,
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 6fd566ad2b..456d0e25af 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 dc1fe2ef31..3697d6be7a 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.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 @@
* @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 a27f1464e1..88e242ee87 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 8e6a265492..4544735032 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 @@
*/
@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 55fce2a891..b86d4dceb0 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 @@
* @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 c7b425e95c..776846ed90 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 @@
* 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 045cd36c96..0000000000
---
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 45284ba99e..0000000000
---
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 3d554dbe1b..0000000000
---
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 fcbbeafd9a..0000000000
---
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 2afe472823..827a0a7124 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 @@
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 void encodeAndDecode() throws Exception {
}
@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 9ab7d2f203..410c56327c 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-protobuf/src/main/java/org/apache/geode/internal/protocol/operations/ProtobufOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/operations/ProtobufOperationHandler.java
new file mode 100644
index 0000000000..b4bc817485
--- /dev/null
+++
b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/operations/ProtobufOperationHandler.java
@@ -0,0 +1,31 @@
+/*
+ * 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.operations;
+
+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.protobuf.v1.ClientProtocol;
+import
org.apache.geode.internal.protocol.protobuf.v1.ProtobufSerializationService;
+import
org.apache.geode.internal.protocol.state.exception.ConnectionStateException;
+
+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 0764f54652..0000000000
---
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 c534444079..de01e5cb34 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 @@
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 783c64c5c7..c052f440ff 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 2b717fc546..1d5319c7fb 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.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 @@
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 c97b73bae3..c6f68c6c77 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.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 2a8c095e21..9e639665b4 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.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 cef71fd581..ed5daae94e 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.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 eb4d7fc69e..5b62b074cc 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.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 @@
}
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 0af9ab8b8a..7a2426cd45 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.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 @@
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 06cfd35215..8f0ed28094 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.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 @@
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 @@
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 720e7c7456..a3c99cf0fd 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.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 @@
}
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 727a693685..44eb1bab34 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.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.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 0cdb39ec6b..84742e87d1 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.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 b7ad0a786d..0000000000
---
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 3b900eaed1..4c523d2d61 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
@@ -41,36 +35,6 @@
*/
@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
*
@@ -94,20 +58,17 @@
* @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));
}
/**
@@ -141,36 +102,6 @@
return
ClientProtocol.Request.newBuilder().setGetAllRequest(getAllRequest).build();
}
- /**
- * 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
*
@@ -208,86 +139,4 @@ public static Object decodeValue(SerializationService
serializationService,
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 f5d665ce1a..3b246de8b7 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 @@
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 167d3b47be..0000000000
---
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 bc3a5158b3..d8fd4deda1 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 @@ private void verifyOperations(boolean readAllowed, boolean
writeAllowed) throws
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 56ecdbbcb1..aa76bb2228 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 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 static void sendHandshake(Socket socket) throws
IOException {
}
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 static void sendHandshake(Socket socket) throws
IOException {
}
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 7f6327d649..d565935077 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 @@
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 4adf37e29a..6b266d31b3 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 @@
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 a828fa5376..def4fbaee6 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.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 @@
private Cache cache;
private int cacheServerPort;
- private SerializationService serializationService;
+ private ProtobufSerializationService serializationService;
private Socket socket;
private OutputStream outputStream;
@@ -169,9 +165,9 @@ public void testNewProtocolWithMultikeyOperations() throws
Exception {
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 void
multiKeyOperationErrorsWithClasscastException() throws Exception {
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 void multiKeyOperationErrorsWithClasscastException()
throws Exception {
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 @@ private void validatePutAllResponse(Socket socket,
}
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 592e8df330..7630927074 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.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 void setUp() throws Exception {
@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 void processReturnsExpectedValuesForValidKeys() throws
Exception {
@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 void processReturnsNoEntriesForNoKeysRequested()
throws Exception {
@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 void singeNullKey() throws Exception {
@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 void multipleKeysWhereOneThrows() throws Exception
{
}
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 61f72d12ba..1babc8b473 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.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.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 void testWhenServersFromSnapshotAreNullReturnsEmtpy()
throws Exception {
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 4913e4b42d..3cada9608e 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.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 void setUp() throws Exception {
@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 void processReturnsNoCacheRegions() throws Exception {
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 bdcec29ee9..53509b0ff6 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 void processReturnsCacheRegions() throws Exception {
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 void processReturnsNoCacheRegions() throws Exception {
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 72f275948f..ac2e1960bc 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.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.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 void setUp() throws Exception {
@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 void processReturnsTheEncodedValueFromTheRegion()
throws Exception {
@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 void
processReturnsUnsucessfulResponseForInvalidRegion() throws Exception
@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 void processReturnsKeyNotFoundWhenKeyIsNotFound()
throws Exception {
@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 void
processReturnsLookupFailureWhenKeyFoundWithNoValue() throws Exceptio
@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 void
processReturnsErrorWhenUnableToDecodeRequest() throws Exception {
}
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 7a94afa2e5..b1fb399f4c 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.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 41081ab9d8..010fca8d57 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.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 void setUp() throws Exception {
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 void processInsertsMultipleValidEntriesInCache()
throws Exception {
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 void
processWithInvalidEntrySucceedsAndReturnsFailedKey() throws Exceptio
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 void processWithNoEntriesPasses() throws Exception
{
}
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 ef07fcabdf..0b7a85cc2b 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.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.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 void setUp() throws Exception {
@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 void test_puttingTheEncodedEntryIntoRegion() throws
Exception {
@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 void test_invalidEncodingType() throws Exception {
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 void test_RegionThrowsClasscastException() throws
Exception {
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 void test_RegionThrowsClasscastException() throws
Exception {
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 e8bd857d39..6835b85d0c 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.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.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 void setUp() throws Exception {
@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 void processValidKeyRemovesTheEntryAndReturnSuccess()
throws Exception {
@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 void
processReturnsUnsucessfulResponseForInvalidRegion() throws Exception
@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 void processReturnsSuccessWhenKeyIsNotFound() throws
Exception {
@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 void
processReturnsErrorWhenUnableToDecodeRequest() throws Exception {
}
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 944b0388da..33e0731c84 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.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.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 void testSimpleJSONEncode() throws Exception {
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 @@ private PdxInstance createPDXInstanceForComplexJSONString()
{
@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 c421bafda4..0000000000
---
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 b9671b88ef..b0b76e49e3 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.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 c1a0743319..77e9bf303a 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.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));
}
}
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Improve JSON encoding for new protocol
> --------------------------------------
>
> Key: GEODE-4080
> URL: https://issues.apache.org/jira/browse/GEODE-4080
> Project: Geode
> Issue Type: Improvement
> Components: client/server
> Reporter: Galen O'Sullivan
>
> One of the encoding types in the new protobuf protocol is called
> {{CustomEncodedValue}}. However, users aren't really free to encode their own
> types. Also, packing JSON into a byte array is going to be harder for users
> than just sending ti as a string. Let's make the JSON type a string and put
> the custom value type in later when we actually have support for custom
> encoding.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)