use of com.google.api.services.dataflow.model.ParDoInstruction in project beam by apache.
the class ReplacePgbkWithPrecombineFunctionTest method testPrecombinePgbkIsReplaced.
@Test
public void testPrecombinePgbkIsReplaced() throws Exception {
// Network:
// out1 --> precombine_pgbk --> out2
Map<String, Object> valueCombiningFn = new HashMap<>();
Node out1 = createInstructionOutputNode("out1");
String pgbkName = "precombine_pgbk";
Node precombinePgbk = createPrecombinePgbkNode(pgbkName, valueCombiningFn);
Node out2 = createInstructionOutputNode("out2");
MutableNetwork<Node, Edge> network = createEmptyNetwork();
network.addNode(out1);
network.addNode(precombinePgbk);
network.addNode(out2);
network.addEdge(out1, precombinePgbk, DefaultEdge.create());
network.addEdge(precombinePgbk, out2, DefaultEdge.create());
Network<Node, Edge> inputNetwork = ImmutableNetwork.copyOf(network);
network = new ReplacePgbkWithPrecombineFunction().apply(network);
// Assert that network has same structure (same number of nodes and paths).
assertEquals(inputNetwork.nodes().size(), network.nodes().size());
assertEquals(inputNetwork.edges().size(), network.edges().size());
List<List<Node>> oldPaths = Networks.allPathsFromRootsToLeaves(inputNetwork);
List<List<Node>> newPaths = Networks.allPathsFromRootsToLeaves(network);
assertEquals(oldPaths.size(), newPaths.size());
// Assert that the pgbk node has been replaced.
for (Node node : network.nodes()) {
if (node instanceof ParallelInstructionNode) {
ParallelInstructionNode createdCombineNode = (ParallelInstructionNode) node;
ParallelInstruction parallelInstruction = createdCombineNode.getParallelInstruction();
assertEquals(parallelInstruction.getName(), pgbkName);
assertNull(parallelInstruction.getPartialGroupByKey());
assertNotNull(parallelInstruction.getParDo());
ParDoInstruction parDoInstruction = parallelInstruction.getParDo();
assertEquals(parDoInstruction.getUserFn(), valueCombiningFn);
break;
}
}
}
Aggregations