use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method changeStoreRecordVersions.
@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);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method fieldChangedFromMessageToGroup.
@Test
public void fieldChangedFromMessageToGroup() {
// The message and group types here have the same form, but messages and groups are serialized differently
assertInvalid("field type changed", TestRecordsWithHeaderProto.getDescriptor(), TestHeaderAsGroupProto.getDescriptor());
assertInvalid("field type changed", TestHeaderAsGroupProto.getDescriptor(), TestRecordsWithHeaderProto.getDescriptor());
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecordsWithHeaderProto.getDescriptor());
metaDataBuilder.getRecordType("MyRecord").setPrimaryKey(Key.Expressions.field("header").nest(Key.Expressions.concatenateFields("path", "rec_no")));
RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
RecordMetaData metaData2 = replaceRecordsDescriptor(metaData1, TestHeaderAsGroupProto.getDescriptor());
assertInvalid("field type changed", metaData1, metaData2);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method addRecordTypeWithUniversalIndex.
@Test
public void addRecordTypeWithUniversalIndex() {
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
metaDataBuilder.addUniversalIndex(new Index("rec_no", "rec_no"));
RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
assertNotNull(metaData1.getUniversalIndex("rec_no"));
// Keep the index universal
RecordMetaData metaData2 = addNewRecordType(metaData1);
assertNotNull(metaData2.getUniversalIndex("rec_no"));
validator.validate(metaData1, metaData2);
// Make the index a multi-type index on the original record types
RecordMetaData metaData3 = replaceIndex(metaData2, "rec_no", indexProto -> indexProto.toBuilder().addRecordType("MySimpleRecord").addRecordType("MyOtherRecord").build());
MetaDataException e = assertThrows(MetaDataException.class, () -> metaData3.getUniversalIndex("rec_no"));
assertThat(e.getMessage(), containsString("Index rec_no not defined"));
assertInvalid("new index removes record type", metaData2, metaData3);
validator.validate(metaData1, metaData3);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method swapIsomorphicRecordTypesWithExplicitKeys.
@Test
public void swapIsomorphicRecordTypesWithExplicitKeys() {
FileDescriptor updatedFile = mutateFile(fileBuilder -> {
DescriptorProtos.DescriptorProto newMessageType = fileBuilder.getMessageTypeList().stream().filter(messageType -> messageType.getName().equals("MyOtherRecord")).findFirst().get().toBuilder().setName("MyOtherOtherRecord").build();
fileBuilder.addMessageType(newMessageType);
fileBuilder.getMessageTypeBuilderList().forEach(messageType -> {
if (messageType.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
messageType.addField(DescriptorProtos.FieldDescriptorProto.newBuilder().setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL).setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE).setTypeName("MyOtherOtherRecord").setName("_MyOtherOtherRecord").setNumber(messageType.getFieldList().stream().mapToInt(DescriptorProtos.FieldDescriptorProto::getNumber).max().orElse(0) + 1));
}
});
});
RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(updatedFile);
metaDataBuilder.getRecordType("MyOtherRecord").setRecordTypeKey("other");
metaDataBuilder.getRecordType("MyOtherOtherRecord").setRecordTypeKey("other_other");
RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
assertEquals("other", metaData1.getRecordType("MyOtherRecord").getRecordTypeKey());
assertEquals("other_other", metaData1.getRecordType("MyOtherOtherRecord").getRecordTypeKey());
// Swap the definitions in the union descriptor
FileDescriptor secondFile = mutateFile(updatedFile, fileBuilder -> fileBuilder.getMessageTypeBuilderList().forEach(messageType -> {
if (messageType.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
messageType.getFieldBuilderList().forEach(field -> {
if (field.getName().equals("_MyOtherRecord")) {
field.setTypeName("MyOtherOtherRecord");
} else if (field.getName().equals("_MyOtherOtherRecord")) {
field.setTypeName("MyOtherRecord");
}
});
}
}));
RecordMetaData metaData2 = replaceRecordsDescriptor(metaData1, secondFile);
assertEquals("other", metaData2.getRecordType("MyOtherRecord").getRecordTypeKey());
assertEquals("other_other", metaData2.getRecordType("MyOtherOtherRecord").getRecordTypeKey());
assertInvalid("record type key changed", metaData1, metaData2);
// Swap the definitions in the record type descriptor list
RecordMetaData metaData3 = replaceRecordsDescriptor(metaData1, secondFile, metaDataProtoBuilder -> metaDataProtoBuilder.getRecordTypesBuilderList().forEach(recordType -> {
if (recordType.getName().equals("MyOtherRecord")) {
recordType.setName("MyOtherOtherRecord");
} else if (recordType.getName().equals("MyOtherOtherRecord")) {
recordType.setName("MyOtherRecord");
}
}));
assertEquals("other", metaData3.getRecordType("MyOtherOtherRecord").getRecordTypeKey());
assertEquals("other_other", metaData3.getRecordType("MyOtherRecord").getRecordTypeKey());
validator.validate(metaData1, metaData3);
// Verify that using "update records" updates the record type keys
RecordMetaDataBuilder metaDataBuilder4 = RecordMetaData.newBuilder().setRecords(metaData1.toProto());
metaDataBuilder4.updateRecords(secondFile);
RecordMetaData metaData4 = metaDataBuilder4.getRecordMetaData();
assertEquals("other", metaData4.getRecordType("MyOtherOtherRecord").getRecordTypeKey());
assertEquals("other_other", metaData4.getRecordType("MyOtherRecord").getRecordTypeKey());
validator.validate(metaData1, metaData4);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method changeFormerIndexName.
@Test
public void changeFormerIndexName() {
RecordMetaDataBuilder metaData1Builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
metaData1Builder.removeIndex("MySimpleRecord$str_value_indexed");
RecordMetaData metaData1 = metaData1Builder.getRecordMetaData();
RecordMetaDataProto.MetaData.Builder metaData2ProtoBuilder = metaData1.toProto().toBuilder().setVersion(metaData1.getVersion() + 1);
metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).setFormerName("some_other_name"));
RecordMetaData metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
assertInvalid("name of former index differs from prior version", metaData1, metaData2);
metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).clearFormerName());
metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
assertInvalid("name of former index differs from prior version", metaData1, metaData2);
// For existing former indexes, changing the name is not allowed even with the laxer validation option
MetaDataEvolutionValidator laxerValidator = MetaDataEvolutionValidator.newBuilder().setAllowMissingFormerIndexNames(true).build();
assertInvalid("name of former index differs from prior version", laxerValidator, metaData1, metaData2);
}
Aggregations