KryoCoder extends CustomCoder<T> { public static <T> KryoCoder<T> of() { return of(PipelineOptionsFactory.create(), Collections.emptyList()); } private  KryoCoder(SerializableOptions options, List<KryoRegistrar> registrars); static KryoCoder<T> of(); static KryoCoder<T> of(KryoRegistrar... registrars); static KryoCoder<T> of(List<KryoRegistrar> registrars); static KryoCoder<T> of(PipelineOptions pipelineOptions); static KryoCoder<T> of(PipelineOptions pipelineOptions, KryoRegistrar... registrars); static KryoCoder<T> of(
      PipelineOptions pipelineOptions, List<KryoRegistrar> registrars); @Override void encode(T value, OutputStream outStream); @Override T decode(InputStream inStream); @Override void verifyDeterministic(); KryoCoder<T> withRegistrar(KryoRegistrar registrar); @Override int hashCode(); @Override boolean equals(@Nullable Object other);  }
@Test public void testBasicCoding() throws IOException { final KryoCoder<ClassToBeEncoded> coder = KryoCoder.of(OPTIONS, k -> k.register(ClassToBeEncoded.class)); assertEncoding(coder); }
@Test(expected = CoderException.class) public void testWrongRegistrarCoding() throws IOException { OPTIONS.as(KryoOptions.class).setKryoRegistrationRequired(true); final KryoCoder<ClassToBeEncoded> coder = KryoCoder.of(OPTIONS); assertEncoding(coder); }
@Test(expected = CoderException.class) public void testWrongRegistrarDecoding() throws IOException { final KryoRegistrar registrarCoding = k -> k.register(ClassToBeEncoded.class); final KryoRegistrar registrarDecoding = k -> { }; final KryoCoder<ClassToBeEncoded> coderToEncode = KryoCoder.of(OPTIONS, registrarCoding); final KryoCoder<ClassToBeEncoded> coderToDecode = KryoCoder.of(OPTIONS, registrarDecoding); assertEncoding(coderToEncode, coderToDecode); }
@Test public void testCoderSerialization() throws IOException, ClassNotFoundException { final KryoRegistrar registrar = k -> k.register(ClassToBeEncoded.class); final KryoCoder<ClassToBeEncoded> coder = KryoCoder.of(OPTIONS, registrar); final ByteArrayOutputStream outStr = new ByteArrayOutputStream(); final ObjectOutputStream oss = new ObjectOutputStream(outStr); oss.writeObject(coder); oss.flush(); oss.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(outStr.toByteArray())); @SuppressWarnings("unchecked") KryoCoder<ClassToBeEncoded> coderDeserialized = (KryoCoder<ClassToBeEncoded>) ois.readObject(); assertEncoding(coder, coderDeserialized); }