KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > basic > TestBigExtent


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.runtime.basic;
19
20 import org.objectweb.speedo.SpeedoTestHelper;
21 import org.objectweb.speedo.pobjects.basic.BasicA;
22 import org.objectweb.util.monolog.api.BasicLevel;
23
24 import java.util.Calendar JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import javax.jdo.Extent;
28 import javax.jdo.PersistenceManager;
29
30 /**
31  *
32  * @author S.Chassande-Barrioz
33  */

34 public class TestBigExtent extends SpeedoTestHelper {
35
36     public TestBigExtent(String JavaDoc s) {
37         super(s);
38     }
39
40     protected String JavaDoc getLoggerName() {
41         return LOG_NAME + ".rt.basic.TestBigExtent";
42     }
43
44     public void testCreateObjects(int NBOBJ) {
45         logger.log(BasicLevel.WARN, "Creating " + NBOBJ + " objects ...");
46         PersistenceManager pm = pmf.getPersistenceManager();
47         pm.currentTransaction().begin();
48         for(int i=0; i<NBOBJ; i++) {
49             BasicA ba = new BasicA();
50             ba.writeF1("testBigExtent_" + NBOBJ);
51             pm.makePersistent(ba);
52         }
53         pm.currentTransaction().commit();
54         pm.evictAll();
55         pm.close();
56     }
57
58     public void test1CreateObjects1000() {
59         testCreateObjects(1000);
60     }
61
62     public void test2BigExtent() {
63         logger.log(BasicLevel.WARN, "Using the extent ...");
64         PersistenceManager pm = pmf.getPersistenceManager();
65         pm.evictAll();
66         long t = Calendar.getInstance().getTimeInMillis();
67         Extent e = pm.getExtent(BasicA.class, false);
68         Iterator JavaDoc it = e.iterator();
69         int i= 0;
70         while(it.hasNext()) {
71             BasicA ba = (BasicA) it.next();
72             logger.log(BasicLevel.DEBUG, ba.readF1());
73         }
74         e.closeAll();
75         pm.close();
76         t = Calendar.getInstance().getTimeInMillis() - t;
77         logger.log(BasicLevel.WARN, "Time: " + t + "ms");
78     }
79
80     public void testRemoveObject(int NBOBJ) {
81         logger.log(BasicLevel.WARN, "Removing " + NBOBJ + " objects ...");
82         PersistenceManager pm = pmf.getPersistenceManager();
83         pm.currentTransaction().begin();
84         Extent e = pm.getExtent(BasicA.class, false);
85         Iterator JavaDoc it = e.iterator();
86         int i= 0;
87         while(it.hasNext()) {
88             assertTrue("More object than expected, expected="
89                 + NBOBJ + ", found " + (i + 1), i < NBOBJ);
90             BasicA ba = (BasicA) it.next();
91             pm.deletePersistent(ba);
92             logger.log(BasicLevel.DEBUG, ba.readF1());
93             i++;
94         }
95         e.closeAll();
96         pm.currentTransaction().commit();
97         pm.close();
98     }
99
100     public void test3RemoveObject1000() {
101         testRemoveObject(1000);
102     }
103 }
104
Popular Tags