Search in sources :

Example 11 with RecordMetaDataBuilder

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

Example 12 with RecordMetaDataBuilder

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

Example 13 with RecordMetaDataBuilder

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

Example 14 with RecordMetaDataBuilder

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

Example 15 with RecordMetaDataBuilder

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());
}
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)

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