You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yacy_search_server/test/net/yacy/kelondro/util/MemoryControlTest.java

44 lines
1.2 KiB

package net.yacy.kelondro.util;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class MemoryControlTest {
final int onemb = 1024 * 1024;
/**
* Test of request method, of class MemoryControl.
*/
@Test
public void testRequest_StandardStrategy() {
MemoryControl.setStandardStrategy(true);
MemoryControl.setProperMbyte(24);
int memblock = onemb * 13; // memsize to allocate
int iterations = (int) MemoryControl.available() / memblock;
int arraysize = (int) MemoryControl.maxMemory() / memblock + 10;
byte[][] x = new byte[arraysize][];
int i = 0;
while (i < arraysize && MemoryControl.request(memblock, false)) {
x[i] = new byte[memblock];
// for realistic test produce some memory avail to GC
if (MemoryControl.request(memblock, false)) {
x[i] = new byte[memblock];
}
i++;
}
System.out.println("allocated " + i + " * " + memblock/onemb + " MB = " + i*memblock/onemb + " MB");
assertTrue(i >= iterations);
}
}