@Override public Coder<CovarianceAccumulator> getAccumulatorCoder( CoderRegistry registry, Coder<Row> inputCoder) { return SerializableCoder.of(CovarianceAccumulator.class); }
@VisibleForTesting static MutationGroup decode(byte[] bytes) { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); try { return CODER.decode(bis); } catch (IOException e) { throw new RuntimeException(e); } }
@Test(expected = IOException.class) public void coderDoesNotWrapIoException() throws Exception { final SerializableCoder<String> coder = SerializableCoder.of(String.class); final OutputStream outputStream = mock( OutputStream.class, (Answer) invocationOnMock -> { throw new IOException(); }); coder.encode("", outputStream); } }
@Test public void testEncodingNotBuffered() throws Exception { // This test ensures that the coder doesn't read ahead and buffer data. // Reading ahead causes a problem if the stream consists of records of different // types. Pojo before = new Pojo("Hello", 42); AvroCoder<Pojo> coder = AvroCoder.of(Pojo.class); SerializableCoder<Integer> intCoder = SerializableCoder.of(Integer.class); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Context context = Context.NESTED; coder.encode(before, outStream, context); intCoder.encode(10, outStream, context); ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray()); Pojo after = coder.decode(inStream, context); Assert.assertEquals(before, after); Integer intAfter = intCoder.decode(inStream, context); Assert.assertEquals(Integer.valueOf(10), intAfter); }
@Test public void testSerializableCoderConstruction() throws Exception { SerializableCoder<MyRecord> coder = SerializableCoder.of(MyRecord.class); assertEquals(coder.getRecordType(), MyRecord.class); CoderProperties.coderSerializable(coder); SerializableCoder<?> decoded = SerializableUtils.clone(coder); assertThat(decoded.getRecordType(), Matchers.<Object>equalTo(MyRecord.class)); }
@Test public void testEncodedTypeDescriptor() throws Exception { assertThat( SerializableCoder.of(MyRecord.class).getEncodedTypeDescriptor(), Matchers.equalTo(TypeDescriptor.of(MyRecord.class))); }
@VisibleForTesting static byte[] encode(MutationGroup g) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { CODER.encode(g, bos); } catch (IOException e) { throw new RuntimeException(e); } return bos.toByteArray(); } }
@Override public CloudObject toCloudObject(SerializableCoder target, SdkComponents sdkComponents) { CloudObject base = CloudObject.forClass(SerializableCoder.class); Structs.addString(base, TYPE_FIELD, target.getRecordType().getName()); return base; }
@Override public Coder<KinesisReaderCheckpoint> getCheckpointMarkCoder() { return SerializableCoder.of(KinesisReaderCheckpoint.class); }
@Override public Coder<ObjectId> getOutputCoder() { return SerializableCoder.of(ObjectId.class); }
@Override public Coder<VarianceAccumulator> getAccumulatorCoder( CoderRegistry registry, Coder<T> inputCoder) { return SerializableCoder.of(VarianceAccumulator.class); }
@Override public Coder<AmqpCheckpointMark> getCheckpointMarkCoder() { return SerializableCoder.of(AmqpCheckpointMark.class); } }
@Override public Coder<LargestUnique> getAccumulatorCoder(CoderRegistry registry, Coder<T> inputCoder) { return SerializableCoder.of(LargestUnique.class); }
@Override public Coder<Document> getOutputCoder() { return SerializableCoder.of(Document.class); }
@Override public Coder<SqsCheckpointMark> getCheckpointMarkCoder() { return SerializableCoder.of(SqsCheckpointMark.class); }
@Override public Coder<Message> getOutputCoder() { return SerializableCoder.of(Message.class); }
BoundedSourceCoder() { coder = (Coder<BoundedSource<T>>) SerializableCoder.of((Class) BoundedSource.class); }
@Override public Coder<Accum> getAccumulatorCoder(CoderRegistry registry, Coder<String> inputCoder) throws CannotProvideCoderException { return SerializableCoder.of(Accum.class); }
@Override public Coder<Counter> getAccumulatorCoder(CoderRegistry registry, Coder<Integer> inputCoder) { // This is a *very* inefficient encoding to send over the wire, but suffices // for tests. return SerializableCoder.of(Counter.class); } }