001: /*
002:
003: * $Id: TestPhysicalRowIdManager.java,v 1.5 2003/09/21 15:49:02 boisvert Exp $
004:
005: *
006:
007: * Unit tests for PhysicalRowIdManager class
008:
009: *
010:
011: * Simple db toolkit
012:
013: * Copyright (C) 1999, 2000 Cees de Groot <cg@cdegroot.com>
014:
015: *
016:
017: * This library is free software; you can redistribute it and/or
018:
019: * modify it under the terms of the GNU Library General Public License
020:
021: * as published by the Free Software Foundation; either version 2
022:
023: * of the License, or (at your option) any later version.
024:
025: *
026:
027: * This library is distributed in the hope that it will be useful,
028:
029: * but WITHOUT ANY WARRANTY; without even the implied warranty of
030:
031: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
032:
033: * Library General Public License for more details.
034:
035: *
036:
037: * You should have received a copy of the GNU Library General Public License
038:
039: * along with this library; if not, write to the Free Software Foundation,
040:
041: * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
042:
043: */
044:
045: package jdbm.recman;
046:
047: import junit.framework.*;
048:
049: /**
050:
051: * This class contains all Unit tests for {@link PhysicalRowIdManager}.
052:
053: */
054:
055: public class TestPhysicalRowIdManager extends TestCase {
056:
057: public TestPhysicalRowIdManager(String name) {
058:
059: super (name);
060:
061: }
062:
063: public void setUp() {
064:
065: TestRecordFile.deleteTestFile();
066:
067: }
068:
069: public void tearDown() {
070:
071: TestRecordFile.deleteTestFile();
072:
073: }
074:
075: /**
076:
077: * Test constructor
078:
079: */
080:
081: public void testCtor() throws Exception {
082:
083: RecordFile f = new RecordFile(TestRecordFile.testFileName);
084:
085: PageManager pm = new PageManager(f);
086:
087: PhysicalRowIdManager physMgr = new PhysicalRowIdManager(f, pm);
088:
089: f.forceClose();
090:
091: }
092:
093: /**
094:
095: * Test basics
096:
097: */
098:
099: public void testBasics() throws Exception {
100:
101: RecordFile f = new RecordFile(TestRecordFile.testFileName);
102:
103: PageManager pm = new PageManager(f);
104:
105: PhysicalRowIdManager physMgr = new PhysicalRowIdManager(f, pm);
106:
107: // insert a 10,000 byte record.
108:
109: byte[] data = TestUtil.makeRecord(10000, (byte) 1);
110:
111: Location loc = physMgr.insert(data, 0, data.length);
112:
113: assertTrue("check data1",
114:
115: TestUtil.checkRecord(physMgr.fetch(loc), 10000, (byte) 1));
116:
117: // update it as a 20,000 byte record.
118:
119: data = TestUtil.makeRecord(20000, (byte) 2);
120:
121: Location loc2 = physMgr.update(loc, data, 0, data.length);
122:
123: assertTrue("check data2",
124:
125: TestUtil.checkRecord(physMgr.fetch(loc2), 20000, (byte) 2));
126:
127: // insert a third record. This'll effectively block the first one
128:
129: // from growing
130:
131: data = TestUtil.makeRecord(20, (byte) 3);
132:
133: Location loc3 = physMgr.insert(data, 0, data.length);
134:
135: assertTrue("check data3",
136:
137: TestUtil.checkRecord(physMgr.fetch(loc3), 20, (byte) 3));
138:
139: // now, grow the first record again
140:
141: data = TestUtil.makeRecord(30000, (byte) 4);
142:
143: loc2 = physMgr.update(loc2, data, 0, data.length);
144:
145: assertTrue("check data4",
146:
147: TestUtil.checkRecord(physMgr.fetch(loc2), 30000, (byte) 4));
148:
149: // delete the record
150:
151: physMgr.delete(loc2);
152:
153: f.forceClose();
154:
155: }
156:
157: /**
158:
159: * Runs all tests in this class
160:
161: */
162:
163: public static void main(String[] args) {
164:
165: junit.textui.TestRunner.run(new TestSuite(
166: TestPhysicalRowIdManager.class));
167:
168: }
169:
170: }
|