From: James Ahlborn Date: Thu, 17 Apr 2008 02:09:16 +0000 (+0000) Subject: more big index tests; minor bug fix X-Git-Tag: rel_1_1_14~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6f9ccc356d24f21bff5675a5bc7bd228fc9f32a4;p=jackcess.git more big index tests; minor bug fix git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@334 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/java/com/healthmarketscience/jackcess/IndexPageCache.java b/src/java/com/healthmarketscience/jackcess/IndexPageCache.java index f8046d4..0c0d890 100644 --- a/src/java/com/healthmarketscience/jackcess/IndexPageCache.java +++ b/src/java/com/healthmarketscience/jackcess/IndexPageCache.java @@ -610,6 +610,7 @@ public class IndexPageCache // clear the root page rootMain._leaf = false; + rootMain._childTailPageNumber = INVALID_INDEX_PAGE_NUMBER; rootExtra._entries = new ArrayList(); rootExtra._entryPrefix = EMPTY_PREFIX; rootExtra._totalEntrySize = 0; @@ -869,6 +870,7 @@ public class IndexPageCache throw new IllegalStateException("Prev page " + prevMain + " does not ref " + dpMain); } + validatePeerStatus(dpMain, prevMain); } DataPageMain nextMain = _dataPages.get(dpMain._nextPageNumber); @@ -877,6 +879,25 @@ public class IndexPageCache throw new IllegalStateException("Next page " + nextMain + " does not ref " + dpMain); } + validatePeerStatus(dpMain, nextMain); + } + } + + private void validatePeerStatus(DataPageMain dpMain, DataPageMain peerMain) + throws IOException + { + if(dpMain._leaf != peerMain._leaf) { + throw new IllegalStateException("Mismatched peer status " + + dpMain._leaf + " " + peerMain._leaf); + } + if(!dpMain._leaf) { + if((dpMain._parentPageNumber != null) && + (peerMain._parentPageNumber != null) && + ((int)dpMain._parentPageNumber != (int)peerMain._parentPageNumber)) { + throw new IllegalStateException("Mismatched node parents " + + dpMain._parentPageNumber + " " + + peerMain._parentPageNumber); + } } } diff --git a/test/data/bigIndexTest.mdb b/test/data/bigIndexTest.mdb new file mode 100644 index 0000000..abbb14d Binary files /dev/null and b/test/data/bigIndexTest.mdb differ diff --git a/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java b/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java index fdca807..73f1a9c 100644 --- a/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java @@ -65,60 +65,75 @@ public class BigIndexTest extends TestCase { public void testComplexIndex() throws Exception { // this file has an index with "compressed" entries and node pages - File origFile = new File("test/data/compIndexTest.mdb"); - Database db = open(origFile); + Database db = open(new File("test/data/compIndexTest.mdb")); Table t = db.getTable("Table1"); Index index = t.getIndex("CD_AGENTE"); assertFalse(index.isInitialized()); assertEquals(512, countRows(t)); assertEquals(512, index.getEntryCount()); db.close(); + } + + public void testBigIndex() throws Exception + { + // this file has an index with "compressed" entries and node pages + File origFile = new File("test/data/bigIndexTest.mdb"); + Database db = open(origFile); + Table t = db.getTable("Table1"); + Index index = t.getIndex("col1"); + assertFalse(index.isInitialized()); + assertEquals(0, countRows(t)); + assertEquals(0, index.getEntryCount()); + db.close(); DatabaseTest._autoSync = false; try { + + String extraText = " some random text to fill out the index and make it fill up pages"; // copy to temp file and attempt to edit db = openCopy(origFile); t = db.getTable("Table1"); - index = t.getIndex("CD_AGENTE"); + index = t.getIndex("col1"); System.out.println("BigIndexTest: Index type: " + index.getClass()); // add 10,000 (pseudo) random entries to the table Random rand = new Random(13L); - for(int i = 0; i < 10000; ++i) { - Integer nextInt = rand.nextInt(); + for(int i = 0; i < 2000; ++i) { + int nextInt = rand.nextInt(Integer.MAX_VALUE); + String nextVal = "" + nextInt + extraText; if(((i + 1) % 3333) == 0) { - nextInt = null; + nextVal = null; } - t.addRow(nextInt, - "this is some row data " + nextInt, - "this is some more row data " + nextInt); + t.addRow(nextVal, "this is some row data " + nextInt); } ((BigIndex)index).validate(); db.flush(); t = db.getTable("Table1"); - index = t.getIndex("CD_AGENTE"); + index = t.getIndex("col1"); // make sure all entries are there and correctly ordered - int lastValue = Integer.MAX_VALUE; + String lastValue = " "; int rowCount = 0; - List firstTwo = new ArrayList(); + List firstTwo = new ArrayList(); for(Map row : Cursor.createIndexCursor(t, index)) { - Integer tmpVal = (Integer)row.get("CD_AGENTE"); - int val = ((tmpVal != null) ? (int)tmpVal : Integer.MIN_VALUE); + String val = (String)row.get("col1"); + if(val == null) { + val = "ZZZZZZZ"; + } assertTrue("" + val + " <= " + lastValue + " " + rowCount, - val <= lastValue); + lastValue.compareTo(val) <= 0); if(firstTwo.size() < 2) { - firstTwo.add(tmpVal); + firstTwo.add(val); } lastValue = val; ++rowCount; } - assertEquals(10512, rowCount); + assertEquals(2000, rowCount); ((BigIndex)index).validate(); @@ -132,9 +147,9 @@ public class BigIndexTest extends TestCase { ((BigIndex)index).validate(); - List found = new ArrayList(); + List found = new ArrayList(); for(Map row : Cursor.createIndexCursor(t, index)) { - found.add((Integer)row.get("CD_AGENTE")); + found.add((String)row.get("col1")); } assertEquals(firstTwo, found); @@ -158,17 +173,19 @@ public class BigIndexTest extends TestCase { } } - public void x_testBigIndex() throws Exception - { - File f = new File("test/data/databaseTest19731_ind.mdb"); - Database db = open(f); - Table t = db.getTable("test"); - System.out.println("FOO reading index"); - Index index = t.getIndexes().get(0); - index.initialize(); - System.out.println(index); - db.close(); - } +// public void testBigIndex2() throws Exception +// { +// File f = new File("test/data/databaseTest19731_ind.mdb"); +// Database db = open(f); +// Table t = db.getTable("test"); +// System.out.println("FOO reading index"); +// Index index = t.getIndexes().get(0); +// index.initialize(); +// index.forceInit(); +// index.validate(); +// System.out.println(index); +// db.close(); +// } }