From 6f9ccc356d24f21bff5675a5bc7bd228fc9f32a4 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Thu, 17 Apr 2008 02:09:16 +0000 Subject: [PATCH] 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 --- .../jackcess/IndexPageCache.java | 21 +++++ test/data/bigIndexTest.mdb | Bin 0 -> 114688 bytes .../jackcess/BigIndexTest.java | 77 +++++++++++------- 3 files changed, 68 insertions(+), 30 deletions(-) create mode 100644 test/data/bigIndexTest.mdb 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 0000000000000000000000000000000000000000..abbb14df93999d56ad4af1aad0fe468a71313df5 GIT binary patch literal 114688 zcmeHQ3v?96m3`eBNi(C-j3f|X3}zzy3$c`$kr2W$j--)fEK3Lw;9#_%-v|bMBMA%! z83o6ClAMzbIoa$wjuXe;1UBAJ;yB*j#CBpQ_WCS|4V(QXC;x=?i8qkXW_|M4?0wZ; znx2sm0?9I;SEK5F{i^EKt6SC8UDZ`jWDqqExAk?l4R!|WW5dCkY66R%?8|6x^?YUX ztDoLESowB(=-!8qB<_DO{KEb(o(Vnu{jYzl<6Eb``f%Ov-}m&o{r#s`J$mw?->p7= z<143&-q-p!bfDb(%J(0CPwTvB=xvXee(kmW+j`%0aK&d%9{h-V*#m$4`!$y*qKE3i*=9eTi`qMYH|C&Z^|MnD+xgpae{y#AP5Ko zf`A|(2nYg#fFK|U2m-T#fMF~#FyNEl6^ejibOw05&(5T$0(%1%Ek{8>5D)|e0YN|z z5CjAPK|l}?1Ox#=KoGd75ct2u44i3vFNaIB*hRDz-`wZfMbmQvx}?qdltcNLBH(EP zI7Btz+36%s+Q+gylmVUxk_$LYIThemGExKFoWiBn9&msq)Jtws0hwt51qg6)itKSw zR*J=t;pG4?h}6u-43)ytBbf*1n!_n_AuKfoSpj(vHfcZrMVvIi5B1UmlvWD66iCJl z4`-e=Ucd-ava{8-Dk7<_ORMYSI!Fjf%YPIKGxDc$Q(p?p1N*Cx=z{yNip&%&U%FQBOmv;6fZT=-Ae00q*{-(tXm)C zu=EAA5qUA)M_owS0N)2K7Nzl|zdT^cO@-aN z)REI5)ugd4WXO68T{29uEc_NtD6_`bLoTGwRQZ`W zX29o?8%Ga(9{F($uqPjmx$u7S;+O-EHict0yrs^#4nhb5f`A|(2nYg#fFK|U2m*q@ zWq^QbeA>^&Xu`OIM;)u|GO1yRqkPRgG`EK598`d)^WfR(!Mz$?W7q^%>TuPVZ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ck*={|_nUxt9O{ literal 0 HcmV?d00001 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(); +// } } -- 2.39.5