Search in sources :

Example 91 with RecordMetaDataBuilder

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());
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 92 with RecordMetaDataBuilder

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());
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 93 with RecordMetaDataBuilder

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());
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) RecordMetaDataProto(com.apple.foundationdb.record.RecordMetaDataProto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 94 with RecordMetaDataBuilder

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);
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Example 95 with RecordMetaDataBuilder

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);
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

RecordMetaDataBuilder (com.apple.foundationdb.record.RecordMetaDataBuilder)150 Test (org.junit.jupiter.api.Test)91 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)69 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 Nonnull (javax.annotation.Nonnull)22 Index (com.apple.foundationdb.record.metadata.Index)21 Descriptors (com.google.protobuf.Descriptors)15 TestRecords1Proto (com.apple.foundationdb.record.TestRecords1Proto)14 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)14 RecordMetaDataProto (com.apple.foundationdb.record.RecordMetaDataProto)13 ByteString (com.google.protobuf.ByteString)13 Tuple (com.apple.foundationdb.tuple.Tuple)12 Collections (java.util.Collections)12 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)11 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)11 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)11 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)11 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)10 BooleanSource (com.apple.test.BooleanSource)10