From 67c81a8b189a9002b61a60488d787cee9b6b6579 Mon Sep 17 00:00:00 2001 From: Anu Engineer Date: Sat, 6 May 2017 09:44:07 -0700 Subject: [PATCH] HDFS-11761. Ozone: Get container report should only report closed containers. Contributed by Weiwei Yang. --- .../common/impl/TestContainerPersistence.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java index 110093a1475..7e783308388 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/container/common/impl/TestContainerPersistence.java @@ -256,6 +256,35 @@ public class TestContainerPersistence { .containsKey(containerName1)); } + @Test + public void testGetContainerReports() throws Exception{ + final int count = 10; + List containerNames = new ArrayList(); + + for (int i = 0; i < count; i++) { + String containerName = OzoneUtils.getRequestID(); + ContainerData data = new ContainerData(containerName); + containerManager.createContainer(createSingleNodePipeline(containerName), + data); + + // Close a bunch of containers. + // Put closed container names to a list. + if (i%3 == 0) { + containerManager.closeContainer(containerName); + containerNames.add(containerName); + } + } + + // The container report only returns reports of closed containers. + List reports = containerManager.getContainerReports(); + Assert.assertEquals(4, reports.size()); + for(ContainerData report : reports) { + String actualName = report.getContainerName(); + Assert.assertTrue(containerNames.remove(actualName)); + } + Assert.assertTrue(containerNames.isEmpty()); + } + /** * This test creates 1000 containers and reads them back 5 containers at a * time and verifies that we did get back all containers.