BobWithSerializeMethod.unshared = false;
/*
* creation of object graph:
* BobWithSerializeMethod->Bob1->Bob2,BobWithSerializeMethod->Integer
*/
BobWithSerializeMethod bobContainer = new BobWithSerializeMethod();
Bob1 bob1 = new Bob1();
bobContainer.setObject1(bob1);
bobContainer.setNotPrimitiveValue(Integer.valueOf(10));
Bob2 bob2 = new Bob2();
bob1.setBob2(bob2);
store.setRoot(bobContainer);
store.save(false, false);
Map<DataRecordIdentifier, String> map = objectClassMap(new DataRecordIdentifier[] {});
objectIoManager.clearObjectState();
final String links1 = links(map);
// objectIoManager.clearObjectState();
// heapRecordableManager.clear();
logger.debug("initial save");
/*
* assert garbage information after initial creation:
* BobWithSerializeMethod->Bob1->Bob2,BobWithSerializeMethod->Integer
*/
/*
* BobWithSerializeMethod->Integer: no data record for basic
*/
String expectedLinks = sortString(
/**/"StoreRoot4 -> BobWithSerializeMethod\n" +
/**/"BobWithSerializeMethod -> Bob1\n" +
/**/"Bob1 -> Bob2\n");
assertEquals("not expected link", expectedLinks, links1);
/* number of to garbage */
int numberToGarbage = toGarbageRecordManager.getNumberOfToGarbage();
assertEquals("must not have object to garbage", 0, numberToGarbage);
/* number of garbage candidate */
int numberOfGarbageCandidate = garbageCandidateRecordManager
.getNumberOfGarbageCandidate();
assertEquals(MUST_NOT_HAVE_OBJECT_MARKED_GARBAGE_CANDIDATE, 0,
numberOfGarbageCandidate);
/* number of class name definition */
final int initialNumberOfClassDef = classNameManager
.getNumberOfClassDef();
/* number of to visit */
final int numberOfToVisit = toVisitRecordManager.getNumberOfToVisit();
assertEquals(0, numberOfToVisit);
/* number of visited */
int numberOfVisited = visitedRecordManager.getNumberOfVisited();
assertEquals(0, numberOfVisited);
/* all data record */
final int initialNumberOfDataRecord = dataManager
.getNumberOfDataRecord();
/*
* read, check data record identifier, detach object, save
*/
bobContainer = (BobWithSerializeMethod) store.readAndGetRoot();
// x = store.getObjectIOManager().getObjectAndPersistInfoOfObject(
// bobContainer);
final DataRecordIdentifier idBobContainer = store
.getDataRecordIdentifierAssociatedToObject(bobContainer);
logger.debug("id bob container " + idBobContainer);
assertNotNull("bobContainer must have associated data record",
idBobContainer);
bob1 = (Bob1) bobContainer.getObject1();
final DataRecordIdentifier idBob1 = store
.getDataRecordIdentifierAssociatedToObject(bob1);
logger.debug("id bob1 " + idBob1);
assertNotNull("bob1 must have associated data record", idBob1);
bob2 = bob1.getBob2();
final DataRecordIdentifier idBob2 = store
.getDataRecordIdentifierAssociatedToObject(bob2);
logger.debug("id bob2 " + idBob2);
assertNotNull("bob2 must have associated data record", idBob2);
assertDataRecord(new DataRecordIdentifier[] {
/**/StoreForTest.IDENTIFIER_FOR_STORE_HEADER,/* store header */
/**/StoreForTest.IDENTIFIER_FOR_ROOT,/* root record */
/**/idBobContainer,/**/
/**/idBob1,/**/
/**/idBob2, /**/
// /**/idNotPrimitive /**/
}, new DataRecordIdentifier[] {});
/*
* break BobWithSerializeMethod->Bob1 on
* BobWithSerializeMethod->Bob1->Bob2,BobWithSerializeMethod->Integer
*/
/* id1 must be to garbage */
bobContainer.setObject1(null);
store.save(false, false);
map = objectClassMap(new DataRecordIdentifier[] { idBob1 });
objectIoManager.clearObjectState();
final String links2 = links(map);
logAllDataIdentifier();
logger.debug("bob1 detached from bobContainer");
/*
* assert garbage information after detaching object
*/
expectedLinks = sortString(
/**/"StoreRoot4 -> BobWithSerializeMethod\n" +
/**/"Bob1 -> Bob2\n");
assertEquals("not expected link", expectedLinks, links2);
String deleted = deleteLink(links1, links2);
expectedLinks =
/**/"BobWithSerializeMethod -> Bob1\n";
assertEquals("not deleted expected", expectedLinks, deleted);
/* number of to garbage */
numberToGarbage = toGarbageRecordManager.getNumberOfToGarbage();
assertEquals("must have object to garbage: bob1", 1, numberToGarbage);
assertTrue("bob1 must be to garbage",
toGarbageRecordManager.containsToGarbage(idBob1));
/* number of garbage candidate */
numberOfGarbageCandidate = garbageCandidateRecordManager
.getNumberOfGarbageCandidate();
// assertEquals(MUST_NOT_HAVE_OBJECT_MARKED_GARBAGE_CANDIDATE, 0,
// numberOfGarbageCandidate);
assertEquals(1, numberOfGarbageCandidate);
assertTrue(garbageCandidateRecordManager.containsCandidate(idBob2));
/* number of class name definition */
final int numberOfClassDef = classNameManager.getNumberOfClassDef();
assertEquals(initialNumberOfClassDef, numberOfClassDef);
/* number of to visit */
numberOfVisited = toVisitRecordManager.getNumberOfToVisit();
assertEquals(0, numberOfToVisit);
/* number of visited */
numberOfVisited = visitedRecordManager.getNumberOfVisited();
assertEquals(0, numberOfVisited);
/* all data record */
int numberOfDataRecord = dataManager.getNumberOfDataRecord();
// assertEquals("number of data record must not change",
// initialNumberOfDataRecord, numberOfDataRecord);
/*
* do garbage collection: bo1 and bob2 must be deleted, idbob1->idbob2
* link must be removed
*/
garbageSweep();
logger.debug("garbaged");
logAllDataIdentifier();
final String links3 = links(map);
expectedLinks = sortString(
/**/"StoreRoot4 -> BobWithSerializeMethod\n");
assertEquals("not expected link", expectedLinks, links3);
numberToGarbage = toGarbageRecordManager.getNumberOfToGarbage();
assertEquals("no more to garbage", 0, numberToGarbage);
numberOfGarbageCandidate = garbageCandidateRecordManager
.getNumberOfGarbageCandidate();
assertEquals(MUST_NOT_HAVE_OBJECT_MARKED_GARBAGE_CANDIDATE, 0,
numberOfGarbageCandidate);
numberOfDataRecord = dataManager.getNumberOfDataRecord();
assertEquals(
/* decrease of 2 records for data, 2 records for link */
"number of data record must decrease",
initialNumberOfDataRecord - 2 - 2, numberOfDataRecord);
assertDataRecord(new DataRecordIdentifier[] {
/* expected */
/**/Store.IDENTIFIER_FOR_STORE_HEADER,/* store header */
/**/Store.IDENTIFIER_FOR_ROOT,/* root record */
/* unexpected */
/**/idBobContainer,/**/
// /**/idNotPrimitive /**/
}, new DataRecordIdentifier[] {
/**/idBob1,/**/
/**/idBob2 /**/
});
bobContainer = (BobWithSerializeMethod) store.readAndGetRoot();
/*
* break BobWithSerializeMethod->Integer this must change nothing
*/
bobContainer.setNotPrimitiveValue(null);
store.save(true, false);
// logAllDataIdentifier();
map = objectClassMap(new DataRecordIdentifier[] {});
objectIoManager.clearObjectState();
final String links4 = links(map);