use of com.apple.foundationdb.record.RecordMetaDataBuilder 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.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilderTest method setEvolutionValidatorAfterRecords.
@Test
public void setEvolutionValidatorAfterRecords() {
final MetaDataEvolutionValidator defaultValidator = MetaDataEvolutionValidator.getDefaultInstance();
RecordMetaDataBuilder builder = createBuilder(TestRecords1Proto.getDescriptor(), true);
assertSame(defaultValidator, builder.getEvolutionValidator());
MetaDataEvolutionValidator secondValidator = MetaDataEvolutionValidator.newBuilder().setAllowIndexRebuilds(true).build();
MetaDataException e = assertThrows(MetaDataException.class, () -> builder.setEvolutionValidator(secondValidator));
assertEquals("Records already set.", e.getMessage());
assertSame(defaultValidator, builder.getEvolutionValidator());
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilderTest method indexOnPartialNestedPrimaryKey.
@ParameterizedTest(name = "indexOnPartialNestedPrimaryKey [indexCounterBasedSubspaceKey = {0}]")
@BooleanSource
public void indexOnPartialNestedPrimaryKey(final boolean indexCounterBasedSubspaceKey) {
RecordMetaDataBuilder builder = createBuilder(TestRecordsWithHeaderProto.getDescriptor(), indexCounterBasedSubspaceKey);
builder.getRecordType("MyRecord").setPrimaryKey(field("header").nest(concatenateFields("path", "rec_no")));
builder.addIndex("MyRecord", new Index("MyRecord$path_str", concat(field("header").nest("path"), field("str_value")), IndexTypes.VALUE));
RecordMetaData metaData = builder.getRecordMetaData();
Index index = metaData.getIndex("MyRecord$path_str");
assertNotNull(index);
assertNotNull(index.getPrimaryKeyComponentPositions());
assertArrayEquals(new int[] { 0, -1 }, index.getPrimaryKeyComponentPositions());
if (!indexCounterBasedSubspaceKey) {
assertEquals(index.getName(), index.getSubspaceKey());
} else {
assertEquals(1L, index.getSubspaceKey());
}
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilderTest method versionInPrimaryKey.
@Test
public void versionInPrimaryKey() {
RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
RecordTypeBuilder simpleRecordTypeBuilder = builder.getRecordType("MySimpleRecord");
assertThrows(MetaDataException.class, () -> simpleRecordTypeBuilder.setPrimaryKey(Key.Expressions.concat(Key.Expressions.field("rec_no"), VersionKeyExpression.VERSION)));
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilderTest method updateRecords.
@Test
public void updateRecords() {
RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
final int prevVersion = builder.getVersion();
assertSame(builder.getRecordType("MySimpleRecord").getDescriptor().getFile(), TestRecords1Proto.getDescriptor());
assertSame(builder.getRecordType("MyOtherRecord").getDescriptor().getFile(), TestRecords1Proto.getDescriptor());
builder.updateRecords(TestRecords1EvolvedProto.getDescriptor(), true);
RecordMetaData recordMetaData = builder.build(true);
assertSame(TestRecords1EvolvedProto.getDescriptor(), recordMetaData.getRecordType("MySimpleRecord").getDescriptor().getFile());
assertSame(TestRecords1EvolvedProto.getDescriptor(), recordMetaData.getRecordType("MyOtherRecord").getDescriptor().getFile());
assertSame(TestRecords1EvolvedProto.getDescriptor(), recordMetaData.getRecordType("AnotherRecord").getDescriptor().getFile());
assertEquals(recordMetaData.getVersion(), recordMetaData.getRecordType("AnotherRecord").getSinceVersion().intValue());
assertThat(recordMetaData.getRecordType("AnotherRecord").getSinceVersion(), greaterThan(prevVersion));
MetaDataException e = assertThrows(MetaDataException.class, () -> RecordMetaData.newBuilder().setLocalFileDescriptor(TestRecords1EvolvedProto.getDescriptor()).setRecords(recordMetaData.toProto()).updateRecords(TestRecords1EvolvedProto.getDescriptor()));
assertEquals("Updating the records descriptor is not allowed when the local file descriptor is set", e.getMessage());
e = assertThrows(MetaDataException.class, () -> RecordMetaData.newBuilder().updateRecords(TestRecords1EvolvedProto.getDescriptor()));
assertEquals("Records descriptor is not set yet", e.getMessage());
}
Aggregations