mirror of https://github.com/apache/activemq.git
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:
parent
a33951d2eb
commit
839b154cd2
|
@ -61,7 +61,7 @@ public abstract class Usage<T extends Usage> implements Service {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.usagePortion = portion;
|
this.usagePortion = portion;
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
this.limiter.setLimit((long) (parent.getLimit() * portion));
|
this.limiter.setLimit((long) (parent.getLimit() * (double)portion));
|
||||||
name = parent.name + ":" + name;
|
name = parent.name + ":" + name;
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -173,7 +173,7 @@ public abstract class Usage<T extends Usage> implements Service {
|
||||||
if (usagePortion > 0 && parent != null) {
|
if (usagePortion > 0 && parent != null) {
|
||||||
usageLock.writeLock().lock();
|
usageLock.writeLock().lock();
|
||||||
try {
|
try {
|
||||||
this.limiter.setLimit((long) (parent.getLimit() * usagePortion));
|
this.limiter.setLimit((long) (parent.getLimit() * (double) usagePortion));
|
||||||
} finally {
|
} finally {
|
||||||
usageLock.writeLock().unlock();
|
usageLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class MemoryUsageTest {
|
||||||
underTest.start();
|
underTest.start();
|
||||||
underTest.increaseUsage(1);
|
underTest.increaseUsage(1);
|
||||||
assertEquals("usage is correct", 10, underTest.getPercentUsage());
|
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
|
@Test
|
||||||
|
@ -61,8 +61,8 @@ public class MemoryUsageTest {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
underTest.increaseUsage(1);
|
underTest.increaseUsage(1);
|
||||||
assertTrue("listner was called", called.await(30, TimeUnit.SECONDS));
|
assertTrue("listener was called", called.await(30, TimeUnit.SECONDS));
|
||||||
assertTrue("listner called from another thread", !Thread.currentThread().toString().equals(listnerThreadNameHolder[0]));
|
assertTrue("listener called from another thread", !Thread.currentThread().toString().equals(listnerThreadNameHolder[0]));
|
||||||
assertEquals("usage is correct", 10, underTest.getPercentUsage());
|
assertEquals("usage is correct", 10, underTest.getPercentUsage());
|
||||||
assertEquals("new thread created with listener", activeThreadCount + 1, Thread.activeCount());
|
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());
|
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
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
underTest = new MemoryUsage();
|
underTest = new MemoryUsage();
|
||||||
|
@ -84,9 +94,9 @@ public class MemoryUsageTest {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
underTest.setExecutor(this.executor);
|
underTest.setExecutor(this.executor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
assertNotNull(underTest);
|
assertNotNull(underTest);
|
||||||
|
|
Loading…
Reference in New Issue