Return-Path: X-Original-To: apmail-giraph-commits-archive@www.apache.org Delivered-To: apmail-giraph-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EB16E1843B for ; Fri, 15 Jan 2016 17:42:57 +0000 (UTC) Received: (qmail 17734 invoked by uid 500); 15 Jan 2016 17:42:57 -0000 Delivered-To: apmail-giraph-commits-archive@giraph.apache.org Received: (qmail 17657 invoked by uid 500); 15 Jan 2016 17:42:57 -0000 Mailing-List: contact commits-help@giraph.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@giraph.apache.org Delivered-To: mailing list commits@giraph.apache.org Received: (qmail 17648 invoked by uid 99); 15 Jan 2016 17:42:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Jan 2016 17:42:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 783D3DFBEE; Fri, 15 Jan 2016 17:42:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: edunov@apache.org To: commits@giraph.apache.org Message-Id: <086e2cee6636402297452222193fcedf@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/trunk to 1e802da Date: Fri, 15 Jan 2016 17:42:57 +0000 (UTC) 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 Authored: Fri Jan 15 09:42:50 2016 -0800 Committer: Sergey Edunov 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 } } + @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 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 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); + } +}