KickJava   Java API By Example, From Geeks To Geeks.

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


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.api.internal.SessionInternal;
31 import org.objectweb.jalisto.se.api.ClassDescription;
32 import org.objectweb.jalisto.se.JalistoFactory;
33 import org.objectweb.jalisto.se.impl.LogicalOid;
34 import org.objectweb.jalisto.se.impl.meta.type.MetaTypeFactory;
35
36 public class PopulateTestCase extends JalistoTestCase {
37     public PopulateTestCase() {
38     }
39
40     public PopulateTestCase(String JavaDoc name) {
41         super(name);
42     }
43
44     public static Test suite() {
45         JalistoTestSuite suite = new JalistoTestSuite();
46         PopulateTestCase tc = (PopulateTestCase) newTestCase(suite, new PopulateTestCase());
47
48         tc.define();
49         tc.cleanUp();
50
51         tc.populate(500); // should be 500 for the test suite validity
52

53         tc.eraseTest();
54
55 // tc.overheadFloids();
56

57         tc.finishTests();
58
59         return suite;
60     }
61
62     public void eraseTest() {
63         session.closeSession();
64         session.eraseStorage();
65         SessionInternal internal = (SessionInternal) session;
66         long[] floids = internal.getOidTable().getIdentityProvider().getFloidCounters();
67         for (int i = 0; i < floids.length; i++) {
68             assertEquals("must be null", 0, floids[i]);
69         }
70         short clid = internal.getOidTable().getIdentityProvider().getClidCounter();
71         assertEquals("must be empty", -1, clid);
72         session.openSession();
73     }
74
75     public void overheadFloids() {
76         boolean continueTest = true;
77         String JavaDoc className = "java.Vomir";
78         Object JavaDoc[] data = new Object JavaDoc[2];
79         data[0] = "tralala";
80         data[1] = new Integer JavaDoc(465);
81         int c = 0;
82         while(continueTest) {
83             try {
84                 ClassDescription meta = JalistoFactory.createClassDescription(className+c);
85                 meta.addField(JalistoFactory.createFieldDescription("title", MetaTypeFactory.StringType));
86                 meta.addField(JalistoFactory.createFieldDescription("pages", MetaTypeFactory.IntegerType));
87                 session.defineClass(meta);
88                 tx.begin();
89                 LogicalOid floid = (LogicalOid) session.createObject(data, className+c);
90                 assertEquals("must be equals", c, floid.getClid());
91                 assertEquals("must be equals", 0, floid.getInstanceNumber());
92                 assertTrue("must be > 0, c = "+c, floid.getFloidAsLong() >= 0);
93                 tx.commit();
94             } catch (Exception JavaDoc e) {
95                 continueTest = false;
96                 System.out.println("c = "+c);
97                 System.out.println(e.getMessage());
98             }
99             if ((c % 100) == 0) {
100                 System.out.println("c = "+c);
101             }
102             c++;
103         }
104     }
105
106     /**
107      * ***********************************************************************************
108      */

109
110     public void define() {
111         super.initSession(false);
112         super.define(Book.getMetaDescription());
113     }
114
115     public void cleanUp() {
116         super.cleanUp(Book.class);
117     }
118
119     public void populate(int nbr) {
120         super.populate(nbr);
121     }
122
123     public void finishTests() {
124         super.finishTests();
125     }
126 }
127
Popular Tags