KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.Test;
27 import org.objectweb.jalisto.se.api.ClassDescription;
28 import org.objectweb.jalisto.se.api.query.Query;
29 import org.objectweb.jalisto.se.api.query.Constraint;
30 import org.objectweb.jalisto.se.test.data.BookWithAuthor;
31 import org.objectweb.jalisto.se.test.workbench.JalistoTestCase;
32 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite;
33 import org.objectweb.jalisto.se.test.workbench.JalistoTimer;
34
35 public class EvolutionTestCase extends JalistoTestCase {
36     public EvolutionTestCase() {
37     }
38
39     public EvolutionTestCase(String JavaDoc name) {
40         super(name);
41     }
42
43     public static Test suite() {
44         JalistoTestSuite suite = new JalistoTestSuite();
45         EvolutionTestCase tc = (EvolutionTestCase) newTestCase(suite, new EvolutionTestCase());
46
47         tc.initSession();
48         tc.define(BookWithAuthor.getMetaDescription());
49
50         tc.evolutionTest(50);
51
52         return suite;
53     }
54
55     /**
56      * **************************************************************************************
57      */

58
59     public void evolutionTest(int nbrExecution) {
60         int[] intValues = {1000, 5000, 10000, 20000};
61         String JavaDoc title1 = BookWithAuthor.titles[0];
62         String JavaDoc title2 = BookWithAuthor.titles[1];
63
64         Query query1 = queryManager.query();
65         query1.constrain(BookWithAuthor.class);
66         query1.descend("title").constrain(title1).equal();
67
68         Query query2 = queryManager.query();
69         query2.constrain(BookWithAuthor.class);
70         Constraint c1 = query2.descend("title").constrain(title1).equal();
71         Constraint c2 = query2.descend("title").constrain(title2).equal();
72         c1.or(c2);
73
74         Query[] queries = {query1, query2};
75
76         float[][] resultTimes = new float[intValues.length][queries.length];
77
78         for (int i = 0; i < intValues.length; i++) {
79             for (int j = 0; j < queries.length; j++) {
80                 cleanUp(BookWithAuthor.class);
81                 populateBookWithAuthor(intValues[i]);
82
83                 for (int k = 0; k < nbrExecution; k++) {
84                     JalistoTimer.timerStart("evolutionTest");
85                     tx.begin();
86                     queries[j].execute();
87                     tx.commit();
88                     JalistoTimer.timerStop("evolutionTest", false);
89                 }
90                 resultTimes[i][j] = JalistoTimer.getAverage("evolutionTest");
91                 JalistoTimer.clean("evolutionTest");
92             }
93         }
94
95         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
96         for (int i = 0; i < resultTimes.length; i++) {
97             sb.append(intValues[i]).append(" : ");
98             float[] f = resultTimes[i];
99             for (int j = 0; j < f.length; j++) {
100                 sb.append(String.valueOf(f[j]) + " \t");
101             }
102             sb.append("\n");
103         }
104
105         System.out.println(sb.toString());
106
107         cleanUp(BookWithAuthor.class);
108     }
109
110
111     /**
112      * ********************************************************************************
113      */

114
115     public void initSession() {
116         super.initSession(false);
117     }
118
119     public void define(ClassDescription classDescription) {
120         super.define(classDescription);
121     }
122 }
123
Popular Tags