https://issues.apache.org/jira/browse/AMQ-4482 - implement and test setPercentOfJvmHeap attribute on memory usage

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1518263 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2013-08-28 15:37:28 +00:00
parent f71e2fe21a
commit feb71c3c6e
2 changed files with 13 additions and 1 deletions

View File

@ -205,4 +205,10 @@ public class MemoryUsage extends Usage<MemoryUsage> {
public void setUsage(long usage) {
this.usage = usage;
}
public void setPercentOfJvmHeap(int percentOfJvmHeap) {
if (percentOfJvmHeap > 0) {
setLimit(Math.round(Runtime.getRuntime().maxMemory() * percentOfJvmHeap / 100.0));
}
}
}

View File

@ -66,7 +66,13 @@ public class MemoryUsageTest {
assertEquals("usage is correct", 10, underTest.getPercentUsage());
assertEquals("new thread created with listener", activeThreadCount + 1, Thread.activeCount());
}
@Test
public void testPercentOfJvmHeap() throws Exception {
underTest.setPercentOfJvmHeap(50);
assertEquals("limit is half jvm limit", Math.round(Runtime.getRuntime().maxMemory() / 2.0), underTest.getLimit());
}
@Before
public void setUp() throws Exception {
underTest = new MemoryUsage();