diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2023-01-12 22:22:29 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2023-01-12 22:22:29 +0000 |
commit | b02d1df66cbd159b1b318405f614827af683bfbb (patch) | |
tree | 61fce9d5b55276eaffbe3e6d1439c1040dd6fcb3 /src/test/java/com/healthmarketscience | |
parent | e8cd3131bdffd29b640175836cbf7edf07b5760c (diff) | |
download | jackcess-b02d1df66cbd159b1b318405f614827af683bfbb.tar.gz jackcess-b02d1df66cbd159b1b318405f614827af683bfbb.zip |
Add option to DatabaseBuilder for ignoring broken system catalog indexes. Fixes #46
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1395 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java/com/healthmarketscience')
4 files changed, 42 insertions, 13 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java b/src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java index 004b3b2..9f2e6cd 100644 --- a/src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java @@ -35,7 +35,7 @@ public class BigIndexTest extends TestCase { public BigIndexTest(String name) { super(name); } - + public void testComplexIndex() throws Exception { for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMP_INDEX, true)) { @@ -99,12 +99,12 @@ public class BigIndexTest extends TestCase { } } - index.getIndexData().validate(); + index.getIndexData().validate(false); db.flush(); t = null; System.gc(); - + t = (TableImpl)db.getTable("Table1"); index = t.getIndex("col1"); @@ -130,7 +130,7 @@ public class BigIndexTest extends TestCase { assertEquals(2000, rowCount); - index.getIndexData().validate(); + index.getIndexData().validate(false); // delete an entry in the middle Cursor cursor = CursorBuilder.createCursor(index); @@ -147,7 +147,7 @@ public class BigIndexTest extends TestCase { cursor.deleteCurrentRow(); } - index.getIndexData().validate(); + index.getIndexData().validate(false); List<String> found = new ArrayList<String>(); for(Row row : CursorBuilder.createCursor(index)) { @@ -166,7 +166,7 @@ public class BigIndexTest extends TestCase { assertFalse(cursor.moveToNextRow()); assertFalse(cursor.moveToPreviousRow()); - index.getIndexData().validate(); + index.getIndexData().validate(false); // add 50 (pseudo) random entries to the table rand = new Random(42L); @@ -179,14 +179,14 @@ public class BigIndexTest extends TestCase { t.addRow(nextVal, "this is some row data " + nextInt); } - index.getIndexData().validate(); + index.getIndexData().validate(false); cursor = CursorBuilder.createCursor(index); while(cursor.moveToNextRow()) { cursor.deleteCurrentRow(); } - index.getIndexData().validate(); + index.getIndexData().validate(false); db.close(); diff --git a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java index 3b90545..06a05b8 100644 --- a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -989,6 +989,31 @@ public class DatabaseTest extends TestCase assertEquals(expectedUpdateDate, table.getUpdatedDate().toString()); } } + + public void testBrokenIndex() throws Exception { + TestDB testDb = TestDB.getSupportedForBasename(Basename.TEST).get(0); + try (Database db = new DatabaseBuilder(testDb.getFile()) + .setReadOnly(true).setIgnoreBrokenSystemCatalogIndex(true).open()) { + Table test = db.getTable("Table1"); + assertNotNull(test); + verifyFinderType(db, "FallbackTableFinder"); + } + try (Database db = openMem(testDb)) { + Table test = db.getTable("Table1"); + assertNotNull(test); + verifyFinderType(db, "DefaultTableFinder"); + } + } + + private static void verifyFinderType(Database db, String clazzName) + throws Exception{ + java.lang.reflect.Field f = db.getClass().getDeclaredField("_tableFinder"); + f.setAccessible(true); + Object finder = f.get(db); + assertNotNull(finder); + assertEquals(clazzName, finder.getClass().getSimpleName()); + } + private static void checkRawValue(String expected, Object val) { if(expected != null) { diff --git a/src/test/java/com/healthmarketscience/jackcess/IndexTest.java b/src/test/java/com/healthmarketscience/jackcess/IndexTest.java index a312ae8..0ddf171 100644 --- a/src/test/java/com/healthmarketscience/jackcess/IndexTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/IndexTest.java @@ -342,7 +342,7 @@ public class IndexTest extends TestCase { if(expectedSuccess) { assertNull(failure); } else { - assertTrue(failure != null); + assertNotNull(failure); assertTrue(failure.getMessage().contains("uniqueness")); } } diff --git a/src/test/java/com/healthmarketscience/jackcess/TestUtil.java b/src/test/java/com/healthmarketscience/jackcess/TestUtil.java index 7d1d6b3..97139b8 100644 --- a/src/test/java/com/healthmarketscience/jackcess/TestUtil.java +++ b/src/test/java/com/healthmarketscience/jackcess/TestUtil.java @@ -200,10 +200,14 @@ public class TestUtil final Database db = new DatabaseBuilder(file).setReadOnly(readOnly) .setAutoSync(getTestAutoSync()).setChannel(channel) .setCharset(charset).open(); - Assert.assertEquals("Wrong JetFormat.", - DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), - ((DatabaseImpl)db).getFormat()); - Assert.assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat()); + if(fileFormat != null) { + Assert.assertEquals( + "Wrong JetFormat.", + DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), + ((DatabaseImpl)db).getFormat()); + Assert.assertEquals( + "Wrong FileFormat.", fileFormat, db.getFileFormat()); + } return db; } |