LuciferYang commented on a change in pull request #33848:
URL: https://github.com/apache/spark/pull/33848#discussion_r696421330



##########
File path: 
common/network-shuffle/src/test/java/org/apache/spark/network/shuffle/ExternalShuffleBlockResolverSuite.java
##########
@@ -110,6 +118,48 @@ public void testSortShuffleBlocks() throws IOException {
     }
   }
 
+  @Test
+  public void testShuffleIndexCacheEvictionBehavior() throws IOException, 
ExecutionException {
+    Map<String, String> config = new HashMap<>();
+    String indexCacheSize = "8192m";
+    config.put("spark.shuffle.service.index.cache.size", indexCacheSize);
+    TransportConf transportConf = new TransportConf("shuffle", new 
MapConfigProvider(config));
+    ExternalShuffleBlockResolver resolver = new 
ExternalShuffleBlockResolver(transportConf, null);
+    resolver.registerExecutor("app0", "exec0", 
dataContext.createExecutorInfo(SORT_MANAGER));
+
+    LoadingCache<File, ShuffleIndexInformation> shuffleIndexCache = 
resolver.shuffleIndexCache;
+
+    // 8g -> 8589934592 bytes
+    long maximumWeight = JavaUtils.byteStringAsBytes(indexCacheSize);
+    int unitSize = 1048575;
+    // CacheBuilder.DEFAULT_CONCURRENCY_LEVEL
+    int concurrencyLevel = 4;
+    int totalGetCount = 16384;
+    // maxCacheCount is 8192
+    long maxCacheCount = maximumWeight / concurrencyLevel / unitSize * 
concurrencyLevel;
+    for (int i = 0; i < totalGetCount; i++) {
+      File indexFile = new File("shuffle_" + 0 + "_" + i + "_0.index");
+      ShuffleIndexInformation indexInfo = 
Mockito.mock(ShuffleIndexInformation.class);
+      Mockito.when(indexInfo.getSize()).thenReturn(unitSize);
+      shuffleIndexCache.get(indexFile, () -> indexInfo);
+    }
+
+    long totalWeight =
+      
shuffleIndexCache.asMap().values().stream().mapToLong(ShuffleIndexInformation::getSize).sum();
+    long size = shuffleIndexCache.size();
+    try{
+      Assert.assertTrue(size <= maxCacheCount);
+      Assert.assertTrue(totalWeight < maximumWeight);
+      fail("The tests code should not enter this line now.");

Review comment:
       Should enter line 153, but it won't now
   
   




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