long MB = KB * KB;
long GB = MB * KB;
// long TB = GB * KB;
-
+
/* some of these tests assume a host machine with RAM somewhere between 1GB and 1TB */
- // should return 100% of physical memory available (or 1TB whichever is smaller)
+ // should return 100% of physical memory available (or 1TB whichever is
+ // smaller)
long mem1 = MemorySetting.getMemorySetting("1T", "100");
long fullmem = mem1 + 512 * MB; // mem1 gets 512MB removed for the OS
long mem1b = MemorySetting.getMemorySetting("1t", "100");
assertTrue(mem1 > 1 * GB);
assertEquals(mem1, mem1b);
-
- // test 10% memory. Note 512MB is set as minimum, so adjust to 50% if less than
+
+ // test 10% memory. Note 512MB is set as minimum, so adjust to 50% if less
+ // than
// 5GB RAM.
String pc;
Float pcf;
pcf = 0.5f;
}
long mem1c = MemorySetting.getMemorySetting("1T", pc);
- assertTrue(mem1c > (pcf - 0.01) * fullmem && mem1c < (pcf + 0.01) * fullmem); // allowing for floating point errors
-
+ assertTrue(mem1c > (pcf - 0.01) * fullmem
+ && mem1c < (pcf + 0.01) * fullmem); // allowing for floating point
+ // errors
+
// should return 1GB (assuming host machine has more than 1GB RAM)
long mem2 = MemorySetting.getMemorySetting("1G", "100");
long mem2b = MemorySetting.getMemorySetting("1g", "100");
assertEquals(mem2, 1 * GB);
assertEquals(mem2, mem2b);
-
+
long mem3 = MemorySetting.getMemorySetting("1024M", "100");
long mem3b = MemorySetting.getMemorySetting("1024m", "100");
assertEquals(mem3, 1024 * MB);
assertEquals(mem3, mem3b);
-
+
long mem4 = MemorySetting.getMemorySetting("1048576K", "100");
long mem4b = MemorySetting.getMemorySetting("1048576k", "100");
assertEquals(mem4, 1048576 * KB);
assertEquals(mem7, 512 * MB);
// ensure enough memory for OS
- long mem8 = MemorySetting.getMemorySetting("2TB", "100"); // this should be short of 512MB
- long mem8b = MemorySetting.getMemorySetting("2TB", "50");
- assertEquals(mem8b * 2 - mem8, 512 * MB);
+ long mem8 = MemorySetting.getMemorySetting("2T", "100"); // this should be
+ // short of 512MB
+ long mem8b = MemorySetting.getMemorySetting("2T", "50");
+ // allow 10k leeway
+ long diff = mem8b * 2 - mem8;
+ assertTrue(512 * MB - 10 * KB < diff && diff < 512 * MB + 10 * KB);
+ // assertEquals(mem8b * 2 - mem8, 512 * MB);
}
}