ErnestasVaiciukeviciusAdform commented on code in PR #9175: URL: https://github.com/apache/storm/pull/9175#discussion_r4312779375
########## storm-client/test/jvm/org/apache/storm/daemon/worker/WorkerOutboundTasksTest.java: ########## @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version + * 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ + +package org.apache.storm.daemon.worker; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.storm.Config; +import org.apache.storm.generated.StormTopology; +import org.apache.storm.spout.SpoutOutputCollector; +import org.apache.storm.task.GeneralTopologyContext; +import org.apache.storm.task.TopologyContext; +import org.apache.storm.topology.IRichBolt; +import org.apache.storm.topology.IRichSpout; +import org.apache.storm.topology.OutputFieldsDeclarer; +import org.apache.storm.topology.TopologyBuilder; +import org.apache.storm.topology.base.BaseRichBolt; +import org.apache.storm.topology.base.BaseRichSpout; +import org.apache.storm.tuple.Tuple; +import org.junit.jupiter.api.Test; + +/** + * Unit tests for {@link WorkerState#computeOutboundTasks}, which decides the set of task ids a worker must be able to + * route messages to. The key behaviour under test: when upstream feedback is enabled, the upstream (source) component + * tasks of locally-hosted components must be included, because feedback tuples are routed directly to them. Otherwise + * they are missing from {@code cachedTaskToNodePort}, the feedback is dropped and {@code TransferDrainer} logs the + * spurious "No remote destination available for task" warning. + */ +public class WorkerOutboundTasksTest { + + // Linear topology: spout -> bolt1 -> bolt2. Task ids are topology-global and unique per component. + private static final List<Integer> SPOUT_TASKS = Arrays.asList(1, 2); + private static final List<Integer> BOLT1_TASKS = Arrays.asList(3, 4); + private static final List<Integer> BOLT2_TASKS = Arrays.asList(5, 6); + + private GeneralTopologyContext context() { + TopologyBuilder builder = new TopologyBuilder(); + builder.setSpout("spout", new NoopSpout()); + builder.setBolt("bolt1", new NoopBolt()).shuffleGrouping("spout"); + builder.setBolt("bolt2", new NoopBolt()).shuffleGrouping("bolt1"); + StormTopology topology = builder.createTopology(); + + Map<Integer, String> taskToComponent = new HashMap<>(); + SPOUT_TASKS.forEach(t -> taskToComponent.put(t, "spout")); + BOLT1_TASKS.forEach(t -> taskToComponent.put(t, "bolt1")); + BOLT2_TASKS.forEach(t -> taskToComponent.put(t, "bolt2")); + + Map<String, List<Integer>> componentToSortedTasks = new HashMap<>(); + componentToSortedTasks.put("spout", SPOUT_TASKS); + componentToSortedTasks.put("bolt1", BOLT1_TASKS); + componentToSortedTasks.put("bolt2", BOLT2_TASKS); + + return new GeneralTopologyContext(topology, new Config(), taskToComponent, componentToSortedTasks, + new HashMap<>(), "topology-id"); + } + + @Test + public void feedbackDisabled_onlyDownstreamTargets() { + // Worker hosts a bolt1 task. Its only downstream target is bolt2, so the upstream spout tasks are not routable. + GeneralTopologyContext context = context(); + Set<Integer> outbound = WorkerState.computeOutboundTasks(context, BOLT1_TASKS.subList(0, 1), + context.getTaskToComponent(), false); + + assertEquals(new java.util.HashSet<>(BOLT2_TASKS), outbound); + SPOUT_TASKS.forEach(t -> assertFalse(outbound.contains(t), "spout task " + t + " must not be routable without feedback")); + } + + @Test + public void feedbackEnabled_includesUpstreamSourceTasks() { Review Comment: Added test cases with full WorkerState construction: * testTopologyConfigEnabledFeedback * testTopologyConfigDisabledFeedback -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
