001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test;
022:
023: import java.util.*;
024:
025: public class PrimitiveArrayFileSize {
026:
027: Object arr;
028:
029: public void testSimpleLongInObject() {
030: int call = 0;
031: PrimitiveArrayFileSize pafs = new PrimitiveArrayFileSize();
032: for (int i = 0; i < 12; i++) {
033: pafs.arr = new long[100];
034: Test.store(pafs);
035: checkFileSize(call++);
036: Test.commit();
037: checkFileSize(call++);
038: }
039: }
040:
041: public void testLongWrapperInObject() {
042: int call = 0;
043: PrimitiveArrayFileSize pafs = new PrimitiveArrayFileSize();
044: for (int i = 0; i < 12; i++) {
045: pafs.arr = longWrapperArray();
046: Test.store(pafs);
047: checkFileSize(call++);
048: Test.commit();
049: checkFileSize(call++);
050: }
051: }
052:
053: public void testSimpleLongInHashMap() {
054: HashMap hm = new HashMap();
055: int call = 0;
056: for (int i = 0; i < 12; i++) {
057: long[] lll = new long[100];
058: lll[0] = 99999;
059: hm.put("test", lll);
060: Test.store(hm);
061: checkFileSize(call++);
062: Test.commit();
063: checkFileSize(call++);
064: }
065: }
066:
067: public void testLongWrapperInHashMap() {
068: HashMap hm = new HashMap();
069: int call = 0;
070: for (int i = 0; i < 12; i++) {
071: hm.put("test", longWrapperArray());
072: Test.store(hm);
073: checkFileSize(call++);
074: Test.commit();
075: checkFileSize(call++);
076: }
077: }
078:
079: private Long[] longWrapperArray() {
080: Long[] larr = new Long[100];
081: for (int j = 0; j < larr.length; j++) {
082: larr[j] = new Long(j);
083: }
084: return larr;
085: }
086:
087: private void checkFileSize(int call) {
088: if (Test.canCheckFileSize()) {
089: int newFileLength = Test.fileLength();
090:
091: // Interesting for manual tests:
092: // System.out.println(newFileLength);
093:
094: if (call == 6) {
095: // consistency reached, start testing
096: jumps = 0;
097: fileLength = newFileLength;
098: } else if (call > 6) {
099: if (newFileLength > fileLength) {
100: if (jumps < 4) {
101: fileLength = newFileLength;
102: jumps++;
103: // allow two further step in size
104: // may be necessary for commit space extension
105: } else {
106: // now we want constant behaviour
107: Test.error();
108: }
109: }
110: }
111: }
112: }
113:
114: private static transient int fileLength;
115: private static transient int jumps;
116:
117: }
|