use of org.apache.hadoop.hdds.scm.container.MockNodeManager in project ozone by apache.
the class TestContainerBalancer method setup.
/**
* Sets up configuration values and creates a mock cluster.
*/
@Before
public void setup() throws SCMException, NodeNotFoundException {
conf = new OzoneConfiguration();
scm = Mockito.mock(StorageContainerManager.class);
containerManager = Mockito.mock(ContainerManager.class);
replicationManager = Mockito.mock(ReplicationManager.class);
balancerConfiguration = conf.getObject(ContainerBalancerConfiguration.class);
balancerConfiguration.setThreshold(10);
balancerConfiguration.setIterations(1);
balancerConfiguration.setMaxDatanodesPercentageToInvolvePerIteration(100);
balancerConfiguration.setMaxSizeToMovePerIteration(50 * OzoneConsts.GB);
balancerConfiguration.setMaxSizeEnteringTarget(50 * OzoneConsts.GB);
conf.setFromObject(balancerConfiguration);
GenericTestUtils.setLogLevel(ContainerBalancer.LOG, Level.DEBUG);
averageUtilization = createCluster();
mockNodeManager = new MockNodeManager(datanodeToContainersMap);
placementPolicy = ContainerPlacementPolicyFactory.getPolicy(conf, mockNodeManager, mockNodeManager.getClusterNetworkTopologyMap(), true, SCMContainerPlacementMetrics.create());
Mockito.when(replicationManager.isContainerReplicatingOrDeleting(Mockito.any(ContainerID.class))).thenReturn(false);
Mockito.when(replicationManager.move(Mockito.any(ContainerID.class), Mockito.any(DatanodeDetails.class), Mockito.any(DatanodeDetails.class))).thenReturn(CompletableFuture.completedFuture(ReplicationManager.MoveResult.COMPLETED));
when(containerManager.getContainerReplicas(Mockito.any(ContainerID.class))).thenAnswer(invocationOnMock -> {
ContainerID cid = (ContainerID) invocationOnMock.getArguments()[0];
return cidToReplicasMap.get(cid);
});
when(containerManager.getContainer(Mockito.any(ContainerID.class))).thenAnswer(invocationOnMock -> {
ContainerID cid = (ContainerID) invocationOnMock.getArguments()[0];
return cidToInfoMap.get(cid);
});
when(containerManager.getContainers()).thenReturn(new ArrayList<>(cidToInfoMap.values()));
when(scm.getScmNodeManager()).thenReturn(mockNodeManager);
when(scm.getContainerPlacementPolicy()).thenReturn(placementPolicy);
when(scm.getContainerManager()).thenReturn(containerManager);
when(scm.getReplicationManager()).thenReturn(replicationManager);
when(scm.getScmContext()).thenReturn(SCMContext.emptyContext());
when(scm.getClusterMap()).thenReturn(null);
when(scm.getEventQueue()).thenReturn(mock(EventPublisher.class));
when(scm.getConfiguration()).thenReturn(conf);
containerBalancer = new ContainerBalancer(scm);
}
Aggregations