KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > test > core > suite > StabilityTestCase


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.core.suite;
25
26 import junit.framework.Test;
27 import org.objectweb.jalisto.se.test.data.Book;
28 import org.objectweb.jalisto.se.test.workbench.JalistoTestCase;
29 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite;
30 import org.objectweb.jalisto.se.test.workbench.JalistoTimer;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.Random JavaDoc;
34
35 public class StabilityTestCase extends JalistoTestCase {
36
37     public StabilityTestCase() {
38     }
39
40     public StabilityTestCase(String JavaDoc name) {
41         super(name);
42     }
43
44     public static Test suite() {
45         JalistoTestSuite suite = new JalistoTestSuite();
46         StabilityTestCase tc = (StabilityTestCase) newTestCase(suite, new StabilityTestCase());
47
48         tc.define();
49         tc.cleanUp();
50         tc.populate(5000);
51         tc.stabilityTest(200, 10000);
52         tc.cleanUp();
53
54         return suite;
55     }
56
57     /**
58      * **************************************************************************************
59      */

60
61     public void populate(int nbr) {
62         tx.begin();
63         for (int i = 0; i < nbr; i++) {
64             oids.add(session.createObject(Book.newBook().toArray(), Book.class));
65         }
66         tx.commit();
67     }
68
69     public void stabilityTest(int nbrCreate, int nbrIt) {
70         Random JavaDoc random = new Random JavaDoc();
71         String JavaDoc timerName = "Stability test execution cycle";
72         JalistoTimer.createTimer(timerName);
73
74         for (int c = 0; c < nbrIt; c++) {
75             if ((c != 0) && ((c % 50) == 0)) {
76                 session.reorganize();
77                 JalistoTimer.summary();
78                 JalistoTimer.clean(timerName);
79             }
80
81             JalistoTimer.timerStart(timerName);
82             tx.begin();
83             for (int i = 0; i < nbrCreate; i++) {
84                 Object JavaDoc[] bookInArray = Book.newBook().toArray();
85                 Object JavaDoc oid = session.createObject(bookInArray, Book.class);
86                 oids.add(oid);
87             }
88             tx.commit();
89
90             tx.begin();
91             for (int i = 0; i < nbrCreate; i++) {
92                 int index = random.nextInt(oids.size());
93                 Object JavaDoc oid = oids.get(index);
94                 session.readObjectByOid(oid);
95             }
96             tx.commit();
97
98             tx.begin();
99             for (int i = 0; i < nbrCreate; i++) {
100                 int index = random.nextInt(oids.size());
101                 Object JavaDoc oid = oids.get(index);
102                 session.deleteObjectByOid(oid);
103                 oids.remove(index);
104             }
105             tx.commit();
106             JalistoTimer.timerStop(timerName, false);
107         }
108     }
109
110
111     private ArrayList JavaDoc oids = null;
112
113     /**
114      * ***********************************************************************************
115      */

116
117     public void define() {
118         super.initSession(false);
119         super.define(Book.getMetaDescription());
120     }
121
122     public void cleanUp() {
123         super.cleanUp(Book.class);
124     }
125 }
126
Popular Tags