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

    https://github.com/apache/brooklyn-server/pull/331#discussion_r80439379
  
    --- 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 --
    
    if it fails because something else has leaked memory that would also be 
good to know -- let's watch and see


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