KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > test > query > bench > IndexCostTestCase


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.test.query.bench;
25
26 import org.objectweb.jalisto.test.query.JalistoQueryTestCase;
27 import junit.framework.Test;
28 import org.objectweb.jalisto.se.api.ClassDescription;
29 import org.objectweb.jalisto.se.test.data.BookWithAuthor;
30 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite;
31 import org.objectweb.jalisto.se.test.workbench.JalistoTimer;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.Random JavaDoc;
35
36 public class IndexCostTestCase extends JalistoQueryTestCase {
37     static int call = 0;
38
39     public IndexCostTestCase() {
40     }
41
42     public IndexCostTestCase(String JavaDoc name) {
43         super(name);
44     }
45
46     public static Test suite() {
47         JalistoTestSuite suite = new JalistoTestSuite();
48         IndexCostTestCase tc = (IndexCostTestCase) newTestCase(suite, new IndexCostTestCase());
49
50         tc.initSession();
51         tc.define(BookWithAuthor.getMetaDescription());
52
53         tc.deleteIndex(BookWithAuthor.class, "title");
54         tc.cleanUp(BookWithAuthor.class);
55
56         tc.populateBookWithAuthor(5000);
57         tc.stabilityTest(200, 201);
58
59         tc.buildIndex(BookWithAuthor.class, "title");
60         tc.stabilityTest(200, 201);
61
62         tc.printIndex(BookWithAuthor.class, "title");
63
64         return suite;
65     }
66
67     /**
68      * **************************************************************************************
69      */

70
71     public void stabilityTest(int nbrCreate, int nbrIt) {
72         ArrayList JavaDoc oids = new ArrayList JavaDoc();
73         Random JavaDoc random = new Random JavaDoc();
74         String JavaDoc timerName = " time for call " + (call++);
75         String JavaDoc createName = "create" + timerName;
76         String JavaDoc deleteName = "delete" + timerName;
77         JalistoTimer.createTimer(createName);
78         JalistoTimer.createTimer(deleteName);
79
80         for (int c = 0; c < nbrIt; c++) {
81             if ((c != 0) && ((c % 100) == 0)) {
82                 session.reorganize();
83                 JalistoTimer.summary();
84                 JalistoTimer.clean(createName);
85                 JalistoTimer.clean(deleteName);
86             }
87
88             JalistoTimer.timerStart(createName);
89             tx.begin();
90             for (int i = 0; i < nbrCreate; i++) {
91                 Object JavaDoc[] bookInArray = BookWithAuthor.newBook().toArray();
92                 Object JavaDoc oid = session.createObject(bookInArray, BookWithAuthor.class);
93                 oids.add(oid);
94             }
95             tx.commit();
96             JalistoTimer.timerStop(createName, false);
97
98             JalistoTimer.timerStart(deleteName);
99             tx.begin();
100             for (int i = 0; i < nbrCreate; i++) {
101                 int index = random.nextInt(oids.size());
102                 Object JavaDoc oid = oids.get(index);
103                 session.deleteObjectByOid(oid);
104                 oids.remove(index);
105             }
106             tx.commit();
107             JalistoTimer.timerStop(deleteName, false);
108         }
109
110         JalistoTimer.removeTimer(createName);
111         JalistoTimer.removeTimer(deleteName);
112     }
113
114
115     /**
116      * ********************************************************************************
117      */

118
119     public void initSession() {
120         super.initSession(false);
121     }
122
123     public void define(ClassDescription classDescription) {
124         super.define(classDescription);
125     }
126
127     public void cleanUp(Class JavaDoc aClass) {
128         super.cleanUp(aClass);
129     }
130
131     public void populateBookWithAuthor(int nbr) {
132         super.populateBookWithAuthor(nbr);
133     }
134
135     public void buildIndex(Class JavaDoc aClass, String JavaDoc fieldName) {
136         super.buildIndex(aClass, fieldName);
137     }
138
139     public void deleteIndex(Class JavaDoc aClass, String JavaDoc fieldName) {
140         super.deleteIndex(aClass, fieldName);
141     }
142
143     public void printIndex(Class JavaDoc aClass, String JavaDoc fieldName) {
144         super.printIndex(aClass, fieldName);
145     }
146 }
147
Popular Tags