tomscut commented on code in PR #4209:
URL: https://github.com/apache/hadoop/pull/4209#discussion_r1034187735


##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/server/TestJournaledEditsCache.java:
##########
@@ -221,6 +224,24 @@ public void testCacheMalformedInput() throws Exception {
     cache.retrieveEdits(-1, 10, new ArrayList<>());
   }
 
+  @Test
+  public void testCacheFraction() {
+    // Set dfs.journalnode.edit-cache-size.bytes.
+    Configuration config = new Configuration();
+    config.setInt(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_KEY, 1);
+    
config.setFloat(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_FRACTION_KEY, 
0.1f);
+    cache = new JournaledEditsCache(config);
+    assertEquals(1, cache.getCapacity(), 0.0);
+
+    // Don't set dfs.journalnode.edit-cache-size.bytes.
+    Configuration config1 = new Configuration();
+    
config1.setFloat(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_FRACTION_KEY, 
0.1f);
+    cache = new JournaledEditsCache(config1);
+    assertEquals(
+        memory * 
config1.getFloat(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_FRACTION_KEY, 
0.0f),
+        cache.getCapacity(), 0.0);

Review Comment:
   Because we compute `capacity` by `capacity = 
conf.getInt(DFSConfigKeys.DFS_JOURNALNODE_EDIT_CACHE_SIZE_KEY,
           (int) Runtime.getRuntime().maxMemory() * fraction)`. 
   
   The assert result will be:
   ```
   java.lang.AssertionError: 
   Expected :190893260
   Actual   :190893264
   ```
   
   So I will update to `assertEquals((int) (Runtime.getRuntime().maxMemory() * 
0.1f), cache.getCapacity())`.



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