Package org.apache.beam.sdk.testing
Class CoderProperties
java.lang.Object
org.apache.beam.sdk.testing.CoderProperties
Properties for use in
Coder
tests. These are implemented with junit assertions rather
than as predicates for the sake of error messages.
We serialize and deserialize the coder to make sure that any state information required by the coder is preserved. This causes tests written such that coders that lose information during serialization or change state during encoding/decoding will fail.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
AnElementByteSizeObserver
that records the observed element sizes for testing purposes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final List
<Coder.Context> All the contexts, for use in test cases. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> void
coderConsistentWithEquals
(Coder<T> coder, T value1, T value2) Verifies that for the givenCoder<T>
and values of typeT
, the values are equal if and only if the encoded bytes are equal.static <T> void
coderConsistentWithEqualsInContext
(Coder<T> coder, Coder.Context context, T value1, T value2) Verifies that for the givenCoder<T>
,Coder.Context
, and values of typeT
, the values are equal if and only if the encoded bytes are equal, in anyCoder.Context
.static <T,
CollectionT extends Collection<T>>
voidcoderDecodeEncodeContentsEqual
(Coder<CollectionT> coder, CollectionT value) Verifies that for the givenCoder<Collection<T>>
, and value of typeCollection<T>
, encoding followed by decoding yields an equal value of typeCollection<T>
, in anyCoder.Context
.static <T,
CollectionT extends Collection<T>>
voidcoderDecodeEncodeContentsEqualInContext
(Coder<CollectionT> coder, Coder.Context context, CollectionT value) Verifies that for the givenCoder<Collection<T>>
, and value of typeCollection<T>
, encoding followed by decoding yields an equal value of typeCollection<T>
, in the givenCoder.Context
.static <T,
IterableT extends Iterable<T>>
voidcoderDecodeEncodeContentsInSameOrder
(Coder<IterableT> coder, IterableT value) Verifies that for the givenCoder<Collection<T>>
, and value of typeCollection<T>
, encoding followed by decoding yields an equal value of typeCollection<T>
, in anyCoder.Context
.static <T,
IterableT extends Iterable<T>>
voidcoderDecodeEncodeContentsInSameOrderInContext
(Coder<IterableT> coder, Coder.Context context, IterableT value) Verifies that for the givenCoder<Iterable<T>>
, and value of typeIterable<T>
, encoding followed by decoding yields an equal value of typeCollection<T>
, in the givenCoder.Context
.static <T> void
coderDecodeEncodeEqual
(Coder<T> coder, T value) Verifies that for the givenCoder<T>
, and value of typeT
, encoding followed by decoding yields an equal value of typeT
, in anyCoder.Context
.static <T> void
coderDecodeEncodeEqualInContext
(Coder<T> coder, Coder.Context context, T value) Verifies that for the givenCoder<T>
,Coder.Context
, and value of typeT
, encoding followed by decoding yields an equal value of typeT
.static <T> void
coderDecodeEncodeInContext
(Coder<T> coder, Coder.Context context, T value, Matcher<T> matcher) Verifies that for the givenCoder<T>
,Coder.Context
, and value of typeT
, encoding followed by decoding yields a value of typeT
and tests that the matcher succeeds on the values.static <T> void
coderDecodesBase64
(Coder<T> coder, String base64Encoding, T value) static <T> void
coderDecodesBase64
(Coder<T> coder, List<String> base64Encodings, List<T> values) static <T,
IterableT extends Iterable<T>>
voidcoderDecodesBase64ContentsEqual
(Coder<IterableT> coder, String base64Encoding, IterableT expected) static <T,
IterableT extends Iterable<T>>
voidcoderDecodesBase64ContentsEqual
(Coder<IterableT> coder, List<String> base64Encodings, List<IterableT> expected) static <T> void
coderDeterministic
(Coder<T> coder, T value1, T value2) Verifies that for the givenCoder<T>
, and values of typeT
, if the values are equal then the encoded bytes are equal, in anyCoder.Context
.static <T> void
coderDeterministicInContext
(Coder<T> coder, Coder.Context context, T value1, T value2) Verifies that for the givenCoder<T>
,Coder.Context
, and values of typeT
, if the values are equal then the encoded bytes are equal.static <T> void
coderEncodesBase64
(Coder<T> coder, List<T> values, List<String> base64Encodings) static <T> void
coderEncodesBase64
(Coder<T> coder, T value, String base64Encoding) static <T> void
coderSerializable
(Coder<T> coder) Verifies that the givenCoder<T>
can be correctly serialized and deserialized.static <T> void
structuralValueConsistentWithEquals
(Coder<T> coder, T value1, T value2) Verifies that for the givenCoder<T>
and values of typeT
, the structural values are equal if and only if the encoded bytes are equal.static <T> void
structuralValueConsistentWithEqualsInContext
(Coder<T> coder, Coder.Context context, T value1, T value2) Verifies that for the givenCoder<T>
,Coder.Context
, and values of typeT
, the structural values are equal if and only if the encoded bytes are equal, in anyCoder.Context
.static <T> void
structuralValueDecodeEncodeEqual
(Coder<T> coder, T value) Verifies that for the givenCoder<T>
and value of typeT
, the structural value is equal to the structural value yield by encoding and decoding the original value.static <T> void
structuralValueDecodeEncodeEqualInContext
(Coder<T> coder, Coder.Context context, T value) Verifies that for the givenCoder<T>
,Coder.Context
, and value of typeT
, the structural value is equal to the structural value yield by encoding and decoding the original value, in anyCoder.Context
.static <T extends Iterable<?>>
voidstructuralValueDecodeEncodeEqualIterable
(Coder<T> coder, T value) Verifies that for the givenCoder<T>
and value of typeT
, the structural value of the content of the Iterable is equal to the structural value yield by encoding and decoding the original value.static <T extends Iterable<?>>
voidstructuralValueDecodeEncodeEqualIterableInContext
(Coder<T> coder, Coder.Context context, T value) Verifies that for the givenCoder<T>
,Coder.Context
, and value of typeT
, the structural content of the Iterable of the value is equal to the structural value yield by encoding and decoding the original value, in anyCoder.Context
.static <T> void
testByteCount
(Coder<T> coder, Coder.Context context, T[] elements) A utility method that passes the given (unencoded) elements through coder's registerByteSizeObserver() and encode() methods, and confirms they are mutually consistent.
-
Field Details
-
ALL_CONTEXTS
All the contexts, for use in test cases.
-
-
Constructor Details
-
CoderProperties
public CoderProperties()
-
-
Method Details
-
coderDeterministic
Verifies that for the givenCoder<T>
, and values of typeT
, if the values are equal then the encoded bytes are equal, in anyCoder.Context
.- Throws:
Exception
-
coderDeterministicInContext
public static <T> void coderDeterministicInContext(Coder<T> coder, Coder.Context context, T value1, T value2) throws Exception Verifies that for the givenCoder<T>
,Coder.Context
, and values of typeT
, if the values are equal then the encoded bytes are equal.- Throws:
Exception
-
coderDecodeEncodeEqual
Verifies that for the givenCoder<T>
, and value of typeT
, encoding followed by decoding yields an equal value of typeT
, in anyCoder.Context
.- Throws:
Exception
-
coderDecodeEncodeEqualInContext
public static <T> void coderDecodeEncodeEqualInContext(Coder<T> coder, Coder.Context context, T value) throws Exception Verifies that for the givenCoder<T>
,Coder.Context
, and value of typeT
, encoding followed by decoding yields an equal value of typeT
.- Throws:
Exception
-
coderDecodeEncodeInContext
public static <T> void coderDecodeEncodeInContext(Coder<T> coder, Coder.Context context, T value, Matcher<T> matcher) throws Exception Verifies that for the givenCoder<T>
,Coder.Context
, and value of typeT
, encoding followed by decoding yields a value of typeT
and tests that the matcher succeeds on the values.- Throws:
Exception
-
coderDecodeEncodeContentsEqual
public static <T,CollectionT extends Collection<T>> void coderDecodeEncodeContentsEqual(Coder<CollectionT> coder, CollectionT value) throws Exception Verifies that for the givenCoder<Collection<T>>
, and value of typeCollection<T>
, encoding followed by decoding yields an equal value of typeCollection<T>
, in anyCoder.Context
.- Throws:
Exception
-
coderDecodeEncodeContentsEqualInContext
public static <T,CollectionT extends Collection<T>> void coderDecodeEncodeContentsEqualInContext(Coder<CollectionT> coder, Coder.Context context, CollectionT value) throws Exception Verifies that for the givenCoder<Collection<T>>
, and value of typeCollection<T>
, encoding followed by decoding yields an equal value of typeCollection<T>
, in the givenCoder.Context
.- Throws:
Exception
-
coderDecodeEncodeContentsInSameOrder
public static <T,IterableT extends Iterable<T>> void coderDecodeEncodeContentsInSameOrder(Coder<IterableT> coder, IterableT value) throws Exception Verifies that for the givenCoder<Collection<T>>
, and value of typeCollection<T>
, encoding followed by decoding yields an equal value of typeCollection<T>
, in anyCoder.Context
.- Throws:
Exception
-
coderDecodeEncodeContentsInSameOrderInContext
public static <T,IterableT extends Iterable<T>> void coderDecodeEncodeContentsInSameOrderInContext(Coder<IterableT> coder, Coder.Context context, IterableT value) throws Exception Verifies that for the givenCoder<Iterable<T>>
, and value of typeIterable<T>
, encoding followed by decoding yields an equal value of typeCollection<T>
, in the givenCoder.Context
.- Throws:
Exception
-
coderSerializable
Verifies that the givenCoder<T>
can be correctly serialized and deserialized. -
coderConsistentWithEquals
public static <T> void coderConsistentWithEquals(Coder<T> coder, T value1, T value2) throws Exception Verifies that for the givenCoder<T>
and values of typeT
, the values are equal if and only if the encoded bytes are equal.- Throws:
Exception
-
coderConsistentWithEqualsInContext
public static <T> void coderConsistentWithEqualsInContext(Coder<T> coder, Coder.Context context, T value1, T value2) throws Exception Verifies that for the givenCoder<T>
,Coder.Context
, and values of typeT
, the values are equal if and only if the encoded bytes are equal, in anyCoder.Context
.- Throws:
Exception
-
structuralValueConsistentWithEquals
public static <T> void structuralValueConsistentWithEquals(Coder<T> coder, T value1, T value2) throws Exception Verifies that for the givenCoder<T>
and values of typeT
, the structural values are equal if and only if the encoded bytes are equal.- Throws:
Exception
-
structuralValueConsistentWithEqualsInContext
public static <T> void structuralValueConsistentWithEqualsInContext(Coder<T> coder, Coder.Context context, T value1, T value2) throws Exception Verifies that for the givenCoder<T>
,Coder.Context
, and values of typeT
, the structural values are equal if and only if the encoded bytes are equal, in anyCoder.Context
.- Throws:
Exception
-
structuralValueDecodeEncodeEqual
Verifies that for the givenCoder<T>
and value of typeT
, 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.
- Throws:
Exception
-
structuralValueDecodeEncodeEqualIterable
public static <T extends Iterable<?>> void structuralValueDecodeEncodeEqualIterable(Coder<T> coder, T value) throws Exception Verifies that for the givenCoder<T>
and value of typeT
, the structural value of the content of the Iterable 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.
- Throws:
Exception
-
structuralValueDecodeEncodeEqualInContext
public static <T> void structuralValueDecodeEncodeEqualInContext(Coder<T> coder, Coder.Context context, T value) throws Exception Verifies that for the givenCoder<T>
,Coder.Context
, and value of typeT
, the structural value is equal to the structural value yield by encoding and decoding the original value, in anyCoder.Context
.- Throws:
Exception
-
structuralValueDecodeEncodeEqualIterableInContext
public static <T extends Iterable<?>> void structuralValueDecodeEncodeEqualIterableInContext(Coder<T> coder, Coder.Context context, T value) throws Exception Verifies that for the givenCoder<T>
,Coder.Context
, and value of typeT
, the structural content of the Iterable of the value is equal to the structural value yield by encoding and decoding the original value, in anyCoder.Context
.- Throws:
Exception
-
coderDecodesBase64
public static <T> void coderDecodesBase64(Coder<T> coder, String base64Encoding, T value) throws Exception - Throws:
Exception
-
coderDecodesBase64
public static <T> void coderDecodesBase64(Coder<T> coder, List<String> base64Encodings, List<T> values) throws Exception - Throws:
Exception
-
coderEncodesBase64
public static <T> void coderEncodesBase64(Coder<T> coder, T value, String base64Encoding) throws Exception - Throws:
Exception
-
coderEncodesBase64
public static <T> void coderEncodesBase64(Coder<T> coder, List<T> values, List<String> base64Encodings) throws Exception - Throws:
Exception
-
coderDecodesBase64ContentsEqual
public static <T,IterableT extends Iterable<T>> void coderDecodesBase64ContentsEqual(Coder<IterableT> coder, String base64Encoding, IterableT expected) throws Exception - Throws:
Exception
-
coderDecodesBase64ContentsEqual
public static <T,IterableT extends Iterable<T>> void coderDecodesBase64ContentsEqual(Coder<IterableT> coder, List<String> base64Encodings, List<IterableT> expected) throws Exception - Throws:
Exception
-
testByteCount
public static <T> void testByteCount(Coder<T> coder, Coder.Context context, T[] elements) throws Exception A utility method that passes the given (unencoded) elements through coder's registerByteSizeObserver() and encode() methods, and confirms they are mutually consistent. This is useful for testing coder implementations.- Throws:
Exception
-