Map<ExecNode<?>, Integer> calculateMaximumDistance() {
        Map<ExecNode<?>, Integer> result = new HashMap<>();
        Map<TopologyNode, Integer> inputsVisitedMap = new HashMap<>();

        Queue<TopologyNode> queue = new LinkedList<>();
        for (TopologyNode node : nodes.values()) {
            if (node.inputs.size() == 0) {
                queue.offer(node);
            }
        }

        while (!queue.isEmpty()) {
            TopologyNode node = queue.poll();
            int dist = -1;
            for (TopologyNode input : node.inputs) {
                dist =
                        Math.max(
                                dist,
                                Preconditions.checkNotNull(
                                        result.get(input.execNode),
                                        "The distance of an input node is not calculated. This is a bug."));
            }
            dist++;
            result.put(node.execNode, dist);

            for (TopologyNode output : node.outputs) {
                int inputsVisited =
                        inputsVisitedMap.compute(output, (k, v) -> v == null ? 1 : v + 1);
                if (inputsVisited == output.inputs.size()) {
                    queue.offer(output);
                }
            }
        }

        return result;
    }
@Test
    void testBoundedCalculateMaximumDistance() {
        Tuple2<TopologyGraph, TestingBatchExecNode[]> tuple2 = buildBoundedTopologyGraph();
        TopologyGraph graph = tuple2.f0;
        TestingBatchExecNode[] nodes = tuple2.f1;

        Map<ExecNode<?>, Integer> result = graph.calculateMaximumDistance();
        assertThat(result).hasSize(6);
        assertThat(result.get(nodes[2]).intValue()).isEqualTo(0);
        assertThat(result.get(nodes[3]).intValue()).isEqualTo(0);
        assertThat(result.get(nodes[4]).intValue()).isEqualTo(1);
        assertThat(result.get(nodes[6]).intValue()).isEqualTo(1);
        assertThat(result.get(nodes[5]).intValue()).isEqualTo(2);
        assertThat(result.get(nodes[7]).intValue()).isEqualTo(2);
    }