KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > BindFileSize


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.test;
22
23 public class BindFileSize {
24     
25     static final int LENGTH = 10000;
26     
27     String JavaDoc foo;
28     
29     public BindFileSize(){
30     }
31     
32     public BindFileSize(int length){
33         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(length);
34         for (int i = 0; i < length; i++) {
35             sb.append("g");
36         }
37         this.foo = sb.toString();
38     }
39     
40     public void store(){
41         Test.deleteAllInstances(this);
42         Test.store(new BindFileSize(LENGTH));
43     }
44     
45     public void testGrowth(){
46         int call = 0;
47         
48         Test.reOpen();
49         
50         BindFileSize bfs = (BindFileSize)Test.getOne(this);
51         long id = Test.objectContainer().getID(bfs);
52         for (int i = 0; i < 12; i++) {
53             bfs = new BindFileSize(LENGTH);
54             Test.objectContainer().bind(bfs, id);
55             Test.objectContainer().set(bfs);
56             Test.commit();
57             checkFileSize(call++);
58             Test.reOpen();
59         }
60     }
61     
62     private void checkFileSize(int call){
63         if(Test.canCheckFileSize()){
64             int newFileLength = Test.fileLength();
65             
66             // Interesting for manual tests:
67
// System.out.println(newFileLength);
68

69             if(call == 6){
70                 // consistency reached, start testing
71
jumps = 0;
72                 fileLength = newFileLength;
73             }else if(call > 6){
74                 if(newFileLength > fileLength){
75                     if(jumps < 4){
76                         fileLength = newFileLength;
77                         jumps ++;
78                         // allow two further steps in size
79
// may be necessary for commit space extension
80
}else{
81                         // now we want constant behaviour
82
Test.error();
83                     }
84                 }
85             }
86         }
87     }
88     
89     private static transient int fileLength;
90     private static transient int jumps;
91
92
93
94 }
95
Popular Tags