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

This commit is contained in:
gtully 2013-10-11 13:55:48 +01:00
parent a33951d2eb
commit 839b154cd2
2 changed files with 17 additions and 7 deletions

View File

@ -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();
}

View File

@ -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);