Github user alasdairhodge commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/326#discussion_r20294956
--- Diff:
utils/common/src/test/java/brooklyn/util/javalang/MemoryUsageTrackerTest.java
---
@@ -20,35 +20,54 @@
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
+import brooklyn.test.Asserts;
import brooklyn.util.collections.MutableList;
import brooklyn.util.guava.Maybe;
import brooklyn.util.text.Strings;
public class MemoryUsageTrackerTest {
+ private static final Logger LOG =
LoggerFactory.getLogger(MemoryUsageTrackerTest.class);
+
@Test(groups="Integration")
public void testBigUsage() {
+ // Don't just use runtime.maxMemory()*2; javadoc says:
+ // If there is no inherent limit then the value
java.lang.Long.MAX_VALUE will be returned.
+ // Therefore cap at 10GB.
+ final long maxMemory = Math.min(Runtime.getRuntime().maxMemory(),
10*1024*1024*1024L);
+
List<Maybe<byte[]>> references = MutableList.of();
long created = 0;
- while (created < 2*Runtime.getRuntime().maxMemory()) {
- byte d[] = new byte[1000000];
+ while (created < 2*maxMemory) {
+ byte d[] = new byte[10*1000*1000];
--- End diff --
Nitpick: a named constant might be nice; `MAX_MEMORY_CAP`?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---