public class SoftCacheTest {
@Test
public void shouldDemonstrateObjectsBeingCollectedAsNeeded() throws Exception {
final int N = 3000000;
SoftCache cache = new SoftCache(new PerpetualCache("default"));
for (int i = 0; i < N; i++) {
byte[] array = new byte[5001]; //waste a bunch of memory
array[5000] = 1;
cache.putObject(i, array);
Object value = cache.getObject(i);
if (cache.getSize() < i + 1) {
//System.out.println("Cache exceeded with " + (i + 1) + " entries.");
break;
}
}
assertTrue(cache.getSize() < N);
}