summaryrefslogtreecommitdiff
path: root/src/test/java/com
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2011-01-03 18:10:28 +0000
committerBrian S. O'Neill <bronee@gmail.com>2011-01-03 18:10:28 +0000
commit5f8479d8d71460c9f25fc1f2b2a69a754cfc0451 (patch)
tree797cea132bcff085b58e58fa04451ecf60b17f97 /src/test/java/com
parent4b4c0fcef239d6f877f490b084dd66819b393480 (diff)
Support serialization of corrupt storable.
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/amazon/carbonado/repo/replicated/TestRepair.java40
1 files changed, 39 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 efcc31c..b3a0028 100644
--- a/src/test/java/com/amazon/carbonado/repo/replicated/TestRepair.java
+++ b/src/test/java/com/amazon/carbonado/repo/replicated/TestRepair.java
@@ -18,6 +18,13 @@
package com.amazon.carbonado.repo.replicated;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -389,7 +396,7 @@ public class TestRepair extends TestCase {
final String recordName = "test.TheTestRecord";
- Class<? extends StorableTestMinimal> type0 =
+ final Class<? extends StorableTestMinimal> type0 =
TestLayout.defineStorable(recordName, 1, TypeDesc.INT);
Class<? extends StorableTestMinimal> type1 =
@@ -495,6 +502,37 @@ public class TestRepair extends TestCase {
}
fail();
} catch (CorruptEncodingException e) {
+ // Verify serialization of primary key storable.
+ assertNotNull(e.getStorableWithPrimaryKey());
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bout);
+ out.writeObject(e);
+ out.close();
+ byte[] bytes = bout.toByteArray();
+
+ ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
+
+ ObjectInputStream in = new ObjectInputStream(bin) {
+ // Special handling to load generated class.
+ @Override
+ protected Class<?> resolveClass(ObjectStreamClass desc)
+ throws IOException, ClassNotFoundException
+ {
+ if (desc.getName().equals(recordName)) {
+ return type0;
+ }
+ return super.resolveClass(desc);
+ }
+ };
+
+ CorruptEncodingException e2 = (CorruptEncodingException) in.readObject();
+
+ Storable s1 = e.getStorableWithPrimaryKey();
+ Storable s2 = e2.getStorableWithPrimaryKey();
+
+ assertFalse(s1 == s2);
+ assertTrue(s1.equalPrimaryKeys(s2));
+ assertTrue(s2.equalPrimaryKeys(s1));
}
// Resync to repair.