RocMarshal commented on code in PR #23635: URL: https://github.com/apache/flink/pull/23635#discussion_r1405002911
########## flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/TaskBalancedPreferredSlotSharingStrategyTest.java: ########## @@ -0,0 +1,248 @@ +/* + * 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.flink.runtime.scheduler; + +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.runtime.clusterframework.types.ResourceProfile; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.jobgraph.JobVertexID; +import org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroup; +import org.apache.flink.runtime.jobmanager.scheduler.CoLocationGroupImpl; +import org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup; +import org.apache.flink.runtime.scheduler.strategy.TestingSchedulingExecutionVertex; +import org.apache.flink.runtime.scheduler.strategy.TestingSchedulingTopology; +import org.apache.flink.util.Preconditions; + +import org.apache.flink.shaded.guava31.com.google.common.collect.Lists; +import org.apache.flink.shaded.guava31.com.google.common.collect.Sets; + +import org.assertj.core.data.Offset; +import org.junit.jupiter.api.Test; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Tests for {@link TaskBalancedPreferredSlotSharingStrategy}. */ +class TaskBalancedPreferredSlotSharingStrategyTest { + + @Test + void testCoLocationConstraintIsRespected() { + TestingSchedulingTopology topology = new TestingSchedulingTopology(); + List<Tuple2<JobVertexID, List<TestingSchedulingExecutionVertex>>> jobVertexInfos = + new ArrayList<>(); + SlotSharingGroup slotSharingGroup1 = new SlotSharingGroup(); + CoLocationGroup coLocationGroup1 = new CoLocationGroupImpl(); + CoLocationGroup coLocationGroup2 = new CoLocationGroupImpl(); + List<TestingJobVertexInfo> mockedJobVertices = + getMockedJobVertices(slotSharingGroup1, coLocationGroup1, coLocationGroup2); + setupCase(mockedJobVertices, topology, jobVertexInfos); + + final SlotSharingStrategy strategy = + new TaskBalancedPreferredSlotSharingStrategy( + topology, + Sets.newHashSet(slotSharingGroup1), + Sets.newHashSet(coLocationGroup1, coLocationGroup2)); + List<TestingSchedulingExecutionVertex> executionVertices1 = jobVertexInfos.get(1).f1; + List<TestingSchedulingExecutionVertex> executionVertices2 = jobVertexInfos.get(2).f1; + TestingSchedulingExecutionVertex executionVertexOfJv0 = jobVertexInfos.get(0).f1.get(0); + ExecutionSlotSharingGroup executionSlotSharingGroupOfExecutionVertexOfJv0 = + strategy.getExecutionSlotSharingGroup(executionVertexOfJv0.getId()); + + assertThat(executionVertices1).hasSameSizeAs(executionVertices2); + for (int i = 0; i < executionVertices1.size(); i++) { + ExecutionSlotSharingGroup executionSlotSharingGroup = + strategy.getExecutionSlotSharingGroup(executionVertices1.get(i).getId()); + assertThat(executionSlotSharingGroup) + .isNotEqualTo(executionSlotSharingGroupOfExecutionVertexOfJv0); + assertThat(executionSlotSharingGroup) + .isEqualTo( + strategy.getExecutionSlotSharingGroup( + executionVertices2.get(i).getId())); + } + + List<TestingSchedulingExecutionVertex> executionVertices3 = jobVertexInfos.get(3).f1; + List<TestingSchedulingExecutionVertex> executionVertices4 = jobVertexInfos.get(4).f1; + for (int i = 0; i < executionVertices1.size(); i++) { + assertThat(strategy.getExecutionSlotSharingGroup(executionVertices3.get(i).getId())) + .isEqualTo( + strategy.getExecutionSlotSharingGroup( + executionVertices4.get(i).getId())); + } + } + + @Nonnull + private static ArrayList<TestingJobVertexInfo> getMockedJobVertices( Review Comment: inlined it back into the calling lines. -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org