KickJava   Java API By Example, From Geeks To Geeks.

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


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.Transaction;
28 import org.objectweb.jalisto.se.api.internal.SessionInternal;
29 import org.objectweb.jalisto.se.JalistoFactory;
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 import java.util.ArrayList JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.Random JavaDoc;
38
39 public class BenchMonoMultiQuery extends JalistoTestCase {
40     ArrayList JavaDoc oids = null;
41
42     public BenchMonoMultiQuery() {
43     }
44
45     public BenchMonoMultiQuery(String JavaDoc name) {
46         super(name);
47     }
48
49     public static Test suite() {
50         JalistoTestSuite suite = new JalistoTestSuite();
51         BenchMonoMultiQuery tc = (BenchMonoMultiQuery) newTestCase(suite, new BenchMonoMultiQuery());
52
53         tc.stabilityTest(true, "mono", 5000, 500, 2000);
54
55 // tc.stabilityTest(false, "multi", 5000, 200, 200);
56

57         return suite;
58     }
59
60     /**
61      * **************************************************************************************
62      */

63
64     public void stabilityTest(boolean isMono, String JavaDoc message, int nbrBook, int nbrAction, int nbrExecution) {
65         SessionInternal workingSession = null;
66
67         if (isMono) {
68             workingSession = (SessionInternal) JalistoFactory.getSession("jalisto-query.properties");
69             System.out.println("is mono : " + workingSession.getProperties().isMonoImplementation());
70         } else {
71             workingSession = (SessionInternal) JalistoFactory.getSession("jalisto-query-multi.properties");
72             System.out.println("is mono : " + workingSession.getProperties().isMonoImplementation());
73         }
74
75         Transaction workingTransaction = workingSession.currentTransaction();
76         workingSession.defineClass(BookWithAuthor.getMetaDescription());
77
78         oids = new ArrayList JavaDoc();
79
80         workingTransaction.begin();
81         for (int i = 0; i < nbrBook; i++) {
82             oids.add(workingSession.createObject(BookWithAuthor.newBook().toArray(), BookWithAuthor.class));
83         }
84         workingTransaction.commit();
85
86         Random JavaDoc random = new Random JavaDoc();
87         String JavaDoc createName = message + " : create time for " + nbrAction + " objects";
88         String JavaDoc readName = message + " : read time for " + nbrAction + " objects";
89         String JavaDoc updateName = message + " : update time for " + nbrAction + " objects";
90         String JavaDoc deleteName = message + " : delete time for " + nbrAction + " objects";
91         String JavaDoc extentName = message + " : get one extent for " + nbrAction + " objects";
92         JalistoTimer.createTimer(createName);
93         JalistoTimer.createTimer(readName);
94         JalistoTimer.createTimer(updateName);
95         JalistoTimer.createTimer(deleteName);
96         JalistoTimer.createTimer(extentName);
97
98         for (int c = 0; c < nbrExecution; c++) {
99             if ((c != 0) && ((c % 50) == 0)) {
100                 workingSession.reorganize();
101             }
102
103 // Timer.timerStart(createName);
104
// workingTransaction.begin();
105
// for (int i = 0; i < nbrAction; i++) {
106
// Object[] bookInArray = Book.newBook().toArray();
107
// Object oid = workingSession.createObject(bookInArray, Book.class);
108
// oids.add(oid);
109
// }
110
// workingTransaction.commit();
111
// Timer.timerStop(createName, false);
112

113             JalistoTimer.timerStart(readName);
114             workingTransaction.begin();
115             for (int i = 0; i < nbrAction; i++) {
116                 int index = random.nextInt(oids.size());
117                 Object JavaDoc oid = oids.get(index);
118                 workingSession.readObjectByOid(oid);
119             }
120             workingTransaction.commit();
121             JalistoTimer.timerStop(readName, false);
122
123 // Timer.timerStart(deleteName);
124
// workingTransaction.begin();
125
// for (int i = 0; i < nbrAction; i++) {
126
// int index = random.nextInt(oids.size());
127
// Object oid = oids.get(index);
128
// workingSession.deleteObjectByOid(oid);
129
// oids.remove(index);
130
// }
131
// workingTransaction.commit();
132
// Timer.timerStop(deleteName, false);
133

134 // Timer.timerStart(extentName);
135
// workingTransaction.begin();
136
// Iterator it = workingSession.getExtent(Book.class).iterator();
137
// while (it.hasNext()) {
138
// Timer.timerStart("pouet");
139
// workingSession.readObjectByOid(it.next());
140
// Timer.timerStop("pouet", false);
141
// }
142
// workingTransaction.commit();
143
// Timer.timerStop(extentName, false);
144
}
145
146         workingTransaction.begin();
147         Iterator JavaDoc extent = workingSession.getExtent(BookWithAuthor.class).readFully().iterator();
148         while (extent.hasNext()) {
149             workingSession.deleteObjectByOid(extent.next());
150         }
151         workingTransaction.commit();
152         workingSession.reorganize();
153
154         JalistoTimer.summary(createName);
155         JalistoTimer.summary(readName);
156         JalistoTimer.summary(updateName);
157         JalistoTimer.summary(deleteName);
158         JalistoTimer.summary(extentName);
159         JalistoTimer.summary("pouet");
160     }
161
162 }
163
Popular Tags