diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2008-04-14 02:09:43 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2008-04-14 02:09:43 +0000 |
commit | 5ed9b04c403f5cc8f7316523b4f5a5b64b9e4419 (patch) | |
tree | 6b6d1fd9c89e1c74515f2c88382650c49d57aadd /test | |
parent | 7d405b6f8e3208f288b0a122bd2642b7b19800aa (diff) | |
download | jackcess-5ed9b04c403f5cc8f7316523b4f5a5b64b9e4419.tar.gz jackcess-5ed9b04c403f5cc8f7316523b4f5a5b64b9e4419.zip |
complete rework of large index support after realizing that my understanding of the node page structure was a wee bit incorrect; basic operations are working, some testing implemented
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@325 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test')
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java | 111 |
1 files changed, 95 insertions, 16 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java b/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java index 52ddc48..31485ea 100644 --- a/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/BigIndexTest.java @@ -28,6 +28,9 @@ King of Prussia, PA 19406 package com.healthmarketscience.jackcess; import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.util.Random; import junit.framework.TestCase; @@ -65,27 +68,103 @@ public class BigIndexTest extends TestCase { File origFile = new File("test/data/compIndexTest.mdb"); Database db = open(origFile); Table t = db.getTable("Table1"); - Index index = t.getIndexes().get(0); + Index index = t.getIndex("CD_AGENTE"); assertFalse(index.isInitialized()); assertEquals(512, countRows(t)); assertEquals(512, index.getEntryCount()); db.close(); - // copy to temp file and attempt to edit - db = openCopy(origFile); - t = db.getTable("Table1"); - index = t.getIndexes().get(0); - - System.out.println("BigIndexTest: Index type: " + index.getClass()); - - // FIXME -// Random rand = new Random(13L); -// for(int i = 0; i < 10000; ++i) { -// int nextInt = rand.nextInt(); -// t.addRow(nextInt, -// "this is some row data " + nextInt, -// "this is some more row data " + nextInt); -// } + DatabaseTest._autoSync = false; + try { + + // copy to temp file and attempt to edit + db = openCopy(origFile); + t = db.getTable("Table1"); + index = t.getIndex("CD_AGENTE"); + + 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(); + if(((i + 1) % 3333) == 0) { + nextInt = null; + } + t.addRow(nextInt, + "this is some row data " + nextInt, + "this is some more row data " + nextInt); + } + + db.flush(); + t = db.getTable("Table1"); + index = t.getIndex("CD_AGENTE"); + + // make sure all entries are there and correctly ordered + int lastValue = Integer.MAX_VALUE; + int rowCount = 0; + List<Integer> firstTwo = new ArrayList<Integer>(); + for(Map<String,Object> row : Cursor.createIndexCursor(t, index)) { + Integer tmpVal = (Integer)row.get("CD_AGENTE"); + int val = ((tmpVal != null) ? (int)tmpVal : Integer.MIN_VALUE); + assertTrue("" + val + " <= " + lastValue + " " + rowCount, + val <= lastValue); + if(firstTwo.size() < 2) { + firstTwo.add(tmpVal); + } + lastValue = val; + ++rowCount; + } + + assertEquals(10512, rowCount); + + // remove all but the first two entries + Cursor cursor = new CursorBuilder(t).setIndex(index) + .afterLast().toCursor(); + for(int i = 0; i < (rowCount - 2); ++i) { + assertTrue(cursor.moveToPreviousRow()); + cursor.deleteCurrentRow(); + } + +// System.out.println("FOO: " + index); + + List<Integer> found = new ArrayList<Integer>(); + for(Map<String,Object> row : Cursor.createIndexCursor(t, index)) { + found.add((Integer)row.get("CD_AGENTE")); + } + + assertEquals(firstTwo, found); + + // FIXME, last entry removal still borked + // remove remaining entries +// cursor = Cursor.createCursor(t); +// for(int i = 0; i < 2; ++i) { +// assertTrue(cursor.moveToNextRow()); +// cursor.deleteCurrentRow(); +// } + +// assertFalse(cursor.moveToNextRow()); +// assertFalse(cursor.moveToPreviousRow()); + +// System.out.println("FOO: " + index); + + db.close(); + + } finally { + DatabaseTest._autoSync = Database.DEFAULT_AUTO_SYNC; + } + } + + 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(); } |