### Question:
SCMContainerPlacementCapacity extends SCMCommonPlacementPolicy { @Override public List<DatanodeDetails> chooseDatanodes( List<DatanodeDetails> excludedNodes, List<DatanodeDetails> favoredNodes, final int nodesRequired, final long sizeRequired) throws SCMException { List<DatanodeDetails> healthyNodes = super.chooseDatanodes(excludedNodes, favoredNodes, nodesRequired, sizeRequired); if (healthyNodes.size() == nodesRequired) { return healthyNodes; } return getResultSet(nodesRequired, healthyNodes); } SCMContainerPlacementCapacity(final NodeManager nodeManager,
      final ConfigurationSource conf, final NetworkTopology networkTopology,
      final boolean fallback, final SCMContainerPlacementMetrics metrics); @Override List<DatanodeDetails> chooseDatanodes(
      List<DatanodeDetails> excludedNodes, List<DatanodeDetails> favoredNodes,
      final int nodesRequired, final long sizeRequired); @Override DatanodeDetails chooseNode(List<DatanodeDetails> healthyNodes);  }### Answer:
@Test public void chooseDatanodes() throws SCMException { ConfigurationSource conf = new OzoneConfiguration(); List<DatanodeDetails> datanodes = new ArrayList<>(); for (int i = 0; i < 7; i++) { datanodes.add(MockDatanodeDetails.randomDatanodeDetails()); } NodeManager mockNodeManager = Mockito.mock(NodeManager.class); when(mockNodeManager.getNodes(NodeState.HEALTHY)) .thenReturn(new ArrayList<>(datanodes)); when(mockNodeManager.getNodeStat(anyObject())) .thenReturn(new SCMNodeMetric(100L, 0L, 100L)); when(mockNodeManager.getNodeStat(datanodes.get(2))) .thenReturn(new SCMNodeMetric(100L, 90L, 10L)); when(mockNodeManager.getNodeStat(datanodes.get(3))) .thenReturn(new SCMNodeMetric(100L, 80L, 20L)); when(mockNodeManager.getNodeStat(datanodes.get(4))) .thenReturn(new SCMNodeMetric(100L, 70L, 30L)); SCMContainerPlacementCapacity scmContainerPlacementRandom = new SCMContainerPlacementCapacity(mockNodeManager, conf, null, true, null); List<DatanodeDetails> existingNodes = new ArrayList<>(); existingNodes.add(datanodes.get(0)); existingNodes.add(datanodes.get(1)); Map<DatanodeDetails, Integer> selectedCount = new HashMap<>(); for (DatanodeDetails datanode : datanodes) { selectedCount.put(datanode, 0); } for (int i = 0; i < 1000; i++) { List<DatanodeDetails> datanodeDetails = scmContainerPlacementRandom .chooseDatanodes(existingNodes, null, 1, 15); Assert.assertEquals(1, datanodeDetails.size()); DatanodeDetails datanode0Details = datanodeDetails.get(0); Assert.assertNotEquals( "Datanode 0 should not been selected: excluded by parameter", datanodes.get(0), datanode0Details); Assert.assertNotEquals( "Datanode 1 should not been selected: excluded by parameter", datanodes.get(1), datanode0Details); Assert.assertNotEquals( "Datanode 2 should not been selected: not enough space there", datanodes.get(2), datanode0Details); selectedCount .put(datanode0Details, selectedCount.get(datanode0Details) + 1); } Assert.assertTrue(selectedCount.get(datanodes.get(3)) > selectedCount .get(datanodes.get(6))); Assert.assertTrue(selectedCount.get(datanodes.get(4)) > selectedCount .get(datanodes.get(6))); }