@Override public void verifyDeterministic() { VarIntCoder.of().verifyDeterministic(); VarLongCoder.of().verifyDeterministic(); }
@Override public FileIO.ReadableFile decode(InputStream is) throws IOException { MatchResult.Metadata metadata = MetadataCoder.of().decode(is); Compression compression = Compression.values()[VarIntCoder.of().decode(is)]; return new FileIO.ReadableFile(metadata, compression); } }
@Test public void testEmptyList() throws Exception { List<Integer> list = Collections.emptyList(); Coder<List<Integer>> coder = ListCoder.of(VarIntCoder.of()); CoderProperties.coderDecodeEncodeEqual(coder, list); }
@Override public void encode(FileIO.ReadableFile value, OutputStream os) throws IOException { MetadataCoder.of().encode(value.getMetadata(), os); VarIntCoder.of().encode(value.getCompression().ordinal(), os); }
@Test public void testCoderEquals() throws Exception { DelegateCoder.CodingFunction<Integer, Integer> identityFn = input -> input; Coder<Integer> varIntCoder1 = DelegateCoder.of(VarIntCoder.of(), identityFn, identityFn); Coder<Integer> varIntCoder2 = DelegateCoder.of(VarIntCoder.of(), identityFn, identityFn); Coder<Integer> bigEndianIntegerCoder = DelegateCoder.of(BigEndianIntegerCoder.of(), identityFn, identityFn); assertEquals(varIntCoder1, varIntCoder2); assertEquals(varIntCoder1.hashCode(), varIntCoder2.hashCode()); assertNotEquals(varIntCoder1, bigEndianIntegerCoder); assertNotEquals(varIntCoder1.hashCode(), bigEndianIntegerCoder.hashCode()); }
@Test public void testRegisterByteSizeObserver() throws Exception { CoderProperties.testByteCount( LengthPrefixCoder.of(VarIntCoder.of()), Coder.Context.NESTED, new Integer[] {0, 10, 1000}); }
@Test public void testListWithNullsAndVarIntCoderThrowsException() throws Exception { thrown.expect(CoderException.class); thrown.expectMessage("cannot encode a null Integer"); List<Integer> list = Arrays.asList(1, 2, 3, null, 4); Coder<List<Integer>> coder = ListCoder.of(VarIntCoder.of()); CoderProperties.coderDecodeEncodeEqual(coder, list); }
@Override public KV<Integer, Long> apply(KV<byte[], Long> input) { try { return KV.of( CoderUtils.decodeFromByteArray(VarIntCoder.of(), input.getKey()), input.getValue()); } catch (CoderException e) { fail("Unexpected Coder Exception " + e); throw new AssertionError("Unreachable"); } } }));
@Before public void setup() { MockitoAnnotations.initMocks(this); clock = MockClock.fromInstant(new Instant(0)); timerUpdateBuilder = TimerUpdate.builder(StructuralKey.of(1234, VarIntCoder.of())); internals = DirectTimerInternals.create(clock, watermarks, timerUpdateBuilder); }
@Override public PCollection<KV<String, Integer>> expand(PBegin input) { return PCollection.createPrimitiveOutputInternal( input.getPipeline(), WindowingStrategy.globalDefault(), PCollection.IsBounded.UNBOUNDED, KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of())); } });
@Test public void testDeclOfStateUsedInSuperclass() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("process"); thrown.expectMessage("declared in a different class"); thrown.expectMessage(DoFnUsingState.STATE_ID); DoFnSignatures.getSignature( new DoFnUsingState() { @StateId(DoFnUsingState.STATE_ID) private final StateSpec<ValueState<Integer>> spec = StateSpecs.value(VarIntCoder.of()); }.getClass()); }
@Test public void noInputUnkeyedOutput() { PCollection<KV<Integer, Iterable<Void>>> unkeyed = p.apply( Create.of(KV.<Integer, Iterable<Void>>of(-1, Collections.emptyList())) .withCoder(KvCoder.of(VarIntCoder.of(), IterableCoder.of(VoidCoder.of())))); p.traverseTopologically(visitor); assertThat(visitor.getKeyedPValues(), not(hasItem(unkeyed))); }
@Override public PCollection<KV<String, Integer>> expand(PBegin input) { return PCollection.createPrimitiveOutputInternal( input.getPipeline(), WindowingStrategy.globalDefault(), PCollection.IsBounded.UNBOUNDED, KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of())); } })
@Test public void testAdvanceWatermarkEqualToPositiveInfinityThrows() { Builder<Integer> stream = TestStream.create(VarIntCoder.of()) .advanceWatermarkTo(BoundedWindow.TIMESTAMP_MAX_VALUE.minus(1L)); thrown.expect(IllegalArgumentException.class); stream.advanceWatermarkTo(BoundedWindow.TIMESTAMP_MAX_VALUE); }
@Test public void testParameterizedDefaultNestedSetCoder() throws Exception { CoderRegistry registry = CoderRegistry.createDefault(); TypeDescriptor<Set<Set<Integer>>> setToken = new TypeDescriptor<Set<Set<Integer>>>() {}; assertEquals(SetCoder.of(SetCoder.of(VarIntCoder.of())), registry.getCoder(setToken)); }
@Test @Category(ValidatesRunner.class) public void testParDoEmptyOutputs() { List<Integer> inputs = Arrays.asList(); PCollection<String> output = pipeline .apply(Create.of(inputs).withCoder(VarIntCoder.of())) .apply("TestDoFn", ParDo.of(new TestNoOutputDoFn())); PAssert.that(output).empty(); pipeline.run(); }
@Test public void testElementAtPositiveInfinityThrows() { Builder<Integer> stream = TestStream.create(VarIntCoder.of()) .addElements(TimestampedValue.of(-1, BoundedWindow.TIMESTAMP_MAX_VALUE.minus(1L))); thrown.expect(IllegalArgumentException.class); stream.addElements(TimestampedValue.of(1, BoundedWindow.TIMESTAMP_MAX_VALUE)); }
@Test public void testListSideInputTranslation() throws Exception { assertEquals( ListCoder.of(KvCoder.of(VoidCoder.of(), VarIntCoder.of())), getTranslatedSideInputCoder(ImmutableList.of(11, 13, 17, 23), View.asList())); }