use of org.apache.beam.sdk.extensions.protobuf.ProtoDomain in project beam by apache.
the class PubsubIOTest method testProtoDynamicMessages.
@Test
public void testProtoDynamicMessages() {
ProtoCoder<Primitive> coder = ProtoCoder.of(Primitive.class);
ImmutableList<Primitive> inputs = ImmutableList.of(Primitive.newBuilder().setPrimitiveInt32(42).build(), Primitive.newBuilder().setPrimitiveBool(true).build(), Primitive.newBuilder().setPrimitiveString("Hello, World!").build());
setupTestClient(inputs, coder);
ProtoDomain domain = ProtoDomain.buildFrom(Primitive.getDescriptor());
String name = Primitive.getDescriptor().getFullName();
PCollection<Primitive> read = readPipeline.apply(PubsubIO.readProtoDynamicMessages(domain, name).fromSubscription(SUBSCRIPTION.getPath()).withClock(CLOCK).withClientFactory(clientFactory)).apply("Return To Primitive", MapElements.into(TypeDescriptor.of(Primitive.class)).via((DynamicMessage message) -> {
try {
return Primitive.parseFrom(message.toByteArray());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Could not return to Primitive", e);
}
}));
PAssert.that(read).containsInAnyOrder(inputs);
readPipeline.run();
}
Aggregations