Search in sources :

Example 1 with TestRecordsEnumProtoV3

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);
}
Also used : DescriptorProtos(com.google.protobuf.DescriptorProtos) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DynamicMessage(com.google.protobuf.DynamicMessage) TestRecords3Proto(com.apple.foundationdb.record.TestRecords3Proto) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TestRecords3ProtoV3(com.apple.foundationdb.record.evolution.TestRecords3ProtoV3) TestRecordsNestedProto3(com.apple.foundationdb.record.evolution.TestRecordsNestedProto3) TestRecordsNestedProto2(com.apple.foundationdb.record.evolution.TestRecordsNestedProto2) TestRecordsEnumProtoV3(com.apple.foundationdb.record.evolution.TestRecordsEnumProtoV3) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Nonnull(javax.annotation.Nonnull) MetaDataEvolutionValidatorTest.replaceRecordsDescriptor(com.apple.foundationdb.record.metadata.MetaDataEvolutionValidatorTest.replaceRecordsDescriptor) TestRecords1ImportedProto(com.apple.foundationdb.record.evolution.TestRecords1ImportedProto) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) TestNestedProto3(com.apple.foundationdb.record.evolution.TestNestedProto3) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Message(com.google.protobuf.Message) MetaDataEvolutionValidatorTest.assertInvalid(com.apple.foundationdb.record.metadata.MetaDataEvolutionValidatorTest.assertInvalid) Matchers.is(org.hamcrest.Matchers.is) MetaDataEvolutionValidatorTest.mutateFile(com.apple.foundationdb.record.metadata.MetaDataEvolutionValidatorTest.mutateFile) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

RecordMetaData (com.apple.foundationdb.record.RecordMetaData)1 RecordMetaDataBuilder (com.apple.foundationdb.record.RecordMetaDataBuilder)1 TestRecords1Proto (com.apple.foundationdb.record.TestRecords1Proto)1 TestRecords3Proto (com.apple.foundationdb.record.TestRecords3Proto)1 TestNestedProto3 (com.apple.foundationdb.record.evolution.TestNestedProto3)1 TestRecords1ImportedProto (com.apple.foundationdb.record.evolution.TestRecords1ImportedProto)1 TestRecords3ProtoV3 (com.apple.foundationdb.record.evolution.TestRecords3ProtoV3)1 TestRecordsEnumProtoV3 (com.apple.foundationdb.record.evolution.TestRecordsEnumProtoV3)1 TestRecordsNestedProto2 (com.apple.foundationdb.record.evolution.TestRecordsNestedProto2)1 TestRecordsNestedProto3 (com.apple.foundationdb.record.evolution.TestRecordsNestedProto3)1 MetaDataEvolutionValidatorTest.assertInvalid (com.apple.foundationdb.record.metadata.MetaDataEvolutionValidatorTest.assertInvalid)1 MetaDataEvolutionValidatorTest.mutateFile (com.apple.foundationdb.record.metadata.MetaDataEvolutionValidatorTest.mutateFile)1 MetaDataEvolutionValidatorTest.replaceRecordsDescriptor (com.apple.foundationdb.record.metadata.MetaDataEvolutionValidatorTest.replaceRecordsDescriptor)1 DescriptorProtos (com.google.protobuf.DescriptorProtos)1 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)1 FileDescriptor (com.google.protobuf.Descriptors.FileDescriptor)1 DynamicMessage (com.google.protobuf.DynamicMessage)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Message (com.google.protobuf.Message)1 Consumer (java.util.function.Consumer)1