[ 
https://issues.apache.org/jira/browse/HDFS-16815?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17624068#comment-17624068
 ] 

ASF GitHub Bot commented on HDFS-16815:
---------------------------------------

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
       }
   ```





> Error occurred in processing CacheManagerSection for xml parsing fsimage
> ------------------------------------------------------------------------
>
>                 Key: HDFS-16815
>                 URL: https://issues.apache.org/jira/browse/HDFS-16815
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: hdfs
>            Reporter: MeiJing
>            Priority: Minor
>              Labels: pull-request-available
>         Attachments: image-2022-10-24-10-34-07-288.png, 
> image-2022-10-24-10-43-57-652.png, image-2022-10-24-10-44-51-234.png
>
>
> For  testing  OfflineImageReconstructor, we run a test method. There are some 
> bugs in the process of  CacheManagerSectionProcessor. 
>   !image-2022-10-24-10-34-07-288.png|width=536,height=582!
>                                                    Fig1 Test Method
> First, we write the test method as Fig1 to test CacheManagerSectionProcessor, 
> but the method throw a exception that shows "<pool> found without 
> <poolName>".  As Fig2 shows.
> !image-2022-10-24-10-43-57-652.png|width=528,height=53!
>                                                    Fig2  result of test 
> method 
> Second, we run the test method again when we solve the first bug. there is 
> another bug that shows "Expected tag end event for CacheManagerSection, but 
> got tag end event for pool". As Fig3 shows.
> !image-2022-10-24-10-44-51-234.png!
>                                                       Fig3 second result of 
> test method



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to