Return-Path: X-Original-To: apmail-crunch-commits-archive@www.apache.org Delivered-To: apmail-crunch-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 97B1111A66 for ; Thu, 12 Jun 2014 03:41:44 +0000 (UTC) Received: (qmail 92323 invoked by uid 500); 12 Jun 2014 03:41:44 -0000 Delivered-To: apmail-crunch-commits-archive@crunch.apache.org Received: (qmail 92277 invoked by uid 500); 12 Jun 2014 03:41:43 -0000 Mailing-List: contact commits-help@crunch.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@crunch.apache.org Delivered-To: mailing list commits@crunch.apache.org Received: (qmail 92261 invoked by uid 99); 12 Jun 2014 03:41:43 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jun 2014 03:41:43 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id AF31947D70; Thu, 12 Jun 2014 03:41:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jwills@apache.org To: commits@crunch.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: CRUNCH-419 Writables.registerComparable does not actually register the WritableComparable Date: Thu, 12 Jun 2014 03:41:42 +0000 (UTC) Repository: crunch Updated Branches: refs/heads/master 772f7f2b2 -> 96ef2d679 CRUNCH-419 Writables.registerComparable does not actually register the WritableComparable Signed-off-by: Josh Wills Project: http://git-wip-us.apache.org/repos/asf/crunch/repo Commit: http://git-wip-us.apache.org/repos/asf/crunch/commit/96ef2d67 Tree: http://git-wip-us.apache.org/repos/asf/crunch/tree/96ef2d67 Diff: http://git-wip-us.apache.org/repos/asf/crunch/diff/96ef2d67 Branch: refs/heads/master Commit: 96ef2d679c9a7bf6c2cb80190e0646f94f558482 Parents: 772f7f2 Author: Tom De Leu Authored: Wed Jun 11 22:09:08 2014 +0200 Committer: Josh Wills Committed: Wed Jun 11 20:04:10 2014 -0700 ---------------------------------------------------------------------- .../apache/crunch/types/writable/Writables.java | 1 + .../crunch/types/writable/WritablesTest.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/crunch/blob/96ef2d67/crunch-core/src/main/java/org/apache/crunch/types/writable/Writables.java ---------------------------------------------------------------------- diff --git a/crunch-core/src/main/java/org/apache/crunch/types/writable/Writables.java b/crunch-core/src/main/java/org/apache/crunch/types/writable/Writables.java index f571f2f..be2cb1a 100644 --- a/crunch-core/src/main/java/org/apache/crunch/types/writable/Writables.java +++ b/crunch-core/src/main/java/org/apache/crunch/types/writable/Writables.java @@ -122,6 +122,7 @@ public class Writables { if (WRITABLE_CODES.containsKey(code)) { throw new IllegalArgumentException("Already have writable class assigned to code = " + code); } + WRITABLE_CODES.put(code, clazz); } private static final String WRITABLE_COMPARABLE_CODES = "crunch.writable.comparable.codes"; http://git-wip-us.apache.org/repos/asf/crunch/blob/96ef2d67/crunch-core/src/test/java/org/apache/crunch/types/writable/WritablesTest.java ---------------------------------------------------------------------- diff --git a/crunch-core/src/test/java/org/apache/crunch/types/writable/WritablesTest.java b/crunch-core/src/test/java/org/apache/crunch/types/writable/WritablesTest.java index 70099f2..2281473 100644 --- a/crunch-core/src/test/java/org/apache/crunch/types/writable/WritablesTest.java +++ b/crunch-core/src/test/java/org/apache/crunch/types/writable/WritablesTest.java @@ -42,7 +42,7 @@ import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.NullWritable; import org.apache.hadoop.io.Text; -import org.apache.hadoop.io.Writable; +import org.apache.hadoop.io.WritableComparable; import org.apache.hadoop.io.WritableUtils; import org.junit.Test; @@ -172,7 +172,7 @@ public class WritablesTest { testInputOutputFn(wt, j, w); } - protected static class TestWritable implements Writable { + protected static class TestWritable implements WritableComparable { String left; int right; @@ -207,6 +207,13 @@ public class WritablesTest { return true; } + @Override + public int compareTo(TestWritable o) { + int cmp = left.compareTo(o.left); + if (cmp != 0) + return cmp; + return Integer.valueOf(right).compareTo(Integer.valueOf(o.right)); + } } @Test @@ -236,6 +243,12 @@ public class WritablesTest { assertSame(Writables.records(TestWritable.class), wt); } + @Test + public void testRegisterComparable() throws Exception { + Writables.registerComparable(TestWritable.class); + assertNotNull(Writables.WRITABLE_CODES.inverse().get(TestWritable.class)); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) protected static void testInputOutputFn(PType ptype, Object java, Object writable) { ptype.getInputMapFn().initialize();