summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2006-11-10 21:30:56 +0000
committerBrian S. O'Neill <bronee@gmail.com>2006-11-10 21:30:56 +0000
commit04c13ea008385e4fea297367086aeeb771b62a5f (patch)
tree015867dba6ab8edba2d2af2c9b91ddca92d698a6 /src/test/java
parent2a03544e9ebf233c57552f7e29280d018f7a8a42 (diff)
Fix resync corruption skip/repair logic.
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/amazon/carbonado/repo/replicated/TestRepair.java35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/test/java/com/amazon/carbonado/repo/replicated/TestRepair.java b/src/test/java/com/amazon/carbonado/repo/replicated/TestRepair.java
index 4a58746..c993e4b 100644
--- a/src/test/java/com/amazon/carbonado/repo/replicated/TestRepair.java
+++ b/src/test/java/com/amazon/carbonado/repo/replicated/TestRepair.java
@@ -27,9 +27,11 @@ import junit.framework.TestSuite;
import com.amazon.carbonado.CorruptEncodingException;
import com.amazon.carbonado.Cursor;
import com.amazon.carbonado.OptimisticLockException;
+import com.amazon.carbonado.PersistException;
import com.amazon.carbonado.Repository;
import com.amazon.carbonado.RepositoryBuilder;
import com.amazon.carbonado.Storage;
+import com.amazon.carbonado.Trigger;
import com.amazon.carbonado.UniqueConstraintException;
import com.amazon.carbonado.capability.ResyncCapability;
@@ -362,6 +364,14 @@ public class TestRepair extends TestCase {
}
public void testCorruptEntry() throws Exception {
+ testCorruptEntry(false);
+ }
+
+ public void testCorruptEntryPreventDelete() throws Exception {
+ testCorruptEntry(true);
+ }
+
+ private void testCorruptEntry(boolean preventDelete) throws Exception {
// Close and open repository again, this time on disk. We need to close
// and re-open the repository as part of the test.
String[] locations = reOpenPersistent(null);
@@ -479,11 +489,34 @@ public class TestRepair extends TestCase {
}
// Resync to repair.
+
+ Trigger trigger = null;
+ if (preventDelete) {
+ // The resync will try to delete the corrupt replica entries, but
+ // this trigger will cause the delete to fail. Instead, the resync
+ // will skip over these entries instead of crashing outright.
+ trigger = new Trigger() {
+ @Override
+ public Object beforeDelete(Object s) throws PersistException {
+ throw new PersistException("Cannot delete me!");
+ }
+ };
+ storage0.addTrigger(trigger);
+ }
+
ResyncCapability cap = mReplicated.getCapability(ResyncCapability.class);
cap.resync(type0, 1.0, null);
- // Verify records can be read out now.
+ if (preventDelete) {
+ // If this point is reached, the resync didn't crash, but it hasn't
+ // actually repaired the broken records. Remove the trigger and do
+ // the resync again.
+ storage0.removeTrigger(trigger);
+ cap.resync(type0, 1.0, null);
+ }
+
{
+ // Verify records can be read out now.
Cursor<? extends StorableTestMinimal> cursor = storage0.query().fetch();
int actual = 0;
while (cursor.hasNext()) {