Updated Branches: refs/heads/trunk a33951d2e -> 839b154cd
https://issues.apache.org/jira/browse/AMQ-4798 - limits are still high but there is no loss in percision so that chidren now match parent and there is no info message Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/839b154c Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/839b154c Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/839b154c Branch: refs/heads/trunk Commit: 839b154cd24980f1c77fa89a37de42684f73d275 Parents: a33951d Author: gtully <[email protected]> Authored: Fri Oct 11 13:55:48 2013 +0100 Committer: gtully <[email protected]> Committed: Fri Oct 11 13:56:44 2013 +0100 ---------------------------------------------------------------------- .../java/org/apache/activemq/usage/Usage.java | 4 ++-- .../apache/activemq/usage/MemoryUsageTest.java | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/839b154c/activemq-client/src/main/java/org/apache/activemq/usage/Usage.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/main/java/org/apache/activemq/usage/Usage.java b/activemq-client/src/main/java/org/apache/activemq/usage/Usage.java index de26032..cfe7de2 100755 --- a/activemq-client/src/main/java/org/apache/activemq/usage/Usage.java +++ b/activemq-client/src/main/java/org/apache/activemq/usage/Usage.java @@ -61,7 +61,7 @@ public abstract class Usage<T extends Usage> implements Service { this.parent = parent; this.usagePortion = portion; if (parent != null) { - this.limiter.setLimit((long) (parent.getLimit() * portion)); + this.limiter.setLimit((long) (parent.getLimit() * (double)portion)); name = parent.name + ":" + name; } this.name = name; @@ -173,7 +173,7 @@ public abstract class Usage<T extends Usage> implements Service { if (usagePortion > 0 && parent != null) { usageLock.writeLock().lock(); try { - this.limiter.setLimit((long) (parent.getLimit() * usagePortion)); + this.limiter.setLimit((long) (parent.getLimit() * (double) usagePortion)); } finally { usageLock.writeLock().unlock(); } http://git-wip-us.apache.org/repos/asf/activemq/blob/839b154c/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java b/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java index 4c35663..b869939 100644 --- a/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java +++ b/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java @@ -41,7 +41,7 @@ public class MemoryUsageTest { underTest.start(); underTest.increaseUsage(1); assertEquals("usage is correct", 10, underTest.getPercentUsage()); - assertEquals("no new thread created withough listener or callback",activeThreadCount, Thread.activeCount()); + assertEquals("no new thread created without listener or callback",activeThreadCount, Thread.activeCount()); } @Test @@ -61,8 +61,8 @@ public class MemoryUsageTest { } }); underTest.increaseUsage(1); - assertTrue("listner was called", called.await(30, TimeUnit.SECONDS)); - assertTrue("listner called from another thread", !Thread.currentThread().toString().equals(listnerThreadNameHolder[0])); + assertTrue("listener was called", called.await(30, TimeUnit.SECONDS)); + assertTrue("listener called from another thread", !Thread.currentThread().toString().equals(listnerThreadNameHolder[0])); assertEquals("usage is correct", 10, underTest.getPercentUsage()); assertEquals("new thread created with listener", activeThreadCount + 1, Thread.activeCount()); } @@ -73,6 +73,16 @@ public class MemoryUsageTest { assertEquals("limit is half jvm limit", Math.round(Runtime.getRuntime().maxMemory() / 2.0), underTest.getLimit()); } + @Test + public void testParentPortion() throws Exception { + underTest.setLimit(1491035750); + MemoryUsage child = new MemoryUsage(underTest, "child", 1f); + assertEquals("limits are matched whole", underTest.getLimit(), child.getLimit()); + + child.setUsagePortion(1f); + assertEquals("limits are still matched whole", underTest.getLimit(), child.getLimit()); + } + @Before public void setUp() throws Exception { underTest = new MemoryUsage(); @@ -84,9 +94,9 @@ public class MemoryUsageTest { } }); underTest.setExecutor(this.executor); - + } - + @After public void tearDown() { assertNotNull(underTest);
