use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilderTest method setEvolutionValidator.
@Test
public void setEvolutionValidator() {
RecordMetaDataBuilder builder = RecordMetaData.newBuilder();
assertSame(MetaDataEvolutionValidator.getDefaultInstance(), builder.getEvolutionValidator());
MetaDataEvolutionValidator secondValidator = MetaDataEvolutionValidator.newBuilder().setAllowIndexRebuilds(true).build();
builder.setEvolutionValidator(secondValidator);
assertSame(secondValidator, builder.getEvolutionValidator());
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilderTest method validUnion.
@Test
public void validUnion() {
RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecordsMarkedUnmarkedProto.getDescriptor());
RecordMetaData recordMetaData = builder.build(true);
assertNotNull(recordMetaData.getRecordType("MyMarkedRecord"));
assertNotNull(recordMetaData.getRecordType("MyUnmarkedRecord1"));
MetaDataException e = assertThrows(MetaDataException.class, () -> recordMetaData.getRecordType("MyUnmarkedRecord2"));
assertEquals("Unknown record type MyUnmarkedRecord2", e.getMessage());
e = assertThrows(MetaDataException.class, () -> RecordMetaData.newBuilder().setRecords(TestUnionDefaultNameProto.getDescriptor()));
assertEquals("Union message type RecordTypeUnion cannot be a union field.", e.getMessage());
e = assertThrows(MetaDataException.class, () -> RecordMetaData.newBuilder().setRecords(TestTwoUnionsProto.getDescriptor()));
assertEquals("Only one union descriptor is allowed", e.getMessage());
e = assertThrows(MetaDataException.class, () -> RecordMetaData.newBuilder().setRecords(TestRecordsUnionMissingRecordProto.getDescriptor()));
assertEquals("Record message type MyMissingRecord must be a union field.", e.getMessage());
e = assertThrows(MetaDataException.class, () -> RecordMetaData.newBuilder().setRecords(TestRecordsUnionMissingRecordProto.getDescriptor()));
assertEquals("Record message type MyMissingRecord must be a union field.", e.getMessage());
e = assertThrows(MetaDataException.class, () -> RecordMetaData.newBuilder().setRecords(TestRecordsUnionWithNestedProto.getDescriptor()));
assertEquals("Union field _MyNestedRecord has type MyNestedRecord which is not a record", e.getMessage());
e = assertThrows(MetaDataException.class, () -> RecordMetaData.newBuilder().setRecords(TestRecordsUnionWithImportedNestedProto.getDescriptor()));
assertEquals("Union field _MyNestedRecord has type RestaurantReview which is not a record", e.getMessage());
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class RecordMetaDataBuilderTest method counterBasedSubspaceKeys.
@Test
public void counterBasedSubspaceKeys() {
// Records descriptor already set.
MetaDataException e = assertThrows(MetaDataException.class, () -> RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor()).enableCounterBasedSubspaceKeys());
assertEquals("Records descriptor has already been set.", e.getMessage());
// Valid use of counter-based subspace keys assignment.
RecordMetaDataBuilder builder = RecordMetaData.newBuilder().enableCounterBasedSubspaceKeys().setRecords(TestRecords1Proto.getDescriptor());
builder.addIndex("MySimpleRecord", "MySimpleRecord$num_value_2", "num_value_2");
RecordMetaData metaData = builder.build(true);
assertNotNull(metaData.getIndex("MySimpleRecord$str_value_indexed"));
assertNotNull(metaData.getIndex("MySimpleRecord$num_value_unique"));
assertNotNull(metaData.getIndex("MySimpleRecord$num_value_3_indexed"));
assertNotNull(metaData.getIndex("MySimpleRecord$num_value_2"));
assertEquals(1L, metaData.getIndex("MySimpleRecord$str_value_indexed").getSubspaceKey());
assertEquals(2L, metaData.getIndex("MySimpleRecord$num_value_unique").getSubspaceKey());
assertEquals(3L, metaData.getIndex("MySimpleRecord$num_value_3_indexed").getSubspaceKey());
assertEquals(4L, metaData.getIndex("MySimpleRecord$num_value_2").getSubspaceKey());
// Valid use of counter-based subspace keys assignment with meta-data proto.
builder = RecordMetaData.newBuilder().enableCounterBasedSubspaceKeys().setRecords(metaData.toProto());
metaData = builder.build(true);
assertNotNull(metaData.getIndex("MySimpleRecord$str_value_indexed"));
assertNotNull(metaData.getIndex("MySimpleRecord$num_value_unique"));
assertNotNull(metaData.getIndex("MySimpleRecord$num_value_3_indexed"));
assertNotNull(metaData.getIndex("MySimpleRecord$num_value_2"));
assertEquals(1L, metaData.getIndex("MySimpleRecord$str_value_indexed").getSubspaceKey());
assertEquals(2L, metaData.getIndex("MySimpleRecord$num_value_unique").getSubspaceKey());
assertEquals(3L, metaData.getIndex("MySimpleRecord$num_value_3_indexed").getSubspaceKey());
assertEquals(4L, metaData.getIndex("MySimpleRecord$num_value_2").getSubspaceKey());
// FormerIndex
RecordMetaDataBuilder formerIndexBuilder = RecordMetaData.newBuilder().enableCounterBasedSubspaceKeys().setRecords(TestRecords1Proto.getDescriptor());
Object formerSubspaceKey = formerIndexBuilder.getIndex("MySimpleRecord$num_value_3_indexed").getSubspaceKey();
formerIndexBuilder.removeIndex("MySimpleRecord$num_value_3_indexed");
final RecordMetaData metaDataWithFormerIndex = formerIndexBuilder.build(true);
FormerIndex formerIndex = metaDataWithFormerIndex.getFormerIndexes().stream().filter(index -> index.getFormerName().equals("MySimpleRecord$num_value_3_indexed")).findFirst().get();
assertEquals(formerSubspaceKey, formerIndex.getSubspaceKey());
// A common case that user had some existing meta-data in which all indexes had implicit subspace keys, and the user now decides to enable this feature.
RecordMetaDataProto.MetaData.Builder protoBuilder = metaData.toProto().toBuilder();
protoBuilder.getIndexesBuilderList().forEach(RecordMetaDataProto.Index.Builder::clearSubspaceKey);
metaData = RecordMetaData.newBuilder().enableCounterBasedSubspaceKeys().setRecords(protoBuilder.build()).getRecordMetaData();
assertNotNull(metaData.getIndex("MySimpleRecord$str_value_indexed"));
assertNotNull(metaData.getIndex("MySimpleRecord$num_value_unique"));
assertNotNull(metaData.getIndex("MySimpleRecord$num_value_3_indexed"));
assertEquals(metaData.getIndex("MySimpleRecord$str_value_indexed").getName(), metaData.getIndex("MySimpleRecord$str_value_indexed").getSubspaceKey());
assertEquals(metaData.getIndex("MySimpleRecord$num_value_unique").getName(), metaData.getIndex("MySimpleRecord$num_value_unique").getSubspaceKey());
assertEquals(metaData.getIndex("MySimpleRecord$num_value_3_indexed").getName(), metaData.getIndex("MySimpleRecord$num_value_3_indexed").getSubspaceKey());
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class MetaDataValidatorTest method duplicateImplicitAndExplicitRecordTypeKey.
@Test
public void duplicateImplicitAndExplicitRecordTypeKey() {
RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
int simpleRecordKey = TestRecords1Proto.RecordTypeUnion.getDescriptor().findFieldByName("_MySimpleRecord").getNumber();
metaData.getRecordType("MyOtherRecord").setRecordTypeKey(simpleRecordKey);
assertInvalid("Same record type key " + simpleRecordKey + " used by both", metaData);
metaData.getRecordType("MyOtherRecord").setRecordTypeKey((long) simpleRecordKey);
assertInvalid("Same record type key " + simpleRecordKey + " used by both", metaData);
}
use of com.apple.foundationdb.record.RecordMetaDataBuilder in project fdb-record-layer by FoundationDB.
the class MetaDataValidatorTest method duplicateRecordTypeKey.
@Test
public void duplicateRecordTypeKey() {
RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
metaData.getRecordType("MySimpleRecord").setPrimaryKey(Key.Expressions.concat(Key.Expressions.recordType(), Key.Expressions.field("rec_no")));
metaData.getRecordType("MySimpleRecord").setRecordTypeKey("same");
metaData.getRecordType("MyOtherRecord").setPrimaryKey(Key.Expressions.concat(Key.Expressions.recordType(), Key.Expressions.field("rec_no")));
metaData.getRecordType("MyOtherRecord").setRecordTypeKey("same");
assertInvalid("Same record type key same used by both", metaData);
}
Aggregations