001: /**
002: * Copyright (C) 2001-2004 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.runtime.basic;
018:
019: import org.objectweb.speedo.SpeedoTestHelper;
020: import org.objectweb.speedo.pobjects.basic.BasicA;
021: import org.objectweb.util.monolog.api.BasicLevel;
022:
023: import java.util.Calendar;
024: import java.util.Iterator;
025:
026: import javax.jdo.Extent;
027: import javax.jdo.PersistenceManager;
028:
029: /**
030: *
031: * @author S.Chassande-Barrioz
032: */
033: public class TestBigExtent extends SpeedoTestHelper {
034:
035: public TestBigExtent(String s) {
036: super (s);
037: }
038:
039: protected String getLoggerName() {
040: return LOG_NAME + ".rt.basic.TestBigExtent";
041: }
042:
043: public void testCreateObjects(int NBOBJ) {
044: logger.log(BasicLevel.WARN, "Creating " + NBOBJ
045: + " objects ...");
046: PersistenceManager pm = pmf.getPersistenceManager();
047: pm.currentTransaction().begin();
048: for (int i = 0; i < NBOBJ; i++) {
049: BasicA ba = new BasicA();
050: ba.writeF1("testBigExtent_" + NBOBJ);
051: pm.makePersistent(ba);
052: }
053: pm.currentTransaction().commit();
054: pm.evictAll();
055: pm.close();
056: }
057:
058: public void test1CreateObjects1000() {
059: testCreateObjects(1000);
060: }
061:
062: public void test2BigExtent() {
063: logger.log(BasicLevel.WARN, "Using the extent ...");
064: PersistenceManager pm = pmf.getPersistenceManager();
065: pm.evictAll();
066: long t = Calendar.getInstance().getTimeInMillis();
067: Extent e = pm.getExtent(BasicA.class, false);
068: Iterator it = e.iterator();
069: int i = 0;
070: while (it.hasNext()) {
071: BasicA ba = (BasicA) it.next();
072: logger.log(BasicLevel.DEBUG, ba.readF1());
073: }
074: e.closeAll();
075: pm.close();
076: t = Calendar.getInstance().getTimeInMillis() - t;
077: logger.log(BasicLevel.WARN, "Time: " + t + "ms");
078: }
079:
080: public void testRemoveObject(int NBOBJ) {
081: logger.log(BasicLevel.WARN, "Removing " + NBOBJ
082: + " objects ...");
083: PersistenceManager pm = pmf.getPersistenceManager();
084: pm.currentTransaction().begin();
085: Extent e = pm.getExtent(BasicA.class, false);
086: Iterator it = e.iterator();
087: int i = 0;
088: while (it.hasNext()) {
089: assertTrue("More object than expected, expected=" + NBOBJ
090: + ", found " + (i + 1), i < NBOBJ);
091: BasicA ba = (BasicA) it.next();
092: pm.deletePersistent(ba);
093: logger.log(BasicLevel.DEBUG, ba.readF1());
094: i++;
095: }
096: e.closeAll();
097: pm.currentTransaction().commit();
098: pm.close();
099: }
100:
101: public void test3RemoveObject1000() {
102: testRemoveObject(1000);
103: }
104: }
|