// final int maxObjectState = 1000 * 5;
// win seven
final int maxObjectState = 100 * 1000;
saveCount = 0;
final int max = 100000;
final IExclusiveDataAccessSession session = filePersistence
.createExclusiveDataAccessSession();
session.open();
List<Integer> bigList;
final IInstanceFactory instanceFactory = session.getInstanceFactory();
bigList = PLinkedList.newInstance(instanceFactory);
assertTrue("must be a proxy", ProxyManager2.isProxyOrEnhanced(bigList));
// instance, proxy attached to persistence
int count;
for (count = 0; count < 5; count++) {
final int value = aValue(count);
saveDone = false;
bigList.add(value); // this not make bigList growing in memory
// because of auto save
assertTrue("must save", saveDone);
}
filePersistence.autoSaveSetup(1000);
for (; count < max; count++) {
final int value = aValue(count);
saveDone = false;
bigList.add(value); // this not make bigList growing in memory
if (saveDone) {
assertTrue("must be unloaded, count=" + count,
ProxyManager2.isUnloaded(bigList));
if (LOGGER.debugEnabled) {
final String stateMessage = HelperTestHugeList
.objectState(filePersistence);
LOGGER.debug(stateMessage);
}
final int numberOfObjectState = filePersistence
.getNumberOfObjectState();
assertTrue("too much object state " + numberOfObjectState
+ ", count #" + count,
numberOfObjectState < maxObjectState);
}
}
session.save();
assertFalse("must not be loaded",
ProxyManager2.proxiedObjectIsLoaded(bigList));
LOGGER.debug("--- save count " + saveCount);// NOPMD
LOGGER.debug("--- set object ---");// NOPMD
session.setObject("myBigList", bigList);
LOGGER.debug("--- save ---");// NOPMD
bigList = null; // NOPMD no more reference the big list
session.save(); // after this the garbage collector can free memory
// of
// the big list
LOGGER.debug("--- iterate ---");// NOPMD
bigList = (List<Integer>) session.getObject("myBigList"); // witchery
// of
// lazy load
// : all the
// big list
// is not
// loaded in
// memory
count = 0;
for (final int value : bigList) {
doSomething(value);
count++;
}
LOGGER.debug("--- clone ---");// NOPMD
final Object bigListClone = ((PLinkedList<Integer>) bigList).clone();
session.setObject("myClone", bigListClone);
session.close();
assertTrue("object state map never cleaned", decreaseCount > 0);
LOGGER.debug("object state map decrease count=" + decreaseCount);
}