KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
24
25 public class PrimitiveArrayFileSize {
26     
27     Object JavaDoc arr;
28     
29     public void testSimpleLongInObject(){
30         int call = 0;
31         PrimitiveArrayFileSize pafs = new PrimitiveArrayFileSize();
32         for (int i = 0; i < 12; i++) {
33             pafs.arr = new long[100];
34             Test.store(pafs);
35             checkFileSize(call++);
36             Test.commit();
37             checkFileSize(call++);
38         }
39     }
40     
41     public void testLongWrapperInObject(){
42         int call = 0;
43         PrimitiveArrayFileSize pafs = new PrimitiveArrayFileSize();
44         for (int i = 0; i < 12; i++) {
45             pafs.arr = longWrapperArray();
46             Test.store(pafs);
47             checkFileSize(call++);
48             Test.commit();
49             checkFileSize(call++);
50         }
51     }
52     
53     public void testSimpleLongInHashMap(){
54         HashMap hm = new HashMap();
55         int call = 0;
56         for (int i = 0; i < 12; i++) {
57             long[] lll = new long[100];
58             lll[0] = 99999;
59             hm.put("test", lll);
60             Test.store(hm);
61             checkFileSize(call++);
62             Test.commit();
63             checkFileSize(call++);
64         }
65     }
66     
67     public void testLongWrapperInHashMap(){
68         HashMap hm = new HashMap();
69         int call = 0;
70         for (int i = 0; i < 12; i++) {
71             hm.put("test", longWrapperArray());
72             Test.store(hm);
73             checkFileSize(call++);
74             Test.commit();
75             checkFileSize(call++);
76         }
77     }
78     
79     
80     private Long JavaDoc[] longWrapperArray(){
81         Long JavaDoc[] larr = new Long JavaDoc[100];
82         for (int j = 0; j < larr.length; j++) {
83             larr[j] = new Long JavaDoc(j);
84         }
85         return larr;
86     }
87     
88     
89     
90     private void checkFileSize(int call){
91         if(Test.canCheckFileSize()){
92             int newFileLength = Test.fileLength();
93             
94             // Interesting for manual tests:
95
// System.out.println(newFileLength);
96

97             if(call == 6){
98                 // consistency reached, start testing
99
jumps = 0;
100                 fileLength = newFileLength;
101             }else if(call > 6){
102                 if(newFileLength > fileLength){
103                     if(jumps < 4){
104                         fileLength = newFileLength;
105                         jumps ++;
106                         // allow two further step in size
107
// may be necessary for commit space extension
108
}else{
109                         // now we want constant behaviour
110
Test.error();
111                     }
112                 }
113             }
114         }
115     }
116     
117     private static transient int fileLength;
118     private static transient int jumps;
119     
120     
121 }
122
123
Popular Tags