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 com.db4o.*;
024: import com.db4o.config.*;
025:
026: public class BindFileSize {
027:
028: static final int LENGTH = 1000;
029:
030: public static class Item {
031:
032: public String foo;
033:
034: public Item() {
035: }
036:
037: public Item(int length) {
038: StringBuffer sb = new StringBuffer(length);
039: for (int i = 0; i < length; i++) {
040: sb.append("g");
041: }
042: this .foo = sb.toString();
043: }
044:
045: }
046:
047: public void configure() {
048: Db4o.configure().generateUUIDs(Integer.MAX_VALUE);
049: Db4o.configure().generateVersionNumbers(Integer.MAX_VALUE);
050: }
051:
052: public void store() {
053: Test.deleteAllInstances(Item.class);
054: Item item1 = new Item(LENGTH - 1);
055: Item item2 = new Item(LENGTH - 1);
056: Test.store(item1);
057: Test.store(item2);
058: Test.commit();
059: Test.delete(item1);
060: Test.delete(item2);
061: Test.commit();
062: Test.store(new Item(LENGTH));
063: }
064:
065: public void testGrowth() {
066: Test.reOpen();
067: Item item = (Item) Test.getOne(Item.class);
068: long id = Test.objectContainer().getID(item);
069: for (int call = 0; call < 50; call++) {
070: item = new Item(LENGTH);
071: Test.objectContainer().bind(item, id);
072: Test.objectContainer().set(item);
073: Test.commit();
074: checkFileSize(call);
075: Test.reOpen();
076: }
077: }
078:
079: private void checkFileSize(int call) {
080: if (Test.canCheckFileSize()) {
081: int newFileLength = Test.fileLength();
082:
083: // Interesting for manual tests:
084: // System.out.println(newFileLength);
085:
086: if (call == 10) {
087: // consistency reached, start testing
088: jumps = 0;
089: fileLength = newFileLength;
090: } else if (call > 10) {
091: if (newFileLength > fileLength) {
092: if (jumps < 4) {
093: fileLength = newFileLength;
094: jumps++;
095: // allow two further steps in size
096: // may be necessary for commit space extension
097: } else {
098: // now we want constant behaviour
099: // Test.error();
100: }
101: }
102: }
103: }
104: }
105:
106: private static transient int fileLength;
107: private static transient int jumps;
108:
109: }
|