@Test public void testDecodeEncodeEqual() throws Exception { for (String uriString : TEST_URI_STRINGS) { CoderProperties.coderDecodeEncodeEqual(uriCoder, new URI(uriString)); } }
@Test public void testCoderSerializable() throws Exception { CoderProperties.coderSerializable(TEST_CODER); }
public static <T> void coderEncodesBase64( Coder<T> coder, List<T> values, List<String> base64Encodings) throws Exception { assertThat( "List of base64 encodings has different size than List of values", base64Encodings.size(), equalTo(values.size())); for (int i = 0; i < base64Encodings.size(); i++) { coderEncodesBase64(coder, values.get(i), base64Encodings.get(i)); } }
@Test public void testDecodeEncodeEqual() throws Exception { for (SolrDocument value : TEST_VALUES) { CoderProperties.coderDecodeEncodeContentsInSameOrder(TEST_CODER, value); CoderProperties.structuralValueDecodeEncodeEqual(TEST_CODER, value); } }
@Test public void testNestedCoding() throws Throwable { Coder<List<ByteString>> listCoder = ListCoder.of(TEST_CODER); CoderProperties.coderDecodeEncodeContentsEqual(listCoder, TEST_VALUES); CoderProperties.coderDecodeEncodeContentsInSameOrder(listCoder, TEST_VALUES); }
@Test public void saneCoder() throws Exception { OutgoingMessage message = new OutgoingMessage( DATA.getBytes(StandardCharsets.UTF_8), ImmutableMap.of(), TIMESTAMP, getRecordId(DATA)); CoderProperties.coderDecodeEncodeEqual(PubsubUnboundedSink.CODER, message); CoderProperties.coderSerializable(PubsubUnboundedSink.CODER); }
@Test public void testCoder() throws Exception { RandomAccessData streamA = new RandomAccessData(); streamA.asOutputStream().write(TEST_DATA_A); RandomAccessData streamB = new RandomAccessData(); streamB.asOutputStream().write(TEST_DATA_A); CoderProperties.coderDecodeEncodeEqual(RandomAccessDataCoder.of(), streamA); CoderProperties.coderDeterministic(RandomAccessDataCoder.of(), streamA, streamB); CoderProperties.coderConsistentWithEquals(RandomAccessDataCoder.of(), streamA, streamB); CoderProperties.coderSerializable(RandomAccessDataCoder.of()); CoderProperties.structuralValueConsistentWithEquals( RandomAccessDataCoder.of(), streamA, streamB); assertTrue(RandomAccessDataCoder.of().isRegisterByteSizeObserverCheap(streamA)); assertEquals(4, RandomAccessDataCoder.of().getEncodedElementByteSize(streamA)); }
@Test public void testTimerCoderWithConsistentWithEqualsPayloadCoder() throws Exception { Coder<Timer<String>> coder = Timer.Coder.of(StringUtf8Coder.of()); CoderProperties.coderDecodeEncodeEqual(coder, Timer.of(INSTANT, "ABC")); CoderProperties.coderConsistentWithEquals( coder, Timer.of(INSTANT, "ABC"), Timer.of(INSTANT, "ABC")); CoderProperties.coderDeterministic(coder, Timer.of(INSTANT, "ABC"), Timer.of(INSTANT, "ABC")); }
@Test public void testTimerCoderWithInconsistentWithEqualsPayloadCoder() throws Exception { Coder<Timer<byte[]>> coder = Timer.Coder.of(ByteArrayCoder.of()); CoderProperties.coderSerializable(coder); CoderProperties.structuralValueDecodeEncodeEqual( coder, Timer.of(INSTANT, "ABC".getBytes(UTF_8))); CoderProperties.structuralValueConsistentWithEquals( coder, Timer.of(INSTANT, "ABC".getBytes(UTF_8)), Timer.of(INSTANT, "ABC".getBytes(UTF_8))); }
@Test public void testAvroCoderEncoding() throws Exception { AvroCoder<Pojo> coder = AvroCoder.of(Pojo.class); CoderProperties.coderSerializable(coder); AvroCoder<Pojo> copy = SerializableUtils.clone(coder); Pojo pojo = new Pojo("foo", 3); Pojo equalPojo = new Pojo("foo", 3); Pojo otherPojo = new Pojo("bar", -19); CoderProperties.coderConsistentWithEquals(coder, pojo, equalPojo); CoderProperties.coderConsistentWithEquals(copy, pojo, equalPojo); CoderProperties.coderConsistentWithEquals(coder, pojo, otherPojo); CoderProperties.coderConsistentWithEquals(copy, pojo, otherPojo); }
@Test public void testCoderIsDeterministic() throws Exception { CoderProperties.coderDeterministic( GlobalWindow.Coder.INSTANCE, GlobalWindow.INSTANCE, GlobalWindow.INSTANCE); } }
@Test public void testStructuralValueConsistentWithEquals() throws Exception { // We know that bi array coders are NOT compatible with equals // (aka injective w.r.t. Object.equals) for (BitSet value1 : TEST_VALUES) { for (BitSet value2 : TEST_VALUES) { CoderProperties.structuralValueConsistentWithEquals(TEST_CODER, value1, value2); } } }
@Test public void testConsistentWithEqualsArrayOfArrayOfBytes() throws Exception { FieldType fieldType = FieldType.array(FieldType.array(FieldType.BYTES)); Schema schema = Schema.of(Schema.Field.of("f1", fieldType)); RowCoder coder = RowCoder.of(schema); List<byte[]> innerList1 = Collections.singletonList(new byte[] {1, 2, 3, 4}); List<List<byte[]>> list1 = Collections.singletonList(innerList1); Row row1 = Row.withSchema(schema).addValue(list1).build(); List<byte[]> innerList2 = Collections.singletonList(new byte[] {1, 2, 3, 4}); List<List<byte[]>> list2 = Collections.singletonList(innerList2); Row row2 = Row.withSchema(schema).addValue(list2).build(); Assume.assumeTrue(coder.consistentWithEquals()); CoderProperties.coderConsistentWithEquals(coder, row1, row2); } }
@Test public void testDecodeEncodeContentsInSameOrder() throws Exception { for (List<Integer> value : TEST_VALUES) { CoderProperties.coderDecodeEncodeContentsInSameOrder(TEST_CODER, value); } }
@Test public void testDeterministic() throws Exception, NonDeterministicException { uriCoder.verifyDeterministic(); for (String uriString : TEST_URI_STRINGS) { CoderProperties.coderDeterministic(uriCoder, new URI(uriString), new URI(uriString)); } }
@Test public void testStructuralValueConsistentWithEquals() throws Exception { CoderProperties.structuralValueConsistentWithEquals(TEST_CODER, null, null); }
@Test public void testConsistentWithEqualsArrayOfBytes() throws Exception { FieldType fieldType = FieldType.array(FieldType.BYTES); Schema schema = Schema.of(Schema.Field.of("f1", fieldType)); RowCoder coder = RowCoder.of(schema); List<byte[]> list1 = Collections.singletonList(new byte[] {1, 2, 3, 4}); Row row1 = Row.withSchema(schema).addValue(list1).build(); List<byte[]> list2 = Collections.singletonList(new byte[] {1, 2, 3, 4}); Row row2 = Row.withSchema(schema).addValue(list2).build(); Assume.assumeTrue(coder.consistentWithEquals()); CoderProperties.coderConsistentWithEquals(coder, row1, row2); }
@Test public void testDecodeEncodeContentsInSameOrder() throws Exception { for (Iterable<Integer> value : TEST_VALUES) { CoderProperties.coderDecodeEncodeContentsInSameOrder(TEST_CODER, value); } }
@Test public void testDecodeEncodeEqual() throws Exception { for (Integer value : TEST_VALUES) { CoderProperties.coderDecodeEncodeEqual(TEST_CODER, value); } }
@Test public void testCoderIsSerialiable() { CoderProperties.coderSerializable(TEST_CODER); }