/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.objectweb.speedo.runtime.basic;
import org.objectweb.speedo.SpeedoTestHelper;
import org.objectweb.speedo.pobjects.basic.BasicA;
import org.objectweb.util.monolog.api.BasicLevel;
import java.util.Calendar;
import java.util.Iterator;
import javax.jdo.Extent;
import javax.jdo.PersistenceManager;
/**
*
* @author S.Chassande-Barrioz
*/
public class TestBigExtent extends SpeedoTestHelper {
public TestBigExtent(String s) {
super(s);
}
protected String getLoggerName() {
return LOG_NAME + ".rt.basic.TestBigExtent";
}
public void testCreateObjects(int NBOBJ) {
logger.log(BasicLevel.WARN, "Creating " + NBOBJ + " objects ...");
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
for(int i=0; i<NBOBJ; i++) {
BasicA ba = new BasicA();
ba.writeF1("testBigExtent_" + NBOBJ);
pm.makePersistent(ba);
}
pm.currentTransaction().commit();
pm.evictAll();
pm.close();
}
public void test1CreateObjects1000() {
testCreateObjects(1000);
}
public void test2BigExtent() {
logger.log(BasicLevel.WARN, "Using the extent ...");
PersistenceManager pm = pmf.getPersistenceManager();
pm.evictAll();
long t = Calendar.getInstance().getTimeInMillis();
Extent e = pm.getExtent(BasicA.class, false);
Iterator it = e.iterator();
int i= 0;
while(it.hasNext()) {
BasicA ba = (BasicA) it.next();
logger.log(BasicLevel.DEBUG, ba.readF1());
}
e.closeAll();
pm.close();
t = Calendar.getInstance().getTimeInMillis() - t;
logger.log(BasicLevel.WARN, "Time: " + t + "ms");
}
public void testRemoveObject(int NBOBJ) {
logger.log(BasicLevel.WARN, "Removing " + NBOBJ + " objects ...");
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
Extent e = pm.getExtent(BasicA.class, false);
Iterator it = e.iterator();
int i= 0;
while(it.hasNext()) {
assertTrue("More object than expected, expected="
+ NBOBJ + ", found " + (i + 1), i < NBOBJ);
BasicA ba = (BasicA) it.next();
pm.deletePersistent(ba);
logger.log(BasicLevel.DEBUG, ba.readF1());
i++;
}
e.closeAll();
pm.currentTransaction().commit();
pm.close();
}
public void test3RemoveObject1000() {
testRemoveObject(1000);
}
}