github-actions[bot] commented on code in PR #62054: URL: https://github.com/apache/doris/pull/62054#discussion_r3032456792
########## fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/distribute/BucketShuffleDestinationTest.java: ########## @@ -0,0 +1,134 @@ +// 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.doris.nereids.trees.plans.distribute; + +import org.apache.doris.nereids.trees.plans.distribute.worker.DistributedPlanWorker; +import org.apache.doris.nereids.trees.plans.distribute.worker.job.AssignedJob; +import org.apache.doris.nereids.trees.plans.distribute.worker.job.BucketScanSource; +import org.apache.doris.nereids.trees.plans.distribute.worker.job.LocalShuffleBucketJoinAssignedJob; +import org.apache.doris.nereids.trees.plans.distribute.worker.job.ScanRanges; +import org.apache.doris.nereids.trees.plans.distribute.worker.job.UnassignedJob; +import org.apache.doris.planner.ScanNode; +import org.apache.doris.thrift.TUniqueId; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Tests that bucket shuffle + pooling (LocalShuffle) produces correct destinations: + * - destinations count == bucketNum + * - same BE's buckets all point to the same (first) instance + * + * Uses reflection to call DistributePlanner.sortDestinationInstancesByBuckets (private method). + */ +public class BucketShuffleDestinationTest { + + /** + * Simulate 3 workers with 6 buckets (distribution: worker0=[0,3], worker1=[1,4], worker2=[2,5]). + * Input = first-per-worker instances (simulating filterInstancesWhichCanReceiveDataFromRemote output). + * Each first instance's BucketScanSource contains ALL buckets for that worker. + * sortDestinationInstancesByBuckets should produce 6 destinations where same-worker + * buckets point to the same instance. + */ + @Test + public void testBucketShufflePoolingDestinations() throws Exception { + DistributedPlanWorker worker0 = Mockito.mock(DistributedPlanWorker.class); + DistributedPlanWorker worker1 = Mockito.mock(DistributedPlanWorker.class); + DistributedPlanWorker worker2 = Mockito.mock(DistributedPlanWorker.class); + Mockito.when(worker0.id()).thenReturn(100L); + Mockito.when(worker1.id()).thenReturn(200L); + Mockito.when(worker2.id()).thenReturn(300L); + + ScanNode mockScanNode = Mockito.mock(ScanNode.class); + UnassignedJob mockJob = Mockito.mock(UnassignedJob.class); + + // Worker0 first instance: has buckets 0 and 3 + BucketScanSource source0 = makeBucketScanSource(mockScanNode, 0, 3); + LocalShuffleBucketJoinAssignedJob inst0 = new LocalShuffleBucketJoinAssignedJob( + 0, 0, new TUniqueId(0, 0), mockJob, worker0, source0, ImmutableSet.of(0, 3)); + + // Worker1 first instance: has buckets 1 and 4 + BucketScanSource source1 = makeBucketScanSource(mockScanNode, 1, 4); + LocalShuffleBucketJoinAssignedJob inst1 = new LocalShuffleBucketJoinAssignedJob( + 1, 0, new TUniqueId(0, 1), mockJob, worker1, source1, ImmutableSet.of(1, 4)); + + // Worker2 first instance: has buckets 2 and 5 + BucketScanSource source2 = makeBucketScanSource(mockScanNode, 2, 5); + LocalShuffleBucketJoinAssignedJob inst2 = new LocalShuffleBucketJoinAssignedJob( + 2, 0, new TUniqueId(0, 2), mockJob, worker2, source2, ImmutableSet.of(2, 5)); + + // This simulates getFirstInstancePerWorker output + List<AssignedJob> firstPerWorker = new ArrayList<>(); + firstPerWorker.add(inst0); + firstPerWorker.add(inst1); + firstPerWorker.add(inst2); + + // Invoke private sortDestinationInstancesByBuckets via reflection + PipelineDistributedPlan mockPlan = Mockito.mock(PipelineDistributedPlan.class); + Mockito.when(mockPlan.getFragmentJob()).thenReturn(mockJob); + + Method method = DistributePlanner.class.getDeclaredMethod( Review Comment: `sortDestinationInstancesByBuckets()` now has the signature `(PipelineDistributedPlan, List<AssignedJob>, int, boolean)`, but this test still looks up and invokes the old 3-argument form. At runtime `getDeclaredMethod(...)` will throw `NoSuchMethodException` here, so the new coverage never exercises the non-serial bucket-assignment branch. Please update both the reflective lookup and the `invoke(...)` call (or avoid reflection entirely) so the test actually validates the new logic. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
