use of com.apple.foundationdb.record.metadata.MetaDataEvolutionValidator in project fdb-record-layer by FoundationDB.
the class FDBMetaDataStoreTest method withIndexesRequiringRebuild.
@Test
public void withIndexesRequiringRebuild() {
RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
metaDataStore.saveRecordMetaData(metaData);
context.commit();
}
RecordMetaDataProto.MetaData.Builder protoBuilder = metaData.toProto().toBuilder().setVersion(metaData.getVersion() + 1);
protoBuilder.getIndexesBuilderList().forEach(index -> {
if (index.getName().equals("MySimpleRecord$str_value_indexed")) {
index.addOptions(RecordMetaDataProto.Index.Option.newBuilder().setKey(IndexOptions.UNIQUE_OPTION).setValue("true"));
index.setLastModifiedVersion(metaData.getVersion() + 1);
}
});
RecordMetaData metaData2 = RecordMetaData.build(protoBuilder.build());
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.saveRecordMetaData(metaData2));
assertThat(e.getMessage(), containsString("last modified version of index changed"));
MetaDataProtoTest.verifyEquals(metaData, metaDataStore.getRecordMetaData());
context.commit();
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData retrievedMetaData = metaDataStore.getRecordMetaData();
assertThat(retrievedMetaData.getIndex("MySimpleRecord$str_value_indexed").isUnique(), is(false));
MetaDataProtoTest.verifyEquals(metaData, retrievedMetaData);
}
MetaDataEvolutionValidator laxerValidator = MetaDataEvolutionValidator.newBuilder().setAllowIndexRebuilds(true).build();
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
metaDataStore.setEvolutionValidator(laxerValidator);
metaDataStore.saveRecordMetaData(metaData2);
context.commit();
}
try (FDBRecordContext context = fdb.openContext()) {
openMetaDataStore(context);
RecordMetaData retrievedMetaData = metaDataStore.getRecordMetaData();
assertThat(retrievedMetaData.getIndex("MySimpleRecord$str_value_indexed").isUnique(), is(true));
MetaDataProtoTest.verifyEquals(metaData2, metaDataStore.getRecordMetaData());
}
}
Aggregations