1 21 package com.db4o.db4ounit.common.btree; 22 23 import com.db4o.Transaction; 24 import com.db4o.inside.btree.*; 25 26 import db4ounit.Assert; 27 28 public class BTreeAddRemoveTestCase extends BTreeTestCaseBase { 29 30 public void testFirstPointerMultiTransactional(){ 31 int count = BTREE_NODE_SIZE + 1; 32 for (int i = 0; i < count; i++) { 33 add(count + i + 1); 34 } 35 int smallest = count + 1; 36 Transaction trans = newTransaction(); 37 for (int i = 0; i < count; i++) { 38 add(trans, i); 39 } 40 final BTreePointer firstPointer = _btree.firstPointer(trans()); 41 assertPointerKey(smallest, firstPointer); 42 } 43 44 public void testSingleRemoveAdd() { 45 46 final int element = 1; 47 add(element); 48 assertSize(1); 49 50 remove(element); 51 assertSize(0); 52 53 add(element); 54 55 assertSingleElement(element); 56 } 57 58 public void testSearchingRemoved() { 59 final int[] keys = new int[] { 3, 4, 7, 9 }; 60 add(keys); 61 remove(4); 62 final BTreeRange result = search(4); 63 Assert.isTrue(result.isEmpty()); 64 65 final BTreeRange range = result.greater(); 66 BTreeAssert.assertRange(new int[] { 7, 9 }, range); 67 } 68 69 public void testMultipleRemoveAdds() { 70 71 final int element = 1; 72 73 add(element); 74 remove(element); 75 remove(element); 76 add(element); 77 78 assertSingleElement(element); 79 } 80 81 public void testMultiTransactionCancelledRemoval() { 82 final int element = 1; 83 add(element); 84 commit(); 85 86 final Transaction trans1 = newTransaction(); 87 final Transaction trans2 = newTransaction(); 88 89 remove(trans1, element); 90 assertSingleElement(trans2, element); 91 add(trans1, element); 92 assertSingleElement(trans1, element); 93 assertSingleElement(trans2, element); 94 95 trans1.commit(); 96 assertSingleElement(element); 97 } 98 99 public void testMultiTransactionSearch() { 100 101 final int[] keys = new int[] { 3, 4, 7, 9 }; 102 add(trans(), keys); 103 commit(trans()); 104 105 final int[] assorted = new int[] { 1, 2, 11, 13, 21, 52, 51, 66, 89, 10 }; 106 add(systemTrans(), assorted); 107 assertKeys(keys); 108 109 remove(systemTrans(), assorted); 110 assertKeys(keys); 111 112 BTreeAssert.assertRange(new int[] { 7, 9 }, search(trans(), 4).greater()); 113 } 114 115 private void assertKeys(final int[] keys) { 116 BTreeAssert.assertKeys(trans(), _btree, keys); 117 } 118 119 public void testAddRemoveInDifferentTransactions() { 120 121 final int element = 1; 122 123 add(trans(), element); 124 add(systemTrans(), element); 125 126 remove(systemTrans(), element); 127 remove(trans(), element); 128 129 assertEmpty(systemTrans()); 130 assertEmpty(trans()); 131 } 132 133 public void testRemoveAddInDifferentTransactions() { 134 final int element = 1; 135 136 add(element); 137 138 db().commit(); 139 140 remove(trans(), element); 141 remove(systemTrans(), element); 142 143 assertEmpty(systemTrans()); 144 assertEmpty(trans()); 145 146 add(trans(), element); 147 assertSingleElement(trans(), element); 148 149 add(systemTrans(), element); 150 assertSingleElement(systemTrans(), element); 151 } 152 153 public static void main(String [] args) { 154 new BTreeAddRemoveTestCase().runSolo(); 155 } 156 } 157 | Popular Tags |