diff options
| author | Brian S. O'Neill <bronee@gmail.com> | 2009-03-24 19:15:57 +0000 | 
|---|---|---|
| committer | Brian S. O'Neill <bronee@gmail.com> | 2009-03-24 19:15:57 +0000 | 
| commit | ce6091edd184fb10b8cd020b5b95797e0340d529 (patch) | |
| tree | c10f35f263f280043780777abd710de17b2426be /src/test/java/com/amazon/carbonado/repo | |
| parent | 855ca3029ab4afc2a5766fd9198c3b3a93f7b594 (diff) | |
Derived index update must tolerate inconsistencies.
Diffstat (limited to 'src/test/java/com/amazon/carbonado/repo')
| -rw-r--r-- | src/test/java/com/amazon/carbonado/repo/indexed/TestIndexRepair.java | 45 | 
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);
  | 
