giraph-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edu...@apache.org
Subject git commit: updated refs/heads/trunk to 1e802da
Date Fri, 15 Jan 2016 17:42:57 GMT
Repository: giraph
Updated Branches:
  refs/heads/trunk 0adfdfd42 -> 1e802da3a


Implementation of DirectWritableSerializerCopyTest.copy()

Summary: Needed in certain application.

Test Plan:
  mvn clean install
  Also run an actual application.

Reviewers: maja.kabiljo, sergey.edunov, ikabiljo

Reviewed By: ikabiljo

Differential Revision: https://reviews.facebook.net/D52149


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

Branch: refs/heads/trunk
Commit: 1e802da3a611eb2953c4ec3c650436278d76b9dc
Parents: 0adfdfd
Author: Sergey Edunov <edunov@fb.com>
Authored: Fri Jan 15 09:42:50 2016 -0800
Committer: Sergey Edunov <edunov@fb.com>
Committed: Fri Jan 15 09:42:50 2016 -0800

----------------------------------------------------------------------
 .../serializers/DirectWritableSerializer.java   |  6 +++
 .../kryo/DirectWritableSerializerCopyTest.java  | 55 ++++++++++++++++++++
 2 files changed, 61 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/giraph/blob/1e802da3/giraph-core/src/main/java/org/apache/giraph/writable/kryo/serializers/DirectWritableSerializer.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/main/java/org/apache/giraph/writable/kryo/serializers/DirectWritableSerializer.java
b/giraph-core/src/main/java/org/apache/giraph/writable/kryo/serializers/DirectWritableSerializer.java
index 1967e6a..e503a15 100644
--- a/giraph-core/src/main/java/org/apache/giraph/writable/kryo/serializers/DirectWritableSerializer.java
+++ b/giraph-core/src/main/java/org/apache/giraph/writable/kryo/serializers/DirectWritableSerializer.java
@@ -22,6 +22,7 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 
 import org.apache.giraph.utils.ReflectionUtils;
+import org.apache.giraph.utils.WritableUtils;
 import org.apache.hadoop.io.Writable;
 
 import com.esotericsoftware.kryo.Kryo;
@@ -66,6 +67,11 @@ public class DirectWritableSerializer<T extends Writable>
     }
   }
 
+  @Override
+  public T copy(Kryo kryo, T original) {
+    return WritableUtils.createCopy(original);
+  }
+
   /**
    * Used by {@link #read(Kryo, Input, Class)} to create the new object.
    * This can be overridden to customize object creation, eg to call a

http://git-wip-us.apache.org/repos/asf/giraph/blob/1e802da3/giraph-core/src/test/java/org/apache/giraph/writable/kryo/DirectWritableSerializerCopyTest.java
----------------------------------------------------------------------
diff --git a/giraph-core/src/test/java/org/apache/giraph/writable/kryo/DirectWritableSerializerCopyTest.java
b/giraph-core/src/test/java/org/apache/giraph/writable/kryo/DirectWritableSerializerCopyTest.java
new file mode 100644
index 0000000..233690c
--- /dev/null
+++ b/giraph-core/src/test/java/org/apache/giraph/writable/kryo/DirectWritableSerializerCopyTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.giraph.writable.kryo;
+
+import com.esotericsoftware.kryo.Kryo;
+import org.apache.giraph.types.ops.collections.BasicArrayList.BasicDoubleArrayList;
+import org.junit.Assert;
+import org.apache.giraph.writable.kryo.serializers.DirectWritableSerializer;
+import org.apache.hadoop.io.DoubleWritable;
+import org.junit.Test;
+
+public class DirectWritableSerializerCopyTest {
+  @Test
+  public void test1() {
+    DoubleWritable value = new DoubleWritable(5.9999);
+    DirectWritableSerializer<DoubleWritable> serializer = new DirectWritableSerializer<>();
+    Kryo kryo = new Kryo();
+    DoubleWritable copy = serializer.copy(kryo, value);
+    Assert.assertEquals(value.get(), copy.get(), 0);
+  }
+
+  @Test
+  public void test2() {
+    BasicDoubleArrayList list = new BasicDoubleArrayList();
+    list.add(new DoubleWritable(0.11111111));
+    list.add(new DoubleWritable(1000.9));
+    list.add(new DoubleWritable(99999999.99999999));
+    DirectWritableSerializer<BasicDoubleArrayList> serializer =
+      new DirectWritableSerializer<>();
+    Kryo kryo = new Kryo();
+    BasicDoubleArrayList copy = serializer.copy(kryo, list);
+    DoubleWritable reusable = new DoubleWritable();
+    copy.getInto(0, reusable);
+    Assert.assertEquals(0.11111111, reusable.get(), 0);
+    copy.getInto(1, reusable);
+    Assert.assertEquals(1000.9, reusable.get(), 0);
+    copy.getInto(2, reusable);
+    Assert.assertEquals(99999999.99999999, reusable.get(), 0);
+  }
+}


Mime
View raw message