kirklund commented on a change in pull request #6845: URL: https://github.com/apache/geode/pull/6845#discussion_r703851825
########## File path: geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/rebalance/MemberTest.java ########## @@ -0,0 +1,107 @@ +/* + * 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.geode.internal.cache.partitioned.rebalance; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; + +import org.apache.geode.distributed.internal.ClusterDistributionManager; +import org.apache.geode.distributed.internal.membership.InternalDistributedMember; +import org.apache.geode.internal.cache.partitioned.rebalance.model.AddressComparor; +import org.apache.geode.internal.cache.partitioned.rebalance.model.Bucket; +import org.apache.geode.internal.cache.partitioned.rebalance.model.Member; +import org.apache.geode.internal.cache.partitioned.rebalance.model.RefusalReason; + +public class MemberTest { + AddressComparor addressComparor = mock(AddressComparor.class); + InternalDistributedMember memberId = mock(InternalDistributedMember.class); + InternalDistributedMember otherMemberId = mock(InternalDistributedMember.class); Review comment: You should probably make fields like these `private` even though it's unlikely someone will try to access them. I only add this because I've seen so many tangled dunit tests that access each other's non-private fields. ########## File path: geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/rebalance/model/PartitionedRegionLoadModel.java ########## @@ -473,21 +478,23 @@ public Move findBestRemove(Bucket bucket) { Move bestMove = null; for (Member member : bucket.getMembersHosting()) { - float newLoad = (member.getTotalLoad() - bucket.getLoad()) / member.getWeight(); - if (newLoad > mostLoaded && !member.equals(bucket.getPrimary())) { - Move move = new Move(null, member, bucket); - if (!this.attemptedBucketRemoves.contains(move)) { - mostLoaded = newLoad; - bestMove = move; + if (member.canDelete(bucket, partitionedRegion.getDistributionManager()).willAccept()) { + float newLoad = (member.getTotalLoad() - bucket.getLoad()) / member.getWeight(); + if (newLoad > mostLoaded && !member.equals(bucket.getPrimary())) { + Move move = new Move(null, member, bucket); + if (!this.attemptedBucketRemoves.contains(move)) { + mostLoaded = newLoad; + bestMove = move; + } Review comment: I would add a unit test for this block if possible. -- 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]
