01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: 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.db4ounit.jre11.defragment;
22:
23: import java.io.*;
24: import java.util.*;
25:
26: import com.db4o.*;
27: import com.db4o.config.*;
28: import com.db4o.db4ounit.common.defragment.*;
29: import com.db4o.db4ounit.jre11.defragment.SlotDefragmentVectorTestCase.*;
30: import com.db4o.defragment.*;
31: import com.db4o.internal.*;
32: import com.db4o.query.*;
33:
34: import db4ounit.*;
35:
36: public class SlotDefragmentVectorUUIDTestCase implements TestCase {
37:
38: public static class Holder {
39: public Vector _vector;
40:
41: public Holder(Vector vector) {
42: this ._vector = vector;
43: }
44: }
45:
46: // FIXME runs fine in db4oj suite, but fails in db4ojdk1.2 suite?!?
47: public void _testVectorDefragment() throws Exception {
48: store();
49: defrag();
50: query();
51: }
52:
53: private void query() {
54: ObjectContainer db = openDatabase();
55: Query query = db.query();
56: query.constrain(Holder.class);
57: ObjectSet result = query.execute();
58: Assert.areEqual(1, result.size());
59: db.close();
60: }
61:
62: private void defrag() throws IOException {
63: DefragmentConfig config = new DefragmentConfig(
64: SlotDefragmentTestConstants.FILENAME);
65: config.forceBackupDelete(true);
66: config.db4oConfig(configuration());
67: Defragment.defrag(config);
68: }
69:
70: private void store() {
71: new File(SlotDefragmentTestConstants.FILENAME).delete();
72: ObjectContainer db = openDatabase();
73: db.set(new Holder(new Vector()));
74: db.close();
75: }
76:
77: private ObjectContainer openDatabase() {
78: Configuration config = configuration();
79: config.generateUUIDs(ConfigScope.GLOBALLY);
80: return Db4o.openFile(config,
81: SlotDefragmentTestConstants.FILENAME);
82: }
83:
84: private Configuration configuration() {
85: Configuration config = Db4o.newConfiguration();
86: config.reflectWith(Platform4.reflectorForType(Data.class));
87: return config;
88: }
89:
90: }
|