use of com.apple.foundationdb.record.metadata.MetaDataException in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreReplaceIndexTest method replacementIndexWithSelfCycleFails.
@Test
public void replacementIndexWithSelfCycleFails() {
try (FDBRecordContext context = openContext()) {
MetaDataException err = assertThrows(MetaDataException.class, () -> openSimpleRecordStore(context, metaDataBuilder -> {
final Index index = new Index("indexWithSelfReplacement", Key.Expressions.field("num_value_2"), IndexTypes.VALUE, Collections.singletonMap(IndexOptions.REPLACED_BY_OPTION_PREFIX, "indexWithSelfReplacement"));
metaDataBuilder.addIndex("MySimpleRecord", index);
}));
assertThat(err.getMessage(), containsString("Index indexWithSelfReplacement has replacement index indexWithSelfReplacement that itself has replacement indexes"));
}
}
use of com.apple.foundationdb.record.metadata.MetaDataException in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method withoutBumpingVersion.
@Test
public void withoutBumpingVersion() {
RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
metaDataStore.saveRecordMetaData(metaData);
MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.saveRecordMetaData(metaData));
assertThat(e.getMessage(), containsString("meta-data version must increase"));
context.commit();
}
}
use of com.apple.foundationdb.record.metadata.MetaDataException in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method identityRename.
/**
* Validate that the identity rename works and changes nothing (except the meta-data version).
*/
@Test
public void identityRename() {
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
metaDataStore.saveRecordMetaData(metaData);
context.commit();
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaDataProto.MetaData metaDataProto = metaDataStore.getRecordMetaData().toProto();
renameRecordType("MySimpleRecord", "MySimpleRecord");
assertThat(metaDataProto.getVersion(), lessThan(metaDataStore.getRecordMetaData().getVersion()));
RecordMetaDataProto.MetaData mutatedMetaDataProto = metaDataStore.getRecordMetaData().toProto().toBuilder().setVersion(metaDataProto.getVersion()).build();
assertEquals(metaDataProto, mutatedMetaDataProto);
MetaDataException e = assertThrows(MetaDataException.class, () -> renameRecordType("MyNonExistentRecord", "MyNonExistentRecord"));
assertEquals("No record type found with name MyNonExistentRecord", e.getMessage());
context.commit();
}
}
use of com.apple.foundationdb.record.metadata.MetaDataException in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method noUnionUpdateRecords.
@ParameterizedTest(name = "noUnionUpdateRecords [repeatSaveOrDoUpdate = {0}]")
@BooleanSource
public void noUnionUpdateRecords(boolean repeatSaveOrDoUpdate) {
int version;
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
metaDataStore.saveRecordMetaData(TestNoUnionProto.getDescriptor());
context.commit();
version = metaDataStore.getRecordMetaData().getVersion();
}
// Update records with an evolved proto. A new record type is added earlier in the file.
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertEquals(version, metaDataStore.getRecordMetaData().getVersion());
if (repeatSaveOrDoUpdate) {
metaDataStore.updateRecords(TestNoUnionEvolvedProto.getDescriptor());
} else {
metaDataStore.saveRecordMetaData(TestNoUnionEvolvedProto.getDescriptor());
}
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MyOtherRecord"));
assertEquals("_MySimpleRecord", metaDataStore.getRecordMetaData().getUnionDescriptor().findFieldByNumber(1).getName());
assertEquals("_MyOtherRecord", metaDataStore.getRecordMetaData().getUnionDescriptor().findFieldByNumber(2).getName());
assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
context.commit();
}
// Renaming a record type is not allowed
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
MetaDataException e;
if (repeatSaveOrDoUpdate) {
e = assertThrows(MetaDataException.class, () -> metaDataStore.updateRecords(TestNoUnionEvolvedRenamedRecordTypeProto.getDescriptor()));
} else {
e = assertThrows(MetaDataException.class, () -> metaDataStore.saveRecordMetaData(TestNoUnionEvolvedRenamedRecordTypeProto.getDescriptor()));
}
assertEquals("Record type MySimpleRecord removed", e.getMessage());
context.commit();
}
}
use of com.apple.foundationdb.record.metadata.MetaDataException in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method extensionRegistryWithUnionDescriptor.
@Test
public void extensionRegistryWithUnionDescriptor() {
try (FDBRecordContext context = fdb.openContext()) {
// test_records_3.proto relies on the union field annotation type
openMetaDataStore(context);
RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecords3Proto.getDescriptor());
builder.getRecordType("MyHierarchicalRecord").setPrimaryKey(Key.Expressions.concatenateFields("parent_path", "child_name"));
RecordMetaData metaData = builder.build();
metaDataStore.saveRecordMetaData(metaData);
context.commit();
}
try (FDBRecordContext context = fdb.openContext()) {
// Default registry parses options
openMetaDataStore(context);
RecordMetaData metaData = metaDataStore.getRecordMetaData();
assertNotSame(metaData.getUnionDescriptor(), TestRecords3Proto.UnionDescriptor.getDescriptor());
assertEquals(metaData.getUnionDescriptor().toProto(), TestRecords3Proto.UnionDescriptor.getDescriptor().toProto());
// Empty registry does not
openMetaDataStore(context);
metaDataStore.setExtensionRegistry(ExtensionRegistry.getEmptyRegistry());
final FDBMetaDataStore finalMetaDataStore = metaDataStore;
MetaDataException e = assertThrows(MetaDataException.class, finalMetaDataStore::getRecordMetaData);
assertThat(e.getMessage(), containsString("Union descriptor is required"));
// Null registry behaves like the empty registry in proto2 and throws an exception in proto3
openMetaDataStore(context);
metaDataStore.setExtensionRegistry(null);
if (ProtoVersionSupplier.getProtoVersion() == 2) {
final FDBMetaDataStore secondFinalMetaDataStore = metaDataStore;
e = assertThrows(MetaDataException.class, secondFinalMetaDataStore::getRecordMetaData);
assertThat(e.getMessage(), containsString("Union descriptor is required"));
} else {
final FDBMetaDataStore secondFinalMetaDataStore = metaDataStore;
assertThrows(NullPointerException.class, secondFinalMetaDataStore::getRecordMetaData);
}
}
}
Aggregations