use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method indexKeyExpressionChanged.
@Test
public void indexKeyExpressionChanged() {
RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
validateIndexMutation("index key expression changed", metaData1, "MySimpleRecord$str_value_indexed", indexProto -> indexProto.toBuilder().setRootExpression(Key.Expressions.field("num_value_2").toKeyExpression()).build());
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method nestedTypeChangesFieldName.
@Test
public void nestedTypeChangesFieldName() {
FileDescriptor updatedFile = mutateField("HeaderRecord", "num", TestRecordsWithHeaderProto.getDescriptor(), field -> field.setName("numb"));
assertInvalid("field renamed", TestRecordsWithHeaderProto.getDescriptor(), updatedFile);
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, updatedFile);
assertInvalid("field renamed", metaData1, metaData2);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method splitTypes.
/**
* Validate that changes to the union descriptor that differentiate two previously equivalent
* types--even if they have the same form--are disallowed. In theory, this could be allowed if
* the machinery to handle indexes were sophisticated enough. It would require that every index
* either be dropped or that all indexes that were previously defined on the combined record type
* are now defined on both types. It also requires that any indexes on record type be dropped.
*/
@Test
public void splitTypes() {
// Add a second "MyOtherRecord" to the union descriptor
FileDescriptor updatedDescriptor = mutateFile(fileBuilder -> fileBuilder.getMessageTypeBuilderList().forEach(message -> {
if (message.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
message.addField(DescriptorProtos.FieldDescriptorProto.newBuilder().setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL).setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE).setTypeName("MyOtherRecord").setName("_MyOtherOtherRecord").setNumber(message.getFieldList().stream().mapToInt(DescriptorProtos.FieldDescriptorProto::getNumber).max().orElse(0) + 1));
}
}));
RecordMetaData metaData1 = RecordMetaData.build(updatedDescriptor);
assertThat(metaData1.getRecordTypes().keySet(), containsInAnyOrder("MySimpleRecord", "MyOtherRecord"));
FileDescriptor secondDescriptor = mutateFile(updatedDescriptor, fileBuilder -> {
DescriptorProtos.DescriptorProto newMessageType = fileBuilder.getMessageTypeList().stream().filter(message -> message.getName().equals("MyOtherRecord")).findFirst().get().toBuilder().setName("MyOtherOtherRecord").build();
fileBuilder.addMessageType(newMessageType);
fileBuilder.getMessageTypeBuilderList().forEach(message -> {
if (message.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
message.getFieldBuilderList().forEach(field -> {
if (field.getName().equals("_MyOtherOtherRecord")) {
field.setTypeName("MyOtherOtherRecord");
}
});
}
});
});
RecordMetaData metaData2 = replaceRecordsDescriptor(metaData1, secondDescriptor, metaDataProtoBuilder -> metaDataProtoBuilder.addRecordTypes(RecordMetaDataProto.RecordType.newBuilder().setName("MyOtherOtherRecord").setPrimaryKey(Key.Expressions.field("rec_no").toKeyExpression())));
assertThat(metaData2.getRecordTypes().keySet(), containsInAnyOrder("MySimpleRecord", "MyOtherRecord", "MyOtherOtherRecord"));
assertInvalid("record type corresponds to multiple types in new meta-data", metaData1, metaData2);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class MetaDataEvolutionValidatorTest method indexRecordTypeAdded.
@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());
// Add NewRecord as a record type to the existing meta-data and index and validate that this change is okay
// because the new record type is newer the old meta-data version.
RecordMetaData tempMetaData = addNewRecordType(metaData1);
RecordMetaData metaData2 = replaceIndex(tempMetaData, "MySimpleRecord$num_value_3_indexed", indexProto -> indexProto.toBuilder().addRecordType("NewRecord").build());
// valid if type and index change happen together
validator.validate(metaData1, metaData2);
assertInvalid("new index adds record type that is not newer than old meta-data", tempMetaData, metaData2);
}
use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.
the class FDBDatabaseRunnerTest method runAsyncDatabaseOperations.
@Test
public void runAsyncDatabaseOperations() {
// Tests to make sure the database operations are run and committed.
RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
testStoreAndRetrieveSimpleRecord(database, metaData);
try (FDBDatabaseRunner runner = database.newRunner()) {
runner.runAsync(context -> {
FDBRecordStore store = FDBRecordStore.newBuilder().setMetaDataProvider(metaData).setContext(context).setKeySpacePath(TestKeySpace.getKeyspacePath(FDBRecordStoreTestBase.PATH_OBJECTS)).build();
return store.deleteRecordAsync(Tuple.from(1066L));
}).join();
FDBStoredRecord<Message> retrieved2 = runner.runAsync(context -> {
FDBRecordStore store = FDBRecordStore.newBuilder().setMetaDataProvider(metaData).setContext(context).setKeySpacePath(TestKeySpace.getKeyspacePath(FDBRecordStoreTestBase.PATH_OBJECTS)).build();
return store.loadRecordAsync(Tuple.from(1066L));
}).join();
assertNull(retrieved2);
}
}
Aggregations