Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E1E72200C49 for ; Sat, 25 Feb 2017 04:37:17 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id E0A6A160B69; Sat, 25 Feb 2017 03:37:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0CEDD160B79 for ; Sat, 25 Feb 2017 04:37:16 +0100 (CET) Received: (qmail 44593 invoked by uid 500); 25 Feb 2017 03:37:16 -0000 Mailing-List: contact commits-help@beam.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@beam.apache.org Delivered-To: mailing list commits@beam.apache.org Received: (qmail 44573 invoked by uid 99); 25 Feb 2017 03:37:15 -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; Sat, 25 Feb 2017 03:37:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C722DDFD9E; Sat, 25 Feb 2017 03:37:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: kenn@apache.org To: commits@beam.apache.org Date: Sat, 25 Feb 2017 03:37:15 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] beam git commit: [BEAM-1554] Add verification of Coder structural equality after enc/dec archived-at: Sat, 25 Feb 2017 03:37:18 -0000 Repository: beam Updated Branches: refs/heads/master 415546eda -> 437ba2505 [BEAM-1554] Add verification of Coder structural equality after enc/dec This also improves the class documentation. Project: http://git-wip-us.apache.org/repos/asf/beam/repo Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/2736c4ae Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/2736c4ae Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/2736c4ae Branch: refs/heads/master Commit: 2736c4ae901ad428f8e05fb7a80ad72f0318735e Parents: 415546e Author: Ismaël Mejía Authored: Fri Feb 24 16:46:17 2017 +0100 Committer: Ismaël Mejía Committed: Sat Feb 25 04:16:28 2017 +0100 ---------------------------------------------------------------------- .../beam/sdk/testing/CoderProperties.java | 66 ++++++++++++++++++-- 1 file changed, 61 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/beam/blob/2736c4ae/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/CoderProperties.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/CoderProperties.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/CoderProperties.java index 910b939..8065505 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/CoderProperties.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/CoderProperties.java @@ -87,7 +87,6 @@ public class CoderProperties { public static void coderDeterministicInContext( Coder coder, Coder.Context context, T value1, T value2) throws Exception { - try { coder.verifyDeterministic(); } catch (NonDeterministicException e) { @@ -189,22 +188,34 @@ public class CoderProperties { } } + /** + * Verifies that the given {@code Coder} can be correctly serialized and + * deserialized. + */ public static void coderSerializable(Coder coder) { SerializableUtils.ensureSerializable(coder); } + /** + * Verifies that for the given {@code Coder} and values of + * type {@code T}, the values are equal if and only if the + * encoded bytes are equal. + */ public static void coderConsistentWithEquals( Coder coder, T value1, T value2) throws Exception { - for (Coder.Context context : ALL_CONTEXTS) { CoderProperties.coderConsistentWithEqualsInContext(coder, context, value1, value2); } } + /** + * Verifies that for the given {@code Coder}, {@code Coder.Context}, and + * values of type {@code T}, the values are equal if and only if the + * encoded bytes are equal, in any {@code Coder.Context}. + */ public static void coderConsistentWithEqualsInContext( Coder coder, Coder.Context context, T value1, T value2) throws Exception { - assertEquals( value1.equals(value2), Arrays.equals( @@ -212,12 +223,20 @@ public class CoderProperties { encode(coder, context, value2))); } + /** + * Verifies if a {@code Coder}'s encodingId is equal to a given + * encodingId. + */ public static void coderHasEncodingId(Coder coder, String encodingId) throws Exception { assertThat(coder.getEncodingId(), equalTo(encodingId)); assertThat(Structs.getString(coder.asCloudObject(), PropertyNames.ENCODING_ID, ""), equalTo(encodingId)); } + /** + * Verifies if a {@code Coder} is allowed to encode using the given + * encodingId. + */ public static void coderAllowsEncoding(Coder coder, String encodingId) throws Exception { assertThat(coder.getAllowedEncodings(), hasItem(encodingId)); assertThat( @@ -230,19 +249,27 @@ public class CoderProperties { hasItem(encodingId)); } + /** + * Verifies that for the given {@code Coder} and values of + * type {@code T}, the structural values are equal if and only if the + * encoded bytes are equal. + */ public static void structuralValueConsistentWithEquals( Coder coder, T value1, T value2) throws Exception { - for (Coder.Context context : ALL_CONTEXTS) { CoderProperties.structuralValueConsistentWithEqualsInContext( coder, context, value1, value2); } } + /** + * Verifies that for the given {@code Coder}, {@code Coder.Context}, and + * values of type {@code T}, the structural values are equal if and only if the + * encoded bytes are equal, in any {@code Coder.Context}. + */ public static void structuralValueConsistentWithEqualsInContext( Coder coder, Coder.Context context, T value1, T value2) throws Exception { - assertEquals( coder.structuralValue(value1).equals(coder.structuralValue(value2)), Arrays.equals( @@ -250,6 +277,35 @@ public class CoderProperties { encode(coder, context, value2))); } + /** + * Verifies that for the given {@code Coder} and value of type {@code T}, + * the structural value is equal to the structural value yield by encoding + * and decoding the original value. + * + *

This is useful to test the correct implementation of a Coder structural + * equality with values that don't implement the equals contract. + */ + public static void structuralValueDecodeEncodeEqual( + Coder coder, T value) + throws Exception { + for (Coder.Context context : ALL_CONTEXTS) { + CoderProperties.structuralValueDecodeEncodeEqualInContext( + coder, context, value); + } + } + + /** + * Verifies that for the given {@code Coder}, {@code Coder.Context}, + * and value of type {@code T}, the structural value is equal to the + * structural value yield by encoding and decoding the original value, + * in any {@code Coder.Context}. + */ + public static void structuralValueDecodeEncodeEqualInContext( + Coder coder, Coder.Context context, T value) throws Exception { + assertEquals( + coder.structuralValue(value), + coder.structuralValue(decodeEncode(coder, context, value))); + } private static final String DECODING_WIRE_FORMAT_MESSAGE = "Decoded value from known wire format does not match expected value."