geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject geode git commit: GEODE-2580: JSON value encoding completed
Date Wed, 24 May 2017 18:09:28 GMT
Repository: geode
Updated Branches:
  refs/heads/feature/GEODE-2580 6a5e4be30 -> e3a752dcf


GEODE-2580: JSON value encoding completed

PdxToJSON.java removed pretty print formatter


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

Branch: refs/heads/feature/GEODE-2580
Commit: e3a752dcfbead28e8712a5acd62439514f2eafb2
Parents: 6a5e4be
Author: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Authored: Wed May 24 11:09:22 2017 -0700
Committer: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Committed: Wed May 24 11:09:22 2017 -0700

----------------------------------------------------------------------
 .../client/NewClientProtocolTestClient.java     | 41 --------------------
 .../client/ProtobufProtocolMessageHandler.kt    |  4 +-
 .../geode/protocol/client/MessageUtils.kt       | 18 +++++++++
 .../client/ProtobufProtocolIntegrationTest.kt   | 26 ++++++++-----
 .../geode/pdx/internal/json/PdxToJSON.java      |  2 +-
 5 files changed, 37 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/e3a752dc/geode-client-protobuf/src/main/java/org/apache/geode/protocol/client/NewClientProtocolTestClient.java
----------------------------------------------------------------------
diff --git a/geode-client-protobuf/src/main/java/org/apache/geode/protocol/client/NewClientProtocolTestClient.java
b/geode-client-protobuf/src/main/java/org/apache/geode/protocol/client/NewClientProtocolTestClient.java
index 0b29aa3..e6e9a42 100644
--- a/geode-client-protobuf/src/main/java/org/apache/geode/protocol/client/NewClientProtocolTestClient.java
+++ b/geode-client-protobuf/src/main/java/org/apache/geode/protocol/client/NewClientProtocolTestClient.java
@@ -15,23 +15,15 @@
 
 package org.apache.geode.protocol.client;
 
-import com.google.protobuf.Any;
-import com.google.protobuf.ByteString;
 import org.apache.geode.internal.cache.tier.sockets.AcceptorImpl;
-import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.ClientProtocol;
 import org.apache.geode.protocol.protobuf.ClientProtocol.Message;
-import org.apache.geode.protocol.protobuf.RegionAPI;
 
-import java.io.BufferedWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.net.InetAddress;
 import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
 import java.nio.channels.SocketChannel;
