You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apex.apache.org by cs...@apache.org on 2016/04/25 04:56:55 UTC
[1/2] incubator-apex-malhar git commit: APEXMALHAR-2058 #resolve
#comment moved Serde to serde package and added simple byte array Serde
implementation.
Repository: incubator-apex-malhar
Updated Branches:
refs/heads/master 4ef0700ad -> 4e0217b43
APEXMALHAR-2058 #resolve #comment moved Serde to serde package and added simple byte array Serde implementation.
Project: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/commit/4c3e00e9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/tree/4c3e00e9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/diff/4c3e00e9
Branch: refs/heads/master
Commit: 4c3e00e9a647720dbd3882fdea08ca9f90b84c20
Parents: 4ef0700
Author: Timothy Farkas <ti...@datatorrent.com>
Authored: Sun Apr 24 18:45:27 2016 -0700
Committer: Timothy Farkas <ti...@datatorrent.com>
Committed: Sun Apr 24 19:36:08 2016 -0700
----------------------------------------------------------------------
.../spillable/SpillableComplexComponent.java | 2 +-
.../org/apache/apex/malhar/lib/utils/Serde.java | 61 -----------------
.../lib/utils/serde/PassThruByteArraySerde.java | 47 +++++++++++++
.../apex/malhar/lib/utils/serde/Serde.java | 61 +++++++++++++++++
.../malhar/lib/utils/serde/package-info.java | 20 ++++++
.../utils/serde/PassThruByteArraySerdeTest.java | 72 ++++++++++++++++++++
6 files changed, 201 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/4c3e00e9/library/src/main/java/org/apache/apex/malhar/lib/spillable/SpillableComplexComponent.java
----------------------------------------------------------------------
diff --git a/library/src/main/java/org/apache/apex/malhar/lib/spillable/SpillableComplexComponent.java b/library/src/main/java/org/apache/apex/malhar/lib/spillable/SpillableComplexComponent.java
index 75769a1..c5acbc5 100644
--- a/library/src/main/java/org/apache/apex/malhar/lib/spillable/SpillableComplexComponent.java
+++ b/library/src/main/java/org/apache/apex/malhar/lib/spillable/SpillableComplexComponent.java
@@ -19,7 +19,7 @@
package org.apache.apex.malhar.lib.spillable;
import org.apache.apex.malhar.lib.spillable.Spillable.SpillableComponent;
-import org.apache.apex.malhar.lib.utils.Serde;
+import org.apache.apex.malhar.lib.utils.serde.Serde;
import com.datatorrent.api.Component;
import com.datatorrent.api.Context.OperatorContext;
http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/4c3e00e9/library/src/main/java/org/apache/apex/malhar/lib/utils/Serde.java
----------------------------------------------------------------------
diff --git a/library/src/main/java/org/apache/apex/malhar/lib/utils/Serde.java b/library/src/main/java/org/apache/apex/malhar/lib/utils/Serde.java
deleted file mode 100644
index f271cfc..0000000
--- a/library/src/main/java/org/apache/apex/malhar/lib/utils/Serde.java
+++ /dev/null
@@ -1,61 +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.apex.malhar.lib.utils;
-
-import org.apache.commons.lang3.mutable.MutableInt;
-
-/**
- * This is an interface for a Serializer/Deserializer class.
- * @param <OBJ> The type of the object to Serialize and Deserialize.
- * @param <SER> The type to Serialize an Object to.
- */
-public interface Serde<OBJ, SER>
-{
- /**
- * Serialized the given object.
- * @param object The object to serialize.
- * @return The serialized representation of the object.
- */
- SER serialize(OBJ object);
-
- /**
- * Deserializes the given serialized representation of an object.
- * @param object The serialized representation of an object.
- * @param offset An offset in the serialized representation of the object. After the
- * deserialize method completes the offset is updated, so that the offset points to
- * the remaining unprocessed portion of the serialized object. For example:<br/>
- * {@code
- * Object obj;
- * MutableInt mi;
- * someObj1 = deserialize(obj, mi);
- * someObj2 = deserialize(obj, mi);
- * }
- *
- * @return The deserialized object.
- */
- OBJ deserialize(SER object, MutableInt offset);
-
- /**
- * Deserializes the given serialized representation of an object.
- * @param object The serialized representation of an object.
- *
- * @return The deserialized object.
- */
- OBJ deserialize(SER object);
-}
http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/4c3e00e9/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/PassThruByteArraySerde.java
----------------------------------------------------------------------
diff --git a/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/PassThruByteArraySerde.java b/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/PassThruByteArraySerde.java
new file mode 100644
index 0000000..7d03634
--- /dev/null
+++ b/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/PassThruByteArraySerde.java
@@ -0,0 +1,47 @@
+/**
+ * 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.apex.malhar.lib.utils.serde;
+
+import org.apache.commons.lang3.mutable.MutableInt;
+
+/**
+ * This is a simple pass through {@link Serde}. When serialization is performed the input byte array is returned.
+ * Similarly when deserialization is performed the input byte array is returned.
+ */
+public class PassThruByteArraySerde implements Serde<byte[], byte[]>
+{
+ @Override
+ public byte[] serialize(byte[] object)
+ {
+ return object;
+ }
+
+ @Override
+ public byte[] deserialize(byte[] object, MutableInt offset)
+ {
+ offset.add(object.length);
+ return object;
+ }
+
+ @Override
+ public byte[] deserialize(byte[] object)
+ {
+ return object;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/4c3e00e9/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/Serde.java
----------------------------------------------------------------------
diff --git a/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/Serde.java b/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/Serde.java
new file mode 100644
index 0000000..df84c59
--- /dev/null
+++ b/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/Serde.java
@@ -0,0 +1,61 @@
+/**
+ * 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.apex.malhar.lib.utils.serde;
+
+import org.apache.commons.lang3.mutable.MutableInt;
+
+/**
+ * This is an interface for a Serializer/Deserializer class.
+ * @param <OBJ> The type of the object to Serialize and Deserialize.
+ * @param <SER> The type to Serialize an Object to.
+ */
+public interface Serde<OBJ, SER>
+{
+ /**
+ * Serialized the given object.
+ * @param object The object to serialize.
+ * @return The serialized representation of the object.
+ */
+ SER serialize(OBJ object);
+
+ /**
+ * Deserializes the given serialized representation of an object.
+ * @param object The serialized representation of an object.
+ * @param offset An offset in the serialized representation of the object. After the
+ * deserialize method completes the offset is updated, so that the offset points to
+ * the remaining unprocessed portion of the serialized object. For example:<br/>
+ * {@code
+ * Object obj;
+ * MutableInt mi;
+ * someObj1 = deserialize(obj, mi);
+ * someObj2 = deserialize(obj, mi);
+ * }
+ *
+ * @return The deserialized object.
+ */
+ OBJ deserialize(SER object, MutableInt offset);
+
+ /**
+ * Deserializes the given serialized representation of an object.
+ * @param object The serialized representation of an object.
+ *
+ * @return The deserialized object.
+ */
+ OBJ deserialize(SER object);
+}
http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/4c3e00e9/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/package-info.java
----------------------------------------------------------------------
diff --git a/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/package-info.java b/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/package-info.java
new file mode 100644
index 0000000..18ae748
--- /dev/null
+++ b/library/src/main/java/org/apache/apex/malhar/lib/utils/serde/package-info.java
@@ -0,0 +1,20 @@
+/**
+ * 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.
+ */
+@org.apache.hadoop.classification.InterfaceStability.Evolving
+package org.apache.apex.malhar.lib.utils.serde;
http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/blob/4c3e00e9/library/src/test/java/org/apache/apex/malhar/lib/utils/serde/PassThruByteArraySerdeTest.java
----------------------------------------------------------------------
diff --git a/library/src/test/java/org/apache/apex/malhar/lib/utils/serde/PassThruByteArraySerdeTest.java b/library/src/test/java/org/apache/apex/malhar/lib/utils/serde/PassThruByteArraySerdeTest.java
new file mode 100644
index 0000000..3cb5b65
--- /dev/null
+++ b/library/src/test/java/org/apache/apex/malhar/lib/utils/serde/PassThruByteArraySerdeTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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.apex.malhar.lib.utils.serde;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+import org.apache.commons.lang3.mutable.MutableInt;
+
+public class PassThruByteArraySerdeTest
+{
+ @Rule
+ public SerdeByteArrayToByteArrayTestWatcher testMeta = new SerdeByteArrayToByteArrayTestWatcher();
+
+ public static class SerdeByteArrayToByteArrayTestWatcher extends TestWatcher
+ {
+ public PassThruByteArraySerde serde;
+
+ @Override
+ protected void starting(Description description)
+ {
+ this.serde = new PassThruByteArraySerde();
+ super.starting(description);
+ }
+ }
+
+ @Test
+ public void simpleSerializeTest()
+ {
+ byte[] byteArray = new byte[]{1, 2, 3};
+ byte[] serialized = testMeta.serde.serialize(byteArray);
+
+ Assert.assertArrayEquals(byteArray, serialized);
+ }
+
+ @Test
+ public void simpleDeserializeTest()
+ {
+ byte[] byteArray = new byte[]{1, 2, 3};
+ byte[] serialized = testMeta.serde.deserialize(byteArray);
+
+ Assert.assertArrayEquals(byteArray, serialized);
+ }
+
+ @Test
+ public void simpleDeserializeOffsetTest()
+ {
+ byte[] byteArray = new byte[]{1, 2, 3};
+ byte[] serialized = testMeta.serde.deserialize(byteArray, new MutableInt(0));
+
+ Assert.assertArrayEquals(byteArray, serialized);
+ }
+}
[2/2] incubator-apex-malhar git commit: Merge branch 'APEXMALHAR-2058'
Posted by cs...@apache.org.
Merge branch 'APEXMALHAR-2058'
Project: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/commit/4e0217b4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/tree/4e0217b4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-malhar/diff/4e0217b4
Branch: refs/heads/master
Commit: 4e0217b431ffffbf4029012b220c64590d0e2f18
Parents: 4ef0700 4c3e00e
Author: Chandni Singh <cs...@apache.org>
Authored: Sun Apr 24 19:56:25 2016 -0700
Committer: Chandni Singh <cs...@apache.org>
Committed: Sun Apr 24 19:56:25 2016 -0700
----------------------------------------------------------------------
.../spillable/SpillableComplexComponent.java | 2 +-
.../org/apache/apex/malhar/lib/utils/Serde.java | 61 -----------------
.../lib/utils/serde/PassThruByteArraySerde.java | 47 +++++++++++++
.../apex/malhar/lib/utils/serde/Serde.java | 61 +++++++++++++++++
.../malhar/lib/utils/serde/package-info.java | 20 ++++++
.../utils/serde/PassThruByteArraySerdeTest.java | 72 ++++++++++++++++++++
6 files changed, 201 insertions(+), 62 deletions(-)
----------------------------------------------------------------------