MetaDataEvolutionValidator { public void validate(@Nonnull RecordMetaData oldMetaData, @Nonnull RecordMetaData newMetaData) { if (oldMetaData.getVersion() > newMetaData.getVersion() || !allowNoVersionChange && oldMetaData.getVersion() == newMetaData.getVersion()) { throw new MetaDataException("new meta-data does not have newer version than old meta-data", LogMessageKeys.OLD_VERSION, oldMetaData.getVersion(), LogMessageKeys.NEW_VERSION, newMetaData.getVersion()); } validateSchemaOptions(oldMetaData, newMetaData); validateUnion(oldMetaData.getUnionDescriptor(), newMetaData.getUnionDescriptor()); Map<String, String> typeRenames = getTypeRenames(oldMetaData.getUnionDescriptor(), newMetaData.getUnionDescriptor()); validateRecordTypes(oldMetaData, newMetaData, typeRenames); validateCurrentAndFormerIndexes(oldMetaData, newMetaData, typeRenames); } private  MetaDataEvolutionValidator(); private  MetaDataEvolutionValidator(@Nonnull Builder builder); void validate(@Nonnull RecordMetaData oldMetaData, @Nonnull RecordMetaData newMetaData); @SuppressWarnings("PMD.CompareObjectsWithEquals") void validateUnion(@Nonnull Descriptor oldUnionDescriptor, @Nonnull Descriptor newUnionDescriptor); @Nonnull IndexMaintainerRegistry getIndexMaintainerRegistry(); boolean allowsNoVersionChange(); boolean allowsNoSinceVersion(); boolean allowsIndexRebuilds(); boolean allowsMissingFormerIndexNames(); boolean allowsOlderFormerIndexAddedVersions(); boolean allowsUnsplitToSplit(); boolean disallowsTypeRenames(); @Nonnull Builder asBuilder(); @Nonnull static Builder newBuilder(); @Nonnull static MetaDataEvolutionValidator getDefaultInstance();  }
@Test public void changeStoreRecordVersions() { RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor()); RecordMetaData metaData2 = RecordMetaData.build(metaData1.toProto().toBuilder() .setVersion(metaData1.getVersion() + 1) .setStoreRecordVersions(!metaData1.isStoreRecordVersions()) .build() ); assertNotEquals(metaData1.isStoreRecordVersions(), metaData2.isStoreRecordVersions()); validator.validate(metaData1, metaData2); RecordMetaData metaData3 = RecordMetaData.build(metaData2.toProto().toBuilder() .setVersion(metaData2.getVersion() + 1) .setStoreRecordVersions(!metaData2.isStoreRecordVersions()) .build() ); assertNotEquals(metaData2.isStoreRecordVersions(), metaData3.isStoreRecordVersions()); validator.validate(metaData2, metaData3); }
@Test public void indexRecordTypeAdded() { RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor()); validateIndexMutation("new index adds record type that is not newer than old meta-data", metaData1, "MySimpleRecord$num_value_3_indexed", indexProto -> indexProto.toBuilder().addRecordType("MyOtherRecord").build() ); RecordMetaData tempMetaData = addNewRecordType(metaData1); RecordMetaData metaData2 = replaceIndex(tempMetaData, "MySimpleRecord$num_value_3_indexed", indexProto -> indexProto.toBuilder().addRecordType("NewRecord").build()); validator.validate(metaData1, metaData2); assertInvalid("new index adds record type that is not newer than old meta-data", tempMetaData, metaData2); }
@Test public void uniquenessConstraintChanged() { RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor()); validateIndexMutation("index adds uniqueness constraint", metaData1, "MySimpleRecord$str_value_indexed", this::makeUnique); RecordMetaData metaData2 = replaceIndex(metaData1, "MySimpleRecord$str_value_indexed", this::makeUnique); RecordMetaData metaData3 = replaceIndex(metaData2, "MySimpleRecord$str_value_indexed", this::clearOptions); validator.validate(metaData2, metaData3); RecordMetaData metaData4 = replaceIndex(metaData2, "MySimpleRecord$str_value_indexed", indexProto -> changeOption(indexProto, IndexOptions.UNIQUE_OPTION, "false")); validator.validate(metaData2, metaData4); }
@Test public void allowedForQueriesChanged() { RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor()); RecordMetaData metaData2 = replaceIndex(metaData1, "MySimpleRecord$str_value_indexed", indexProto -> changeOption(indexProto, IndexOptions.ALLOWED_FOR_QUERY_OPTION, "false")); validator.validate(metaData1, metaData2); RecordMetaData metaData3 = replaceIndex(metaData2, "MySimpleRecord$str_value_indexed", indexProto -> changeOption(indexProto, IndexOptions.ALLOWED_FOR_QUERY_OPTION, "true")); validator.validate(metaData2, metaData3); RecordMetaData metaData4 = replaceIndex(metaData3, "MySimpleRecord$str_value_indexed", this::clearOptions); validator.validate(metaData3, metaData4); }
@Test public void unknownOptionChanged() { RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor()); validateIndexMutation("index option changed", metaData1, "MySimpleRecord$str_value_indexed", indexProto -> changeOption(indexProto, "dummyOption", "dummyValue")); RecordMetaData metaData2 = replaceIndex(metaData1, "MySimpleRecord$str_value_indexed", indexProto -> makeUnique(changeOption(indexProto, "dummyOption", "dummyValue"))); RecordMetaData metaData3 = replaceIndex(metaData2, "MySimpleRecord$str_value_indexed", indexProto -> changeOption(indexProto, IndexOptions.UNIQUE_OPTION, null)); validator.validate(metaData2, metaData3); validateIndexMutation("index option changed", metaData3, "MySimpleRecord$str_value_indexed", indexProto -> changeOption(indexProto, "dummyOption", "dummyValue2")); }