📄 t_rawstorefactory.java
字号:
t_util.t_commit(t); t.close(); PASS("T012"); } /** C010 - Create a container within a transaction, commit and the re-open the container twice. @exception T_Fail Unexpected behaviour from the API @exception StandardException Unexpected exception from the implementation */ protected void C010(int segment) throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); long cid = t_util.t_addContainer(t, segment); t_util.t_commit(t); ContainerHandle c1, c2; c1 = t_util.t_openContainer(t, segment, cid, true); c1 = t_util.t_openContainer(t, segment, cid, true); t_util.t_dropContainer(t, segment, cid); // cleanup t_util.t_commit(t); t.close(); PASS("C010"); } /** C011 - Create a container withina transaction, commit and the re-open the container in update and non-update mode. @exception T_Fail Unexpected behaviour from the API @exception StandardException Unexpected exception from the implementation */ protected void C011() throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); long cid = t_util.t_addContainer(t, 0); t_util.t_commit(t); ContainerHandle c1, c2; c1 = t_util.t_openContainer(t, 0, cid, false); c1 = t_util.t_openContainer(t, 0, cid, true); t_util.t_dropContainer(t, 0, cid); // cleanup t_util.t_commit(t); t.close(); PASS("C011"); } /** C012 - Drop a container within a transaction, commit, see that it is deleted. Drop a container within a transaction, rollback and re-open and see that it is not deleted. @exception T_Fail Unexpected behaviour from the API @exception StandardException Standard Derby error policy */ protected void C012(long segment) throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); long cid = t_util.t_addContainer(t, segment); t_util.t_commit(t); ContainerHandle c1 = t_util.t_openContainer(t, segment, cid, true); t_util.t_dropContainer(t, segment, cid); if (testRollback) { t_util.t_abort(t); // this should rollback the drop c1 = t_util.t_openContainer(t, segment, cid, true); REPORT("rollback of drop container tested"); t_util.t_dropContainer(t, segment, cid); } t_util.t_commit(t); ContainerKey id = new ContainerKey(segment, cid); c1 = t.openContainer(id, (ContainerHandle.MODE_FORUPDATE | openMode)); // this should fail if (c1 != null) throw T_Fail.testFailMsg("Deleted Container should fail to open"); t_util.t_commit(t); t.close(); PASS("C012"); } /** C014 - Open a container for locking only. @exception T_Fail Unexpected behaviour from the API @exception StandardException Standard Derby error policy */ protected void C014() throws T_Fail, StandardException { Transaction t = t_util.t_startTransaction(); ContainerKey id = new ContainerKey(77, 45); ContainerHandle c = t.openContainer(id, ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY); if (c == null) throw T_Fail.testFailMsg("open of a container for lock only failed."); RecordHandle rh1 = c.makeRecordHandle(23, 456); if (rh1 == null) throw T_Fail.testFailMsg("makeRecordHandle returned null"); c.getLockingPolicy().lockRecordForRead(t, c, rh1, true, true); RecordHandle rh2 = c.makeRecordHandle(23, 7); if (rh2 == null) throw T_Fail.testFailMsg("makeRecordHandle returned null"); c.getLockingPolicy().lockRecordForRead(t, c, rh2, true, false); RecordHandle rh3 = c.makeRecordHandle(23, 9); c.getLockingPolicy().lockRecordForWrite(t, rh3, false, true); if (rh3 == null) throw T_Fail.testFailMsg("makeRecordHandle returned null"); c.getLockingPolicy().unlockRecordAfterRead(t, c, rh2, false, true); c.close(); t.commit(); t.close(); PASS("C014"); } /** @exception T_Fail Unexpected behaviour from the API @exception StandardException Unexpected exception from the implementation */ protected void C200() throws T_Fail, StandardException { Transaction t1 = t_util.t_startTransaction(); long cid = t_util.t_addContainer(t1, 0); t_util.t_commit(t1); ContainerHandle c1; Page lastPage; RecordHandle rh001, rh002, rh003; T_RawStoreRow row; REPORT("see if the container can be opened again"); c1 = t_util.t_openContainer(t1, 0, cid, false); c1.close(); t_util.t_commit(t1); REPORT("insert a record into the container."); c1 = t_util.t_openContainer(t1, 0, cid, true); lastPage = t_util.t_getLastPage(c1); if (lastPage == null) throw T_Fail.testFailMsg("Could get container's last page"); if (lastPage.getPageNumber() != ContainerHandle.FIRST_PAGE_NUMBER) throw T_Fail.testFailMsg("Initial page must be " + ContainerHandle.FIRST_PAGE_NUMBER + ", is " + lastPage.getPageNumber()); row = new T_RawStoreRow(REC_001); if (!lastPage.spaceForInsert()) throw T_Fail.testFailMsg("No room for record on page"); rh001 = t_util.t_insert(lastPage, row); if (rh001 == null) throw T_Fail.testFailMsg("Failed to insert record"); // see if we can fetch that record t_util.t_checkFetch(lastPage, rh001, REC_001); lastPage.unlatch(); lastPage = null; t_util.t_commit(t1); c1 = null; REPORT("read record just inserted."); c1 = t_util.t_openContainer(t1, 0, cid, false); lastPage = t_util.t_getLastPage(c1); if (lastPage == null) throw T_Fail.testFailMsg("Could get container's last page"); t_util.t_checkFetch(lastPage, rh001, REC_001); t_util.t_checkFetchFirst(lastPage, REC_001); t_util.t_checkFetchLast(lastPage, REC_001); t_util.t_commit(t1); lastPage = null; c1 = null; REPORT("insert 2 more records."); c1 = t_util.t_openContainer(t1, 0, cid, true); lastPage = t_util.t_getLastPage(c1); if (lastPage == null) throw T_Fail.testFailMsg("Could get container's last page"); if (lastPage.getPageNumber() != ContainerHandle.FIRST_PAGE_NUMBER) throw T_Fail.testFailMsg("Initial page must be " + ContainerHandle.FIRST_PAGE_NUMBER + ", is " + lastPage.getPageNumber()); row = new T_RawStoreRow(REC_002); if (!lastPage.spaceForInsert()) throw T_Fail.testFailMsg("No room for record on page"); if (!lastPage.recordExists(rh001, false)) throw T_Fail.testFailMsg("Record 001 has vanished"); // // RESOLVE: just insert them for now, order is 002,001,003 // 001 is already on the page rh002 = t_util.t_insertAtSlot(lastPage, 0, row); row = new T_RawStoreRow(REC_003); rh003 = t_util.t_insert(lastPage, row); // Order is 002, 001, 003 lastPage.unlatch(); lastPage = null; t_util.t_commit(t1); c1 = null; REPORT("checks on all 3 records."); c1 = t_util.t_openContainer(t1, 0, cid, false); lastPage = t_util.t_getLastPage(c1); if (lastPage == null) throw T_Fail.testFailMsg("Could get container's last page"); // Order is 002, 001, 003 t_util.t_checkFetch(lastPage, rh001, REC_001); t_util.t_checkFetch(lastPage, rh002, REC_002); t_util.t_checkFetch(lastPage, rh003, REC_003); t_util.t_checkFetch(lastPage, lastPage.getRecordHandle(rh001.getId()), REC_001); t_util.t_checkFetch(lastPage, lastPage.getRecordHandle(rh002.getId()), REC_002); lastPage.unlatch(); lastPage = null; t_util.t_commit(t1); REPORT("start deleting."); c1 = t_util.t_openContainer(t1, 0, cid, true); lastPage = t_util.t_getLastPage(c1); if (lastPage == null) throw T_Fail.testFailMsg("Could get container's last page"); // Order is 002, 001, 003 t_util.t_checkFetch(lastPage, rh001, REC_001); t_util.t_checkFetch(lastPage, rh002, REC_002); t_util.t_checkFetch(lastPage, rh003, REC_003); lastPage.delete(rh001, (LogicalUndo)null); if (lastPage.fetch( rh001, new DataValueDescriptor[0], (FormatableBitSet) null, false) != null) { throw T_Fail.testFailMsg("deleted record is still present"); } // Order is 002, 003 t_util.t_checkFetch(lastPage, rh002, REC_002); t_util.t_checkFetch(lastPage, rh003, REC_003); t_util.t_checkFetchNext(lastPage, rh002, REC_003); t_util.t_checkFetchPrevious(lastPage, rh003, REC_002); lastPage.delete(rh002, (LogicalUndo)null); if (lastPage.fetch( rh002, new DataValueDescriptor[0], (FormatableBitSet) null, false) != null) { throw T_Fail.testFailMsg("deleted record is still present"); } t_util.t_checkFetch(lastPage, rh003, REC_003); t_util.t_checkFetchFirst(lastPage, REC_003); t_util.t_checkFetchLast(lastPage, REC_003); lastPage.unlatch(); lastPage = null; t_util.t_commit(t1); REPORT("update the remaining record."); c1 = t_util.t_openContainer(t1, 0, cid, true); lastPage = t_util.t_getLastPage(c1); if (lastPage == null) throw T_Fail.testFailMsg("Could get container's last page"); // Order is 003 t_util.t_checkFetch(lastPage, rh003, REC_003); T_RawStoreRow urow = new T_RawStoreRow(REC_004); if (lastPage.fetch( rh003, new DataValueDescriptor[0], (FormatableBitSet) null, true) == null) { throw T_Fail.testFailMsg("fetch for update returned false"); } if (!lastPage.update(rh003, urow.getRow(), (FormatableBitSet) null)) throw T_Fail.testFailMsg("update returned false"); // Order is 003 t_util.t_checkFetch(lastPage, rh003, REC_004); lastPage.unlatch(); lastPage = null; t_util.t_commit(t1); t_util.t_dropContainer(t1, 0, cid); // cleanup t_util.t_commit(t1); t1.close(); PASS("C200"); } /** C201 - Create container with different page size, minimum record size, inserting into these containers to check if the variables are set correctly. @exception T_Fail Unexpected behaviour from the API @exception StandardException Unexpected exception from the implementation */ protected void C201(int whatPage) throws T_Fail, StandardException { int pageSize = (whatPage == 0 ? 4096 : 32768); Transaction t1 = t_util.t_startTransaction(); REPORT("create container with pageSize " + pageSize + ", spareSpace " + 0 + ", minimumRecordSize " + pageSize/2); long cid = t_util.t_addContainer(t1, 0, pageSize, 0, pageSize/2, false); t_util.t_commit(t1); ContainerHandle c1; Page lastPage; RecordHandle rh001, rh002, rh003; T_RawStoreRow row; REPORT("see if the container can be opened again"); c1 = t_util.t_openContainer(t1, 0, cid, false); c1.close(); t_util.t_commit(t1); REPORT("insert a record into the container."); c1 = t_util.t_openContainer(t1, 0, cid, true); lastPage = t_util.t_getLastPage(c1); if (lastPage == null) throw T_Fail.testFailMsg("Couldn't get container's last page"); if (lastPage.getPageNumber() != ContainerHandle.FIRST_PAGE_NUMBER) throw T_Fail.testFailMsg("Initial page must be " + ContainerHandle.FIRST_PAGE_NUMBER + ", is " + lastPage.getPageNumber()); row = new T_RawStoreRow(REC_001); if (!lastPage.spaceForInsert()) throw T_Fail.testFailMsg("No room for record on page"); rh001 = t_util.t_insert(lastPage, row); if (rh001 == null) throw T_Fail.testFailMsg("Failed to insert record"); // see if we can fetch that record t_util.t_checkFetch(lastPage, rh001, REC_001); lastPage.unlatch(); lastPage = null; t_util.t_commit(t1); c1 = null; REPORT("read record just inserted."); c1 = t_util.t_openContainer(t1, 0, cid, false); lastPage = t_util.t_getLastPage(c1); if (lastPage == null) throw T_Fail.testFailMsg("Couldn't get container's last page"); t_util.t_checkFetch(lastPage, rh001, REC_001); t_util.t_checkFetchFirst(lastPage, REC_001); t_util.t_checkFetchLast(lastPage, REC_001); t_util.t_commit(t1); lastPage = null; c1 = null; // negative testing REPORT("try inserting 1 more record, but there should be no room on page for it."); c1 = t_util.t_openContainer(t1, 0, cid, true); lastPage = t_util.t_getLastPage(c1); if (lastPage == null) throw T_Fail.testFailMsg("Couldn't get container's last page"); if (lastPage.getPageNumber() != ContainerHandle.FIRST_PAGE_NUMBER) throw T_Fail.testFailMsg("Initial page must be " + ContainerHandle.FIRST_PAGE_NUMBER + ", is " + lastPage.getPageNumber()); row = new T_RawStoreRow(REC_002); if (lastPage.spaceForInsert()) { throw T_Fail.testFailMsg("Did not get no room for record on page error"); } if (!lastPage.recordExists(rh001, false)) throw T_Fail.testFailMsg("Record 001 has vanished"); lastPage.unlatch(); lastPage = null; t_util.t_commit(t1); c1 = null; t_util.t_dropContainer(t1, 0, cid); // cleanup t_util.t_commit(t1); //t1.close(); //t1 = t_util.t_startTransaction(); REPORT("create container with pageSize " + pageSize + ", spareSpace " + 0 + ", minimumRecordSize " + pageSize); REPORT("this should set minimumRecordSize to the default 100"); cid = t_util.t_addContainer(t1, 0, pageSize, 0, pageSize, false); t_util.t_commit(t1); REPORT("see if the container can be opened again"); c1 = t_util.t_openContainer(t1, 0, cid, false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -