From ce6091edd184fb10b8cd020b5b95797e0340d529 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 24 Mar 2009 19:15:57 +0000 Subject: Derived index update must tolerate inconsistencies. --- .../carbonado/repo/indexed/TestIndexRepair.java | 45 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/test/java/com/amazon/carbonado/repo/indexed') diff --git a/src/test/java/com/amazon/carbonado/repo/indexed/TestIndexRepair.java b/src/test/java/com/amazon/carbonado/repo/indexed/TestIndexRepair.java index 852c064..2f6578b 100644 --- a/src/test/java/com/amazon/carbonado/repo/indexed/TestIndexRepair.java +++ b/src/test/java/com/amazon/carbonado/repo/indexed/TestIndexRepair.java @@ -27,6 +27,7 @@ import com.amazon.carbonado.*; import com.amazon.carbonado.repo.map.MapRepositoryBuilder; import com.amazon.carbonado.stored.StorableTestBasicCompoundIndexed; +import com.amazon.carbonado.stored.WithJoinIndex; /** * @@ -42,8 +43,6 @@ public class TestIndexRepair extends TestCase { return new TestSuite(TestIndexRepair.class); } - private Repository mRepository; - public TestIndexRepair(String name) { super(name); } @@ -52,6 +51,48 @@ public class TestIndexRepair extends TestCase { return TestUtilities.buildTempRepository("indexrepair", 1000000, true); } + public void test_derivedIndex() throws Exception { + Repository repo = buildTempRepository(); + + Storage storage = repo.storageFor(WithJoinIndex.class); + Storage storage2 = repo.storageFor(WithJoinIndex.Basic.class); + + WithJoinIndex obj; + WithJoinIndex.Basic obj2; + + obj2 = storage2.prepare(); + obj2.setId(1); + obj2.setIntProp(100); + obj2.insert(); + + obj = storage.prepare(); + obj.setId(2); + obj.setBasicId(1); + obj.insert(); + + assertEquals(100, obj.getIntProp()); + + WithJoinIndex.adjust = 5; + try { + // Index is inconsistent now. + obj = storage.query("intProp = ?").with(100).loadOne(); + assertEquals(100 + WithJoinIndex.adjust, obj.getIntProp()); + + // Inconsistency should not break update. + obj2 = obj.getBasic(); + obj2.setIntProp(123); + obj2.update(); + + obj = storage.query("intProp = ?").with(123 + WithJoinIndex.adjust).loadOne(); + assertEquals(123 + WithJoinIndex.adjust, obj.getIntProp()); + } finally { + WithJoinIndex.adjust = 0; + } + + repo.close(); + repo = null; + } + public void test_shouldInsert() throws Exception { Repository repo = buildTempRepository(); test_shouldInsert(repo); -- cgit v1.2.3