jojochuang commented on code in PR #5069:
URL: https://github.com/apache/hadoop/pull/5069#discussion_r1005012357


##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java:
##########
@@ -1410,4 +1410,49 @@ public void testOfflineImageViewerForECPolicies() throws 
Exception {
       }
     }
   }
+
+  /**
+   * Tests that ReverseXML processor doesn't accept XML files with the 
CacheManagerSection contains pool or directive tag
+   */
+  @Test
+  public void testReverseXmlWithCacheManagerSection() throws Throwable {
+    File imageXml = new File(tempDir, "imageXml.xml");
+    PrintWriter writer = new PrintWriter(imageXml, "UTF-8");
+    try {
+      writer.println("<?xml version=\"1.0\"?>");
+      writer.println("<fsimage>");
+      writer.println("<version>");
+      writer.println(String.format("<layoutVersion>%d</layoutVersion>",
+          NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION));
+      writer.println("<onDiskVersion>1</onDiskVersion>");
+      writer.println("<oivRevision>" +
+          "545bbef596c06af1c3c8dca1ce29096a64608478</oivRevision>");
+      writer.println("</version>");
+
+      writer.println("<CacheManagerSection>");
+      writer.println("<nextDirectiveId>1</nextDirectiveId>");
+      writer.println("<numDirectives>0</numDirectives>");
+      writer.println("<numPools>1</numPools>");
+
+      writer.println("<pool>");
+      writer.println("<poolName>0</poolName>");
+      writer.println("<ownerName>1</ownerName>");
+      writer.println("<groupName>2</groupName>");
+      writer.println("<mode>3</mode>");
+      writer.println("<limit>4</limit>");
+      writer.println("<maxRelativeExpiry>455545555</maxRelativeExpiry>");
+      writer.println("</pool>");
+      writer.println("</CacheManagerSection>");
+      writer.println("</fsimage>");
+    } finally {
+      writer.close();
+    }
+    try {
+      OfflineImageReconstructor.run(imageXml.getAbsolutePath(),
+          imageXml.getAbsolutePath() + ".out");
+      Assert.fail("missing some tags in pool filed");
+    } catch (Throwable t) {
+      GenericTestUtils.assertExceptionContains("missing some tags in pool 
filed", t);
+    }

Review Comment:
   This assertion logic looks super convoluted.
   ```suggestion
       OfflineImageReconstructor.run(imageXml.getAbsolutePath(),
           imageXml.getAbsolutePath() + ".out");
   ```



##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java:
##########
@@ -1410,4 +1410,49 @@ public void testOfflineImageViewerForECPolicies() throws 
Exception {
       }
     }
   }
+
+  /**
+   * Tests that ReverseXML processor doesn't accept XML files with the 
CacheManagerSection contains pool or directive tag
+   */
+  @Test
+  public void testReverseXmlWithCacheManagerSection() throws Throwable {
+    File imageXml = new File(tempDir, "imageXml.xml");
+    PrintWriter writer = new PrintWriter(imageXml, "UTF-8");
+    try {

Review Comment:
   ```suggestion
       try (PrintWriter writer = new PrintWriter(imageXml, "UTF-8")) {
   ```



##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java:
##########
@@ -1410,4 +1410,49 @@ public void testOfflineImageViewerForECPolicies() throws 
Exception {
       }
     }
   }
+
+  /**
+   * Tests that ReverseXML processor doesn't accept XML files with the 
CacheManagerSection contains pool or directive tag
+   */
+  @Test
+  public void testReverseXmlWithCacheManagerSection() throws Throwable {
+    File imageXml = new File(tempDir, "imageXml.xml");
+    PrintWriter writer = new PrintWriter(imageXml, "UTF-8");
+    try {
+      writer.println("<?xml version=\"1.0\"?>");
+      writer.println("<fsimage>");
+      writer.println("<version>");
+      writer.println(String.format("<layoutVersion>%d</layoutVersion>",
+          NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION));
+      writer.println("<onDiskVersion>1</onDiskVersion>");
+      writer.println("<oivRevision>" +
+          "545bbef596c06af1c3c8dca1ce29096a64608478</oivRevision>");
+      writer.println("</version>");
+
+      writer.println("<CacheManagerSection>");
+      writer.println("<nextDirectiveId>1</nextDirectiveId>");
+      writer.println("<numDirectives>0</numDirectives>");
+      writer.println("<numPools>1</numPools>");
+
+      writer.println("<pool>");
+      writer.println("<poolName>0</poolName>");
+      writer.println("<ownerName>1</ownerName>");
+      writer.println("<groupName>2</groupName>");
+      writer.println("<mode>3</mode>");
+      writer.println("<limit>4</limit>");
+      writer.println("<maxRelativeExpiry>455545555</maxRelativeExpiry>");
+      writer.println("</pool>");
+      writer.println("</CacheManagerSection>");
+      writer.println("</fsimage>");
+    } finally {
+      writer.close();
+    }

Review Comment:
   ```suggestion
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to