### Question:
ResourceTopStateAntiAffinityConstraint extends UsageSoftConstraint { @Override protected double getAssignmentScore(AssignableNode node, AssignableReplica replica, ClusterContext clusterContext) { if (!replica.isReplicaTopState()) { return 0; } int curTopPartitionCountForResource = node.getAssignedTopStatePartitionsCount(); int estimatedMaxTopStateCount = clusterContext.getEstimatedMaxTopStateCount(); return computeUtilizationScore(estimatedMaxTopStateCount, curTopPartitionCountForResource); }    }### Answer:
@Test public void testGetAssignmentScoreWhenReplicaNotTopState() { when(_testReplica.isReplicaTopState()).thenReturn(false); double score = _constraint.getAssignmentScore(_testNode, _testReplica, _clusterContext); double normalizedScore = _constraint.getAssignmentNormalizedScore(_testNode, _testReplica, _clusterContext); Assert.assertEquals(score, 0.0); Assert.assertEquals(normalizedScore, 1.0); verifyZeroInteractions(_testNode); verifyZeroInteractions(_clusterContext); }
@Test public void testGetAssignmentScoreWhenReplicaIsTopStateHeavyLoad() { when(_testReplica.isReplicaTopState()).thenReturn(true); when(_testNode.getAssignedTopStatePartitionsCount()).thenReturn(20); when(_clusterContext.getEstimatedMaxTopStateCount()).thenReturn(20); double score = _constraint.getAssignmentScore(_testNode, _testReplica, _clusterContext); double normalizedScore = _constraint.getAssignmentNormalizedScore(_testNode, _testReplica, _clusterContext); Assert.assertEquals(score, 1.0); Assert.assertEquals(normalizedScore, 0.5); }
@Test public void testGetAssignmentScoreWhenReplicaIsTopStateLightLoad() { when(_testReplica.isReplicaTopState()).thenReturn(true); when(_testNode.getAssignedTopStatePartitionsCount()).thenReturn(0); when(_clusterContext.getEstimatedMaxTopStateCount()).thenReturn(20); double score = _constraint.getAssignmentScore(_testNode, _testReplica, _clusterContext); double normalizedScore = _constraint.getAssignmentNormalizedScore(_testNode, _testReplica, _clusterContext); Assert.assertEquals(score, 0.0); Assert.assertEquals(normalizedScore, 1.0); }