public void assertUsedMemoryLessThan(String event, long max) { noteUsedMemory(event); long nowUsed = usedMemory.peekLast(); if (nowUsed > max) { // aggressively try to force GC Time.sleep(Duration.ONE_SECOND); usedMemory.removeLast(); noteUsedMemory(event+" (extra GC)"); nowUsed = usedMemory.peekLast(); if (nowUsed > max) { Assert.fail("Too much memory used - "+ByteSizeStrings.java().apply(nowUsed)+" > max "+ByteSizeStrings.java().apply(max)); } } } public void assertUsedMemoryMaxDelta(String event, long deltaMegabytes) {
protected long noteUsedMemory(String message) { Time.sleep(Duration.millis(200)); for (HaMgmtNode n: nodes) { ((AbstractManagementContext)n.mgmt).getGarbageCollector().gcIteration(); } System.gc(); System.gc(); Time.sleep(Duration.millis(50)); System.gc(); System.gc(); long mem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); usedMemory.addLast(mem); log.info("Memory used - "+message+": "+ByteSizeStrings.java().apply(mem)); return mem; } public void assertUsedMemoryLessThan(String event, long max) {