Skip to content

Commit

Permalink
Added testcase for schema evolution check
Browse files Browse the repository at this point in the history
  • Loading branch information
abh1nay committed Oct 16, 2012
1 parent 5aacdc7 commit 1524721
Showing 1 changed file with 37 additions and 0 deletions.
Expand Up @@ -34,6 +34,19 @@ private static Object readVersion0(Map<Integer, String> versions, byte[] version

}

private static byte[] writeVersion0with1Present(Map<Integer, String> versions, Schema s0) {

GenericData.Record record = new GenericData.Record(s0);
record.put("original", new Utf8("Abhinay"));
AvroVersionedGenericSerializer serializer = new AvroVersionedGenericSerializer(versions);
return serializer.toBytes(record);

}

/*
* This tests if a client tries to deserialize an object created using an
* old schema is successful or not
*/
@Test
public void testAvroSchemaEvolution() throws IOException {

Expand All @@ -55,4 +68,28 @@ public void testAvroSchemaEvolution() throws IOException {
GenericData.Record record = (Record) readVersion0(versions, versionZeroBytes);

}

/*
* This tests if a client tries to serialize an object created using an old
* schema is successful or not
*/
@Test
public void testAvroSchemaEvolutionWrite() throws IOException {

String versionZero = "{\"type\": \"record\", \"name\": \"myrec\",\"fields\": [{ \"name\": \"original\", \"type\": \"string\" }]}";

String versionOne = "{\"type\": \"record\", \"name\": \"myrec\",\"fields\": [{ \"name\": \"original\", \"type\": \"string\" } ,"
+ "{ \"name\": \"new-field\", \"type\": \"string\", \"default\":\"\" }]}";

Schema s0 = Schema.parse(versionZero);
Schema s1 = Schema.parse(versionOne);

Map<Integer, String> versions = new HashMap<Integer, String>();

versions.put(0, versionZero);
versions.put(1, versionOne);

byte[] versionZeroBytes = writeVersion0with1Present(versions, s0);

}
}

0 comments on commit 1524721

Please sign in to comment.