activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1518263 - in /activemq/trunk/activemq-client/src: main/java/org/apache/activemq/usage/MemoryUsage.java test/java/org/apache/activemq/usage/MemoryUsageTest.java
Date Wed, 28 Aug 2013 15:37:28 GMT
Author: gtully
Date: Wed Aug 28 15:37:28 2013
New Revision: 1518263

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

Modified:
    activemq/trunk/activemq-client/src/main/java/org/apache/activemq/usage/MemoryUsage.java
    activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java

Modified: activemq/trunk/activemq-client/src/main/java/org/apache/activemq/usage/MemoryUsage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/usage/MemoryUsage.java?rev=1518263&r1=1518262&r2=1518263&view=diff
==============================================================================
--- activemq/trunk/activemq-client/src/main/java/org/apache/activemq/usage/MemoryUsage.java
(original)
+++ activemq/trunk/activemq-client/src/main/java/org/apache/activemq/usage/MemoryUsage.java
Wed Aug 28 15:37:28 2013
@@ -205,4 +205,10 @@ public class MemoryUsage extends Usage<M
     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));
+        }
+    }
 }

Modified: activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java?rev=1518263&r1=1518262&r2=1518263&view=diff
==============================================================================
--- activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java
(original)
+++ activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java
Wed Aug 28 15:37:28 2013
@@ -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();



Mime
View raw message