-
Notifications
You must be signed in to change notification settings - Fork 0
/
HeapFileWriteTest.java
53 lines (43 loc) · 1.41 KB
/
HeapFileWriteTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package simpledb;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import junit.framework.JUnit4TestAdapter;
public class HeapFileWriteTest extends TestUtil.CreateHeapFile {
private TransactionId tid;
/**
* Set up initial resources for each unit test.
*/
@Before public void setUp() throws Exception {
super.setUp();
tid = new TransactionId();
}
@After public void tearDown() throws Exception {
Database.getBufferPool().transactionComplete(tid);
}
/**
* Unit test for HeapFile.addTuple()
*/
@Test public void addTuple() throws Exception {
// we should be able to add 504 tuples on an empty page.
for (int i = 0; i < 504; ++i) {
empty.insertTuple(tid, Utility.getHeapTuple(i, 2));
assertEquals(1, empty.numPages());
}
// the next 512 additions should live on a new page
for (int i = 0; i < 504; ++i) {
empty.insertTuple(tid, Utility.getHeapTuple(i, 2));
assertEquals(2, empty.numPages());
}
// and one more, just for fun...
empty.insertTuple(tid, Utility.getHeapTuple(0, 2));
assertEquals(3, empty.numPages());
}
/**
* JUnit suite target
*/
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(HeapFileWriteTest.class);
}
}