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.db4ounit.common.freespace;
022:
023: import com.db4o.internal.freespace.*;
024: import com.db4o.internal.slots.*;
025:
026: import db4ounit.*;
027:
028: public class FreespaceManagerTestCase extends
029: FreespaceManagerTestCaseBase {
030:
031: public static void main(String[] args) {
032: new FreespaceManagerTestCase().runSolo();
033: }
034:
035: public void testAllocateTransactionLogSlot() {
036: for (int i = 0; i < fm.length; i++) {
037: if (fm[i].systemType() == AbstractFreespaceManager.FM_RAM) {
038: Slot slot = fm[i].allocateTransactionLogSlot(1);
039: Assert.isNull(slot);
040:
041: fm[i].free(new Slot(5, 10));
042: fm[i].free(new Slot(100, 5));
043: fm[i].free(new Slot(140, 27));
044:
045: slot = fm[i].allocateTransactionLogSlot(28);
046: Assert.isNull(slot);
047: Assert.areEqual(3, fm[i].slotCount());
048:
049: slot = fm[i].allocateTransactionLogSlot(27);
050: Assert.areEqual(2, fm[i].slotCount());
051: Assert.areEqual(new Slot(140, 27), slot);
052: }
053: }
054: }
055:
056: public void testConstructor() {
057: for (int i = 0; i < fm.length; i++) {
058: Assert.areEqual(0, fm[i].slotCount());
059: Assert.areEqual(0, fm[i].totalFreespace());
060: }
061: }
062:
063: public void testFree() {
064: for (int i = 0; i < fm.length; i++) {
065: int count = fm[i].slotCount();
066: fm[i].free(new Slot(1000, 1));
067: Assert.areEqual(count + 1, fm[i].slotCount());
068: }
069: }
070:
071: public void testGetSlot() {
072: for (int i = 0; i < fm.length; i++) {
073: Slot slot = fm[i].getSlot(1);
074: Assert.isNull(slot);
075: Assert.areEqual(0, fm[i].slotCount());
076:
077: fm[i].free(new Slot(10, 1));
078: slot = fm[i].getSlot(1);
079: Assert.areEqual(slot.address(), 10);
080: Assert.areEqual(0, fm[i].slotCount());
081:
082: slot = fm[i].getSlot(1);
083: Assert.isNull(slot);
084:
085: fm[i].free(new Slot(10, 1));
086: fm[i].free(new Slot(20, 2));
087: slot = fm[i].getSlot(1);
088: Assert.areEqual(1, fm[i].slotCount());
089: Assert.areEqual(slot.address(), 10);
090:
091: slot = fm[i].getSlot(3);
092: Assert.isNull(slot);
093:
094: slot = fm[i].getSlot(1);
095: Assert.isNotNull(slot);
096: Assert.areEqual(1, fm[i].slotCount());
097:
098: }
099: }
100:
101: public void testMerging() {
102: for (int i = 0; i < fm.length; i++) {
103: fm[i].free(new Slot(5, 5));
104: fm[i].free(new Slot(15, 5));
105: fm[i].free(new Slot(10, 5));
106: Assert.areEqual(1, fm[i].slotCount());
107: }
108: }
109:
110: public void testTotalFreeSpace() {
111: for (int i = 0; i < fm.length; i++) {
112: fm[i].free(new Slot(5, 10));
113: fm[i].free(new Slot(100, 5));
114: fm[i].free(new Slot(140, 27));
115: Assert.areEqual(42, fm[i].totalFreespace());
116: fm[i].getSlot(8);
117: Assert.areEqual(34, fm[i].totalFreespace());
118: fm[i].getSlot(6);
119: Assert.areEqual(28, fm[i].totalFreespace());
120: fm[i].free(new Slot(120, 14));
121: Assert.areEqual(42, fm[i].totalFreespace());
122: }
123: }
124:
125: public void testMigrateTo() {
126: for (int from = 0; from < fm.length; from++) {
127: for (int to = 0; to < fm.length; to++) {
128: if (to != from) {
129:
130: clear(fm[from]);
131: clear(fm[to]);
132:
133: AbstractFreespaceManager.migrate(fm[from], fm[to]);
134:
135: assertSame(fm[from], fm[to]);
136:
137: fm[from].free(new Slot(5, 10));
138: fm[from].free(new Slot(100, 5));
139: fm[from].free(new Slot(140, 27));
140: AbstractFreespaceManager.migrate(fm[from], fm[to]);
141:
142: assertSame(fm[from], fm[to]);
143: }
144: }
145: }
146: }
147:
148: }
|