use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method newTypeWithoutSinceVersion.
@Test
public void newTypeWithoutSinceVersion() {
RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
RecordMetaData metaData2 = addNewRecordType(metaData1, RecordMetaDataProto.RecordType.Builder::clearSinceVersion);
assertInvalid("new record type is missing since version", metaData1, metaData2);
MetaDataEvolutionValidator laxerValidator = MetaDataEvolutionValidator.newBuilder().setAllowNoSinceVersion(true).build();
laxerValidator.validate(metaData1, metaData2);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method rankLevelsChanged.
@Test
public void rankLevelsChanged() {
final String indexName = "MySimpleRecord$rank(num_value_2)";
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
metaDataBuilder.addIndex("MySimpleRecord", new Index(indexName, Key.Expressions.field("num_value_2").ungrouped(), IndexTypes.RANK));
RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
validateIndexMutation("rank levels changed", metaData1, indexName, indexProto -> changeOption(indexProto, IndexOptions.RANK_NLEVELS, "4"));
validateIndexMutation("rank levels changed", metaData1, indexName, indexProto -> changeOption(indexProto, IndexOptions.RANK_NLEVELS, "" + RankedSet.MAX_LEVELS));
// Setting the default explicitly is fine
RecordMetaData metaData2 = replaceIndex(metaData1, indexName, indexProto -> changeOption(indexProto, IndexOptions.RANK_NLEVELS, "" + RankedSet.DEFAULT_LEVELS));
validator.validate(metaData1, metaData2);
RecordMetaData metaData3 = replaceIndex(metaData2, indexName, this::clearOptions);
validator.validate(metaData2, metaData3);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method indexAddedVersionChanged.
@Test
public void indexAddedVersionChanged() {
RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
RecordMetaData metaData2 = replaceIndex(metaData1, "MySimpleRecord$str_value_indexed", indexProto -> indexProto.toBuilder().setAddedVersion(metaData1.getVersion() + 1).setLastModifiedVersion(metaData1.getVersion() + 1).build());
assertInvalid("new index added version does not match old index added version", metaData1, metaData2);
metaData2 = replaceIndex(metaData2, "MySimpleRecord$str_value_indexed", indexProto -> indexProto.toBuilder().setAddedVersion(indexProto.getAddedVersion() - 1).build());
assertInvalid("new index added version does not match old index added version", metaData1, metaData2);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method changeReplacedByIndex.
@Test
public void changeReplacedByIndex() {
RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
RecordMetaData metaData2 = replaceIndex(metaData1, "MySimpleRecord$str_value_indexed", indexProto -> changeOption(indexProto, IndexOptions.REPLACED_BY_OPTION_PREFIX, "MySimpleRecord$num_value_3_indexed"));
assertEquals(Collections.singletonList("MySimpleRecord$num_value_3_indexed"), metaData2.getIndex("MySimpleRecord$str_value_indexed").getReplacedByIndexNames());
validator.validate(metaData1, metaData2);
RecordMetaData metaData3 = replaceIndex(metaData2, "MySimpleRecord$str_value_indexed", this::clearOptions);
assertEquals(Collections.emptyList(), metaData3.getIndex("MySimpleRecord$str_value_indexed").getReplacedByIndexNames());
validator.validate(metaData2, metaData3);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method changeRecordTypeName.
@Test
public void changeRecordTypeName() {
final MetaDataEvolutionValidator renameDisallowingValidator = MetaDataEvolutionValidator.newBuilder().setDisallowTypeRenames(true).build();
// Update the record type name, but don't update any references in indexes
FileDescriptor updatedFile = mutateFile(fileBuilder -> fileBuilder.getMessageTypeBuilderList().forEach(messageType -> {
if (messageType.getName().equals("MyOtherRecord")) {
messageType.setName("MyOtherOtherRecord");
} else if (messageType.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
messageType.getFieldBuilderList().forEach(field -> {
if (field.getName().equals("_MyOtherRecord")) {
field.setName("_MyOtherOtherRecord");
field.setTypeName("MyOtherOtherRecord");
}
});
}
}));
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
metaDataBuilder.addIndex("MyOtherRecord", "num_value_3_indexed");
RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
MetaDataException e = assertThrows(MetaDataException.class, () -> replaceRecordsDescriptor(metaData1, updatedFile));
assertThat(e.getMessage(), containsString("Unknown record type MyOtherRecord"));
validator.validateUnion(metaData1.getUnionDescriptor(), updatedFile.findMessageTypeByName(RecordMetaDataBuilder.DEFAULT_UNION_NAME));
// Changes the record type definition but not the indexes
e = assertThrows(MetaDataException.class, () -> replaceRecordsDescriptor(metaData1, updatedFile, protoBuilder -> protoBuilder.getRecordTypesBuilderList().forEach(recordType -> {
if (recordType.getName().equals("MyOtherRecord")) {
recordType.setName("MyOtherOtherRecord");
}
})));
assertThat(e.getMessage(), containsString("Unknown record type MyOtherRecord"));
// This should be allowed because it replaces all index definitions with the new record type as well
RecordMetaData metaData3 = replaceRecordsDescriptor(metaData1, updatedFile, protoBuilder -> {
protoBuilder.getRecordTypesBuilderList().forEach(recordType -> {
if (recordType.getName().equals("MyOtherRecord")) {
recordType.setName("MyOtherOtherRecord");
}
});
protoBuilder.getIndexesBuilderList().forEach(index -> {
List<String> recordTypes = new ArrayList<>(index.getRecordTypeList());
recordTypes.replaceAll(recordType -> recordType.equals("MyOtherRecord") ? "MyOtherOtherRecord" : recordType);
index.clearRecordType();
index.addAllRecordType(recordTypes);
});
});
assertEquals(Collections.singletonList(metaData3.getRecordType("MyOtherOtherRecord")), metaData3.recordTypesForIndex(metaData3.getIndex("MyOtherRecord$num_value_3_indexed")));
validator.validate(metaData1, metaData3);
assertInvalid("record type name changed", renameDisallowingValidator, metaData1, metaData3);
// Validate that calling update records with the new file descriptor produces a valid evolution
RecordMetaDataBuilder metaDataBuilder4 = RecordMetaData.newBuilder().setRecords(metaData1.toProto());
metaDataBuilder4.updateRecords(updatedFile);
RecordMetaData metaData4 = metaDataBuilder4.getRecordMetaData();
assertEquals(Collections.singletonList(metaData4.getRecordType("MyOtherOtherRecord")), metaData4.recordTypesForIndex(metaData4.getIndex("MyOtherRecord$num_value_3_indexed")));
validator.validate(metaData1, metaData4);
assertInvalid("record type name changed", renameDisallowingValidator, metaData1, metaData4);
}
Aggregations