-import java.util.Random;
 
 
 public class NewClientProtocolTestClient implements AutoCloseable {
@@ -67,37 +59,4 @@ public class NewClientProtocolTestClient implements AutoCloseable {
     System.out.println("response = " + response.toString());
   }
 
-  private Message generateMessage() {
-    Random random = new Random();
-    ClientProtocol.MessageHeader.Builder messageHeader =
-        ClientProtocol.MessageHeader.newBuilder().setCorrelationId(random.nextInt());
-    // .setSize() //we don't need to set the size because Protobuf will handle the message
frame
-
-    BasicTypes.EncodedValue.Builder key = BasicTypes.EncodedValue.newBuilder()
-        .setValue(ByteString.copyFrom(createByteArrayOfSize(64)));
-
-    BasicTypes.EncodedValue.Builder value = BasicTypes.EncodedValue.newBuilder()
-        .setValue(ByteString.copyFrom(createByteArrayOfSize(512)));
-
-    RegionAPI.PutRequest.Builder putRequestBuilder =
-        RegionAPI.PutRequest.newBuilder().setRegionName("TestRegion")
-            .setEntry(BasicTypes.Entry.newBuilder().setKey(key).setValue(value));
-
-    ClientProtocol.Request.Builder request =
-        ClientProtocol.Request.newBuilder().setPutRequest(putRequestBuilder);
-
-    Message.Builder message =
-        Message.newBuilder().setMessageHeader(messageHeader).setRequest(request);
-
-    return message.build();
-  }
-
-  private static byte[] createByteArrayOfSize(int msgSize) {
-    byte[] array = new byte[msgSize];
-    for (int i = 0; i < msgSize; i++) {
-      array[i] = 'a';
-    }
-    return array;
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/e3a752dc/geode-client-protobuf/src/main/java/org/apache/geode/protocol/client/ProtobufProtocolMessageHandler.kt
----------------------------------------------------------------------
diff --git a/geode-client-protobuf/src/main/java/org/apache/geode/protocol/client/ProtobufProtocolMessageHandler.kt
b/geode-client-protobuf/src/main/java/org/apache/geode/protocol/client/ProtobufProtocolMessageHandler.kt
index ec66d44..14ea2de 100644
--- a/geode-client-protobuf/src/main/java/org/apache/geode/protocol/client/ProtobufProtocolMessageHandler.kt
+++ b/geode-client-protobuf/src/main/java/org/apache/geode/protocol/client/ProtobufProtocolMessageHandler.kt
@@ -105,8 +105,8 @@ class ProtobufProtocolMessageHandler : ClientProtocolMessageHandler {
         }
     }
 
-    private fun getEncodingTypeForObject(`object`: Any): BasicTypes.EncodingType {
-        return EncodingTypeThingy.getEncodingTypeForObjectKT(`object`)
+    private fun getEncodingTypeForObject(obj: Any): BasicTypes.EncodingType {
+        return EncodingTypeThingy.getEncodingTypeForObjectKT(obj)
     }
 
     private fun makeGetResponseMessageWithValue(objectToReturn: Any): Message {

http://git-wip-us.apache.org/repos/asf/geode/blob/e3a752dc/geode-client-protobuf/src/test/java/org/apache/geode/protocol/client/MessageUtils.kt
----------------------------------------------------------------------
diff --git a/geode-client-protobuf/src/test/java/org/apache/geode/protocol/client/MessageUtils.kt
b/geode-client-protobuf/src/test/java/org/apache/geode/protocol/client/MessageUtils.kt
index 285c9b4..f74ec99 100644
--- a/geode-client-protobuf/src/test/java/org/apache/geode/protocol/client/MessageUtils.kt
+++ b/geode-client-protobuf/src/test/java/org/apache/geode/protocol/client/MessageUtils.kt
@@ -62,6 +62,24 @@ object MessageUtils {
         return message.build()
     }
 
+    fun makePutMessageForJSON(region: String, key: Any, value: String, keyEncoding: BasicTypes.EncodingType
= EncodingTypeThingy.getEncodingTypeForObjectKT(key)): ClientProtocol.Message {
+        val random = Random()
+        val messageHeader = ClientProtocol.MessageHeader.newBuilder().setCorrelationId(random.nextInt())
+
+        val keyBuilder = getEncodedValueBuilder(key, keyEncoding)
+        val valueBuilder = getEncodedValueBuilder(value, BasicTypes.EncodingType.STRING)
+        valueBuilder.encodingType = BasicTypes.EncodingType.JSON
+
+
+        val putRequestBuilder = RegionAPI.PutRequest.newBuilder().setRegionName(region)
+                .setEntry(BasicTypes.Entry.newBuilder().setKey(keyBuilder).setValue(valueBuilder))
+
+        val request = ClientProtocol.Request.newBuilder().setPutRequest(putRequestBuilder)
+        val message = ClientProtocol.Message.newBuilder().setMessageHeader(messageHeader).setRequest(request)
+
+        return message.build()
+    }
+
     private fun getEncodedValueBuilder(value: Any, encodingType: BasicTypes.EncodingType):
BasicTypes.EncodedValue.Builder {
         return BasicTypes.EncodedValue.newBuilder().setEncodingType(encodingType)
                 .setValue(ByteString.copyFrom(EncodingTypeThingy.serializerFromProtoEnum(encodingType).serialize(value)))

http://git-wip-us.apache.org/repos/asf/geode/blob/e3a752dc/geode-client-protobuf/src/test/java/org/apache/geode/protocol/client/ProtobufProtocolIntegrationTest.kt
----------------------------------------------------------------------
diff --git a/geode-client-protobuf/src/test/java/org/apache/geode/protocol/client/ProtobufProtocolIntegrationTest.kt
b/geode-client-protobuf/src/test/java/org/apache/geode/protocol/client/ProtobufProtocolIntegrationTest.kt
index 2130c88..c7759f2 100644
--- a/geode-client-protobuf/src/test/java/org/apache/geode/protocol/client/ProtobufProtocolIntegrationTest.kt
+++ b/geode-client-protobuf/src/test/java/org/apache/geode/protocol/client/ProtobufProtocolIntegrationTest.kt
@@ -32,7 +32,6 @@ import org.junit.Test
 import org.junit.experimental.categories.Category
 import org.junit.runner.RunWith
 import java.io.IOException
-import java.io.Serializable
 import java.util.*
 
 @Category(IntegrationTest::class)
@@ -108,7 +107,7 @@ class ProtobufProtocolIntegrationTest {
     }
 
     @Test
-    fun objectSerializationIntegrationTest() {
+    fun testPrimitiveSerializationIntegration() {
         val inputs = listOf("Foobar", 1000.toLong(), 22, 231.toShort(), (-107).toByte(),
byteArrayOf(1, 2, 3, 54, 99))
         for (key in inputs) {
             for (value in inputs) {
@@ -117,14 +116,20 @@ class ProtobufProtocolIntegrationTest {
                 }
             }
         }
-//        val jsonString = "{ \"_id\": \"5924ba3f3918de8404fc1321\", \"index\": 0, \"guid\":
\"bd27d3fa-8870-4f0d-ab4d-73adf7cbe58b\", \"isActive\": false, \"balance\": \"$1,934.31\",
\"picture\": \"http://placehold.it/32x32\", \"age\": 39, \"eyeColor\": \"blue\", \"name\":
\"Holt Dickson\", \"gender\": \"male\", \"company\": \"INQUALA\", \"email\": \"holtdickson@inquala.com\",
\"phone\": \"+1 (886) 450-2949\", \"address\": \"933 Diamond Street, Hinsdale, Palau, 2038\",
\"about\": \"Cupidatat excepteur labore cillum ea reprehenderit aliquip magna duis aliquip
Lorem labore. Aliquip elit ullamco aliqua fugiat aute id irure enim Lorem eu qui nisi aliquip.
Et do sit cupidatat sit ut consectetur ullamco aute do nostrud in. Ea voluptate in reprehenderit
sit commodo et aliquip officia id eiusmod. Quis voluptate commodo ad esse do cillum ut occaecat
non.\r\n\", \"registered\": \"2017-02-01T12:28:49 +08:00\", \"latitude\": -69.313434, \"longitude\":
134.707471, \"tags\": [ \"officia\", \"qui
 \", \"ullamco\", \"nostrud\", \"ipsum\", \"dolor\", \"officia\" ], \"friends\": [ { \"id\":
0, \"name\": \"Vivian Beach\" }, { \"id\": 1, \"name\": \"Crystal Mills\" }, { \"id\": 2,
\"name\": \"Mosley Frank\" } ], \"greeting\": \"Hello, Holt Dickson! You have 2 unread messages.\",
\"favoriteFruit\": \"apple\" }"
-//
-//        testMessagePutAndGet(testKey,jsonString,BasicTypes.EncodingType.STRING)
-//        val putMessage = MessageUtils.makePutMessageFor(region = testRegion, key = testKey,
value = jsonString, valueEncoding = BasicTypes.EncodingType.STRING)
     }
 
-    private fun testMessagePutAndGet(key: Serializable, value: Serializable, valueEncoding:
BasicTypes.EncodingType) {
-        val putMessage = MessageUtils.makePutMessageFor(region = testRegion, key = key, value
= value, valueEncoding = valueEncoding)
+    @Test
+    fun testJsonValueSerializationIntegration() {
+        val jsonString = "{\"_id\":\"5924ba3f3918de8404fc1321\",\"index\":0,\"guid\":\"bd27d3fa-8870-4f0d-ab4d-73adf7cbe58b\",\"isActive\":false,\"balance\":\"$1,934.31\",\"picture\":\"http://placehold.it/32x32\",\"age\":39,\"eyeColor\":\"blue\",\"name\":\"Holt
Dickson\",\"gender\":\"male\",\"company\":\"INQUALA\",\"email\":\"holtdickson@inquala.com\",\"phone\":\"+1
(886) 450-2949\",\"address\":\"933 Diamond Street, Hinsdale, Palau, 2038\",\"about\":\"Cupidatat
excepteur labore cillum ea reprehenderit aliquip magna duis aliquip Lorem labore. Aliquip
elit ullamco aliqua fugiat aute id irure enim Lorem eu qui nisi aliquip. Et do sit cupidatat
sit ut consectetur ullamco aute do nostrud in. Ea voluptate in reprehenderit sit commodo et
aliquip officia id eiusmod. Quis voluptate commodo ad esse do cillum ut occaecat non.\",\"registered\":\"2017-02-01T12:28:49
+08:00\",\"latitude\":-69.313434,\"longitude\":134.707471,\"tags\":[\"officia\",\"qui\",\"ullamco\",\"nostrud\",\"ipsum\",\"dolor\"
 ,\"officia\"],\"friends\":[{\"id\":0,\"name\":\"Vivian Beach\"},{\"id\":1,\"name\":\"Crystal
Mills\"},{\"id\":2,\"name\":\"Mosley Frank\"}],\"greeting\":\"Hello, Holt Dickson! You have
2 unread messages.\",\"favoriteFruit\":\"apple\"}"
+
+        testMessagePutAndGet(key = testKey, value = jsonString, valueEncoding = BasicTypes.EncodingType.JSON)
+    }
+
+    private fun testMessagePutAndGet(key: Any, value: Any, valueEncoding: BasicTypes.EncodingType)
{
+        val putMessage = when (valueEncoding) {
+            BasicTypes.EncodingType.JSON -> MessageUtils.makePutMessageForJSON(region
= testRegion, key = key, value = value as String)
+            else -> MessageUtils.makePutMessageFor(region = testRegion, key = key, value
= value, valueEncoding = valueEncoding)
+        }
         val responseMessage = testClient.blockingSendMessage(putMessage)
         assertTrue(responseMessage.response.putResponse.success)
 
@@ -137,10 +142,11 @@ class ProtobufProtocolIntegrationTest {
         val serializer = EncodingTypeThingy.serializerFromProtoEnum(messageEncodingType)
         val messageValue = getResponse.response.getResponse.result.value.toByteArray()
 
-        val deserializeValue = serializer.deserializer.deserialize(messageValue)
+        val deserializeValue = serializer.deserialize(messageValue)
         when (messageEncodingType) {
             BasicTypes.EncodingType.BINARY -> assertArrayEquals(value as ByteArray, deserializeValue
as ByteArray)
-            else -> assertEquals(value, serializer.deserializer.deserialize(messageValue))
+            BasicTypes.EncodingType.JSON -> assertEquals(value, EncodingTypeThingy.serializerFromProtoEnum(BasicTypes.EncodingType.STRING).deserializer.deserialize(messageValue))
+            else -> assertEquals(value, deserializeValue)
         }
     }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/e3a752dc/geode-core/src/main/java/org/apache/geode/pdx/internal/json/PdxToJSON.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/pdx/internal/json/PdxToJSON.java b/geode-core/src/main/java/org/apache/geode/pdx/internal/json/PdxToJSON.java
index 428fa40..52a573d 100644
--- a/geode-core/src/main/java/org/apache/geode/pdx/internal/json/PdxToJSON.java
+++ b/geode-core/src/main/java/org/apache/geode/pdx/internal/json/PdxToJSON.java
@@ -82,7 +82,7 @@ public class PdxToJSON {
   private void enableDisableJSONGeneratorFeature(JsonGenerator jg) {
     jg.enable(Feature.ESCAPE_NON_ASCII);
     jg.disable(Feature.AUTO_CLOSE_TARGET);
-    jg.setPrettyPrinter(new DefaultPrettyPrinter());
+//    jg.setPrettyPrinter(new DefaultPrettyPrinter());
     if (PDXTOJJSON_UNQUOTEFIELDNAMES)
       jg.disable(Feature.QUOTE_FIELD_NAMES);
   }


Mime
View raw message