use of org.apache.beam.sdk.coders.ListCoder in project beam by apache.
the class KryoCoderTest method testCodingWithKvCoderKeyIsKryoCoder.
@Test
public void testCodingWithKvCoderKeyIsKryoCoder() throws IOException {
final KryoRegistrar registrar = k -> k.register(TestClass.class);
final ListCoder<Void> listCoder = ListCoder.of(VoidCoder.of());
final KvCoder<TestClass, List<Void>> kvCoder = KvCoder.of(KryoCoder.of(OPTIONS, registrar), listCoder);
final List<Void> inputValue = new ArrayList<>();
inputValue.add(null);
inputValue.add(null);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final TestClass inputKey = new TestClass("something");
kvCoder.encode(KV.of(inputKey, inputValue), byteArrayOutputStream);
final KV<TestClass, List<Void>> decoded = kvCoder.decode(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
assertNotNull(decoded);
assertNotNull(decoded.getKey());
assertEquals(inputKey, decoded.getKey());
assertNotNull(decoded.getValue());
assertEquals(inputValue, decoded.getValue());
}
use of org.apache.beam.sdk.coders.ListCoder in project beam by apache.
the class KryoCoderTest method testCodingWithKvCoderClassToBeEncoded.
@Test
public void testCodingWithKvCoderClassToBeEncoded() throws IOException {
final KryoRegistrar registrar = k -> {
k.register(TestClass.class);
k.register(ClassToBeEncoded.class);
};
final ListCoder<Void> listCoder = ListCoder.of(VoidCoder.of());
final KvCoder<ClassToBeEncoded, List<Void>> kvCoder = KvCoder.of(KryoCoder.of(OPTIONS, registrar), listCoder);
final List<Void> inputValue = new ArrayList<>();
inputValue.add(null);
inputValue.add(null);
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final ClassToBeEncoded inputKey = new ClassToBeEncoded("something", 1, 0.2);
kvCoder.encode(KV.of(inputKey, inputValue), byteArrayOutputStream);
final KV<ClassToBeEncoded, List<Void>> decoded = kvCoder.decode(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
assertNotNull(decoded);
assertNotNull(decoded.getKey());
assertEquals(inputKey, decoded.getKey());
assertNotNull(decoded.getValue());
assertEquals(inputValue, decoded.getValue());
}
Aggregations