From 5f8479d8d71460c9f25fc1f2b2a69a754cfc0451 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 3 Jan 2011 18:10:28 +0000 Subject: Support serialization of corrupt storable. --- .../carbonado/repo/replicated/TestRepair.java | 40 +++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) 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 type0 = + final Class type0 = TestLayout.defineStorable(recordName, 1, TypeDesc.INT); Class 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. -- cgit v1.2.3