use of com.apple.foundationdb.record.evolution.TestRecordsEnumProtoV3 in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTestV3 method enumChanged.
/**
* Enums are different with proto3 syntax. In particular, they require one of their values have value 0,
* and they introduce an "UNKNOWN" value all of the time.
*/
@Test
public void enumChanged() {
RecordMetaData metaData1 = RecordMetaData.build(TestRecordsEnumProtoV3.getDescriptor());
FileDescriptor updatedFile = mutateEnum(enumType -> enumType.addValue(DescriptorProtos.EnumValueDescriptorProto.newBuilder().setName("X_LARGE").setNumber(4)));
assertNotNull(updatedFile.findMessageTypeByName("MyShapeRecord").findEnumTypeByName("Size").findValueByName("X_LARGE"));
RecordMetaData metaData2 = replaceRecordsDescriptor(metaData1, updatedFile);
MetaDataEvolutionValidator.getDefaultInstance().validate(metaData1, metaData2);
updatedFile = mutateEnum(enumType -> enumType.getValueBuilderList().forEach(enumValue -> {
if (enumValue.getName().equals("SMALL")) {
enumValue.setName("PETIT");
}
}));
assertNotNull(updatedFile.findMessageTypeByName("MyShapeRecord").findEnumTypeByName("Size").findValueByName("PETIT"));
metaData2 = replaceRecordsDescriptor(metaData1, updatedFile);
MetaDataEvolutionValidator.getDefaultInstance().validate(metaData1, metaData2);
updatedFile = mutateEnum(enumType -> enumType.removeValue(enumType.getValueCount() - 1));
assertNull(updatedFile.findMessageTypeByName("MyShapeRecord").findEnumTypeByName("Size").findValueByName("LARGE"));
metaData2 = replaceRecordsDescriptor(metaData1, updatedFile);
assertInvalid("enum removes value", metaData1, metaData2);
}
Aggregations