This is an automated email from the ASF dual-hosted git repository.
upthewaterspout pushed a commit to branch feature/transcoding_experiments
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to
refs/heads/feature/transcoding_experiments by this push:
new f5f3f6b Adding a ValueSerializer that sends Pdx serialized data to
the client
f5f3f6b is described below
commit f5f3f6b9ab4ec2b3fb674db76e3e11eb2d0795b1
Author: Dan Smith <[email protected]>
AuthorDate: Thu Apr 19 12:57:15 2018 -0700
Adding a ValueSerializer that sends Pdx serialized data to the client
---
.../serialization/PdxPassThroughSerializer.java | 42 ++++++++++++
...he.geode.protocol.serialization.ValueSerializer | 3 +-
.../PdxPassThroughSerializerTest.java | 75 ++++++++++++++++++++++
3 files changed, 119 insertions(+), 1 deletion(-)
diff --git
a/geode-protobuf/src/main/java/org/apache/geode/protocol/serialization/PdxPassThroughSerializer.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/serialization/PdxPassThroughSerializer.java
new file mode 100644
index 0000000..4e53658
--- /dev/null
+++
b/geode-protobuf/src/main/java/org/apache/geode/protocol/serialization/PdxPassThroughSerializer.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+package org.apache.geode.protocol.serialization;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+
+import com.google.protobuf.ByteString;
+import com.google.protobuf.UnsafeByteOperations;
+
+import org.apache.geode.DataSerializer;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.pdx.internal.ConvertableToBytes;
+
+public class PdxPassThroughSerializer implements ValueSerializer {
+ @Override
+ public ByteString serialize(Object object) throws IOException {
+ return UnsafeByteOperations.unsafeWrap(((ConvertableToBytes)
object).toBytes());
+ }
+
+ @Override
+ public Object deserialize(ByteString bytes) throws IOException,
ClassNotFoundException {
+ return DataSerializer.readObject(new DataInputStream(bytes.newInput()));
+ }
+
+ @Override
+ public void init(Cache cache) {
+
+ }
+}
diff --git
a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.serialization.ValueSerializer
b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.serialization.ValueSerializer
index 718b795..5d487dd 100644
---
a/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.serialization.ValueSerializer
+++
b/geode-protobuf/src/main/resources/META-INF/services/org.apache.geode.protocol.serialization.ValueSerializer
@@ -1,2 +1,3 @@
org.apache.geode.protocol.serialization.ProtobufStructSerializer
-org.apache.geode.protocol.serialization.CompressingProtobufStructSerializer
\ No newline at end of file
+org.apache.geode.protocol.serialization.CompressingProtobufStructSerializer
+org.apache.geode.protocol.serialization.PdxPassThroughSerializer
\ No newline at end of file
diff --git
a/geode-protobuf/src/test/java/org/apache/geode/protocol/serialization/PdxPassThroughSerializerTest.java
b/geode-protobuf/src/test/java/org/apache/geode/protocol/serialization/PdxPassThroughSerializerTest.java
new file mode 100644
index 0000000..101dd94
--- /dev/null
+++
b/geode-protobuf/src/test/java/org/apache/geode/protocol/serialization/PdxPassThroughSerializerTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+package org.apache.geode.protocol.serialization;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import com.google.protobuf.ByteString;
+import com.pholser.junit.quickcheck.From;
+import com.pholser.junit.quickcheck.Property;
+import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.distributed.ConfigurationProperties;
+import org.apache.geode.pdx.PdxInstance;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+@RunWith(JUnitQuickcheck.class)
+@Category(IntegrationTest.class)
+public class PdxPassThroughSerializerTest {
+
+ private PdxPassThroughSerializer serializer;
+ private static Cache cache;
+
+ @BeforeClass
+ public static void createCache() {
+ cache = new CacheFactory().set(ConfigurationProperties.LOG_LEVEL, "error")
+ .setPdxReadSerialized(true).create();
+ }
+
+ @Before
+ public void createSerializer() {
+ serializer = new PdxPassThroughSerializer();
+ serializer.init(cache);
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ cache.close();
+ }
+
+
+ @Property(trials = 10)
+ public void testSymmetry(
+ @PdxInstanceGenerator.ClassName("someclass")
@PdxInstanceGenerator.FieldTypes({String.class,
+ int.class, long.class, byte.class, byte[].class, double.class,
PdxInstance.class,
+ ArrayList.class}) @From(PdxInstanceGenerator.class) PdxInstance
original)
+ throws IOException, ClassNotFoundException {
+ ByteString bytes = serializer.serialize(original);
+ PdxInstance actual = (PdxInstance) serializer.deserialize(bytes);
+ assertThat(original).isEqualTo(actual);
+ assertEquals(actual, original);
+ }
+}
--
To stop receiving notification emails like this one, please contact
[email protected].