use of org.apache.hadoop.hdds.scm.container.ContainerManager in project ozone by apache.
the class TestSCMMXBean method testSCMContainerStateCount.
@Test
public void testSCMContainerStateCount() throws Exception {
ObjectName bean = new ObjectName("Hadoop:service=StorageContainerManager," + "name=StorageContainerManagerInfo," + "component=ServerRuntime");
TabularData data = (TabularData) mbs.getAttribute(bean, "ContainerStateCount");
Map<String, Integer> containerStateCount = scm.getContainerStateCount();
verifyEquals(data, containerStateCount);
// Do some changes like allocate containers and change the container states
ContainerManager scmContainerManager = scm.getContainerManager();
List<ContainerInfo> containerInfoList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
containerInfoList.add(scmContainerManager.allocateContainer(StandaloneReplicationConfig.getInstance(ReplicationFactor.ONE), UUID.randomUUID().toString()));
}
long containerID;
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
containerID = containerInfoList.get(i).getContainerID();
scmContainerManager.updateContainerState(ContainerID.valueOf(containerID), HddsProtos.LifeCycleEvent.FINALIZE);
assertEquals(scmContainerManager.getContainer(ContainerID.valueOf(containerID)).getState(), HddsProtos.LifeCycleState.CLOSING);
} else {
containerID = containerInfoList.get(i).getContainerID();
scmContainerManager.updateContainerState(ContainerID.valueOf(containerID), HddsProtos.LifeCycleEvent.FINALIZE);
scmContainerManager.updateContainerState(ContainerID.valueOf(containerID), HddsProtos.LifeCycleEvent.CLOSE);
assertEquals(scmContainerManager.getContainer(ContainerID.valueOf(containerID)).getState(), HddsProtos.LifeCycleState.CLOSED);
}
}
data = (TabularData) mbs.getAttribute(bean, "ContainerStateCount");
containerStateCount = scm.getContainerStateCount();
containerStateCount.forEach((k, v) -> {
if (k.equals(HddsProtos.LifeCycleState.CLOSING.toString())) {
assertEquals((int) v, 5);
} else if (k.equals(HddsProtos.LifeCycleState.CLOSED.toString())) {
assertEquals((int) v, 5);
} else {
// Remaining all container state count should be zero.
assertEquals((int) v, 0);
}
});
verifyEquals(data, containerStateCount);
}
Aggregations