RecordDataSchema prevGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
List<RecordDataSchema.Field> oldFields = new ArrayList<RecordDataSchema.Field>();
RecordDataSchema.Field id = new RecordDataSchema.Field(new LongDataSchema());
id.setName("id", errors);
oldFields.add(id);
RecordDataSchema.Field message = new RecordDataSchema.Field(new StringDataSchema());
message.setName("message", errors);
oldFields.add(message);
RecordDataSchema.Field toneField = new RecordDataSchema.Field(tone);
toneField.setName("tone", errors);
toneField.setOptional(true);
oldFields.add(toneField);
prevGreeting.setFields(oldFields, errors);
prevSchemaResolver.bindNameToSchema(toneName, tone, null);
prevSchemaResolver.bindNameToSchema(greetingName, prevGreeting, null);
// compat greeting has removed optional field "tone" and added a new optional field "newField"
RecordDataSchema compatGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
List<RecordDataSchema.Field> compatFields = new ArrayList<RecordDataSchema.Field>();
compatFields.add(id);
compatFields.add(message);
RecordDataSchema.Field newCompatField = new RecordDataSchema.Field(new StringDataSchema());
newCompatField.setName("newField", errors);
newCompatField.setOptional(true);
compatFields.add(newCompatField);
compatGreeting.setFields(compatFields, errors);
compatSchemaResolver.bindNameToSchema(toneName, tone, null);
compatSchemaResolver.bindNameToSchema(greetingName, compatGreeting, null);
// incompat greeting has removed non-optional field "message",
// has changed the type of "id" to string,
// and added a new non-optional field "newField"
RecordDataSchema incompatGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
List<RecordDataSchema.Field> incompatFields = new ArrayList<RecordDataSchema.Field>();
RecordDataSchema.Field incompatId = new RecordDataSchema.Field(new StringDataSchema());
incompatId.setName("id", errors);
oldFields.add(incompatId);
incompatFields.add(incompatId);
incompatFields.add(toneField);
RecordDataSchema.Field newIncompatField = new RecordDataSchema.Field(new StringDataSchema());
newIncompatField.setName("newField", errors);
incompatFields.add(newIncompatField);
incompatGreeting.setFields(incompatFields, errors);
incompatSchemaResolver.bindNameToSchema(toneName, tone, null);