Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/331#discussion_r80226051
  
    --- Diff: 
utils/common/src/test/java/org/apache/brooklyn/util/javalang/MemoryUsageTrackerTest.java
 ---
    @@ -81,7 +81,39 @@ private long sizeOfActiveReferences(List<Maybe<byte[]>> 
references) {
             }
             return size;
         }
    -    
    +
    +    @Test(groups="Integration")
    +    public void testSoftUsageAndClearance() {
    +        long totalMemory = Runtime.getRuntime().totalMemory();
    +        long freeMemory = Runtime.getRuntime().freeMemory();
    +        
    +        List<Maybe<?>> dump = MutableList.of();
    +        Maybe<byte[]> first = Maybe.soft(new byte[1000*1000]);
    +        dump.add(first);
    +        for (int i=0; i<1000*1000; i++) {
    +            totalMemory = Runtime.getRuntime().totalMemory();
    +            freeMemory = Runtime.getRuntime().freeMemory();
    +            
    +            dump.add(Maybe.soft(new byte[1000*1000]));
    +            if (first.isAbsent()) break;
    +        }
    +        int cleared = 0;
    +        for (Maybe<?> m: dump) { if (m.isAbsent()) cleared++; }
    +        LOG.info("First soft reference cleared after "+dump.size()+" 1M 
blocks created; "+cleared+" of them cleared");
    +        
    +        Assert.assertTrue(1.0*freeMemory/totalMemory < 0.10, 
    +            "Should have had less than 10% free memory before clearance, 
had "+Strings.makeSizeString(freeMemory)+" / 
"+Strings.makeSizeString(totalMemory));
    +        
    +        LOG.info("Forcing memory eviction: "+
    +            MemoryUsageTracker.forceClearSoftReferences(100*1000, 
10*1000*1000));
    +        
    +        System.gc(); System.gc();
    +        totalMemory = Runtime.getRuntime().totalMemory();
    +        freeMemory = Runtime.getRuntime().freeMemory();
    +        Assert.assertTrue(1.0*freeMemory/totalMemory > 0.90, 
    --- End diff --
    
    Not convinced this is a safe assertion - if you run the entire suite of 
integration tests, will this definitely be true? Should we not make an 
assertion based on comparing the before-and-after free memory, to just ensure 
that the soft references have been removed?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to