summaryrefslogtreecommitdiff
path: root/src/test/java/com/amazon/carbonado/repo/indexed
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/amazon/carbonado/repo/indexed')
-rw-r--r--src/test/java/com/amazon/carbonado/repo/indexed/TestIndexRepair.java45
1 files changed, 43 insertions, 2 deletions
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<WithJoinIndex> storage = repo.storageFor(WithJoinIndex.class);
+ Storage<WithJoinIndex.Basic> 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);