public void sizeAndPositioningTest1() throws Exception{
File testFileDir = new File(_testPath+"/testData/");
testFileDir.mkdirs();
File testFile = new File(testFileDir,SimpleAddTest.class.getSimpleName()+(_testCounter++)+".jdb");
testFile.delete();
JODBSessionContainer sessionContainer = getContainerForFile(testFile);
Object firstObject = new Object();
sessionContainer.set(firstObject);
sessionContainer.commit();
ObjectD testObjectD = new ObjectD();
testObjectD._obj0 = firstObject;
sessionContainer.set(testObjectD);
sessionContainer.commit();
//sessionContainer.printFileMap();
testObjectD._obj0 = null;
sessionContainer.set(testObjectD);
sessionContainer.commit();
//sessionContainer.printFileMap();
if(sessionContainer.getPersistenceStatistics(testObjectD).getTotalRecords()!=1){
throw new RuntimeException();
}
testObjectD._obj0 = firstObject;
sessionContainer.set(testObjectD);
sessionContainer.commit();
//sessionContainer.printFileMap();
if(sessionContainer.getPersistenceStatistics(testObjectD).getTotalRecords()!=1){
throw new RuntimeException();
}
testObjectD._obj1 = testObjectD;
sessionContainer.set(testObjectD);
sessionContainer.commit();
//sessionContainer.printFileMap();
if(sessionContainer.getPersistenceStatistics(testObjectD).getTotalRecords()!=2){
throw new RuntimeException();
}
testObjectD._member1 = 10;
sessionContainer.set(testObjectD);
sessionContainer.commit();
//sessionContainer.printFileMap();
if(sessionContainer.getPersistenceStatistics(testObjectD).getTotalRecords()!=2){
throw new RuntimeException();
}
testObjectD._obj0 = null;
sessionContainer.set(testObjectD);
sessionContainer.commit();
//sessionContainer.printFileMap();
if(sessionContainer.getPersistenceStatistics(testObjectD).getTotalRecords()!=1){
throw new RuntimeException();
}
testObjectD._obj1 = null;
sessionContainer.set(testObjectD);
sessionContainer.commit();
//sessionContainer.printFileMap();
if(sessionContainer.getPersistenceStatistics(testObjectD).getTotalRecords()!=1){
throw new RuntimeException();
}
testObjectD._obj0 = testObjectD._obj1 = testObjectD;
sessionContainer.set(testObjectD);
sessionContainer.commit();
//sessionContainer.printFileMap();
if(sessionContainer.getPersistenceStatistics(testObjectD).getTotalRecords()!=2){
throw new RuntimeException();
}
testObjectD._obj0 = testObjectD._obj1 = null;
sessionContainer.set(testObjectD);
sessionContainer.commit();
//sessionContainer.printFileMap();
if(sessionContainer.getPersistenceStatistics(testObjectD).getTotalRecords()!=1){
throw new RuntimeException();
}
List list = sessionContainer.getAllObjects();
if(list.size()!=2){
throw new IOException();
}
Object[] array = new Object[3];
array[0] = firstObject;
array[1] = firstObject;
sessionContainer.set(testObjectD);
sessionContainer.commit();
array[2] = array[2];
sessionContainer.set(array);
sessionContainer.commit();
//sessionContainer.printFileMap();
if(sessionContainer.getPersistenceStatistics(testObjectD).getTotalRecords()!=1){
throw new RuntimeException();
}
int inCache = sessionContainer.getCachedObjectsCount();
System.gc();
Thread.sleep(1000);
array = null;
System.gc();
Thread.sleep(1000);
if(inCache == sessionContainer.getCachedObjectsCount()){
throw new RuntimeException("test flow error");
}
//sessionContainer.printFileMap();
list = sessionContainer.getAllObjects();
for (int i = 0; i < list.size(); i++) {
Object obj = list.get(i);
if(obj.getClass().isArray()){
array = (Object[]) obj;
}
}
if(array[0]!=firstObject || array[1]!=firstObject || array[2]!=null){
throw new RuntimeException();
}
array[2] = array;
sessionContainer.set(array);
sessionContainer.commit();
//sessionContainer.printFileMap();
if(sessionContainer.getPersistenceStatistics(testObjectD).getTotalRecords()!=1){
throw new RuntimeException();
}
inCache = sessionContainer.getCachedObjectsCount();
System.gc();
Thread.sleep(500);
array = null;
System.gc();
Thread.sleep(500);
if(inCache == sessionContainer.getCachedObjectsCount()){
throw new RuntimeException("test flow error");
}
list = sessionContainer.getAllObjects();
for (int i = 0; i < list.size(); i++) {
Object obj = list.get(i);
if(obj.getClass().isArray()){
array = (Object[]) obj;
}
}
if(array[0]!=firstObject || array[1]!=firstObject || array[2]!=array){
throw new RuntimeException();
}
sessionContainer.close();
}