Search in sources :

Example 86 with RecordMetaData

use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.

the class MetaDataEvolutionValidatorTest method changeStoreRecordVersions.

@Test
public void changeStoreRecordVersions() {
    RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
    RecordMetaData metaData2 = RecordMetaData.build(metaData1.toProto().toBuilder().setVersion(metaData1.getVersion() + 1).setStoreRecordVersions(!metaData1.isStoreRecordVersions()).build());
    assertNotEquals(metaData1.isStoreRecordVersions(), metaData2.isStoreRecordVersions());
    validator.validate(metaData1, metaData2);
    RecordMetaData metaData3 = RecordMetaData.build(metaData2.toProto().toBuilder().setVersion(metaData2.getVersion() + 1).setStoreRecordVersions(!metaData2.isStoreRecordVersions()).build());
    assertNotEquals(metaData2.isStoreRecordVersions(), metaData3.isStoreRecordVersions());
    validator.validate(metaData2, metaData3);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) Test(org.junit.jupiter.api.Test)

Example 87 with RecordMetaData

use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.

the class MetaDataEvolutionValidatorTest method fieldChangedFromMessageToGroup.

@Test
public void fieldChangedFromMessageToGroup() {
    // The message and group types here have the same form, but messages and groups are serialized differently
    assertInvalid("field type changed", TestRecordsWithHeaderProto.getDescriptor(), TestHeaderAsGroupProto.getDescriptor());
    assertInvalid("field type changed", TestHeaderAsGroupProto.getDescriptor(), TestRecordsWithHeaderProto.getDescriptor());
    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, TestHeaderAsGroupProto.getDescriptor());
    assertInvalid("field type changed", metaData1, metaData2);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Example 88 with RecordMetaData

use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.

the class MetaDataEvolutionValidatorTest method addRecordTypeWithUniversalIndex.

@Test
public void addRecordTypeWithUniversalIndex() {
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaDataBuilder.addUniversalIndex(new Index("rec_no", "rec_no"));
    RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
    assertNotNull(metaData1.getUniversalIndex("rec_no"));
    // Keep the index universal
    RecordMetaData metaData2 = addNewRecordType(metaData1);
    assertNotNull(metaData2.getUniversalIndex("rec_no"));
    validator.validate(metaData1, metaData2);
    // Make the index a multi-type index on the original record types
    RecordMetaData metaData3 = replaceIndex(metaData2, "rec_no", indexProto -> indexProto.toBuilder().addRecordType("MySimpleRecord").addRecordType("MyOtherRecord").build());
    MetaDataException e = assertThrows(MetaDataException.class, () -> metaData3.getUniversalIndex("rec_no"));
    assertThat(e.getMessage(), containsString("Index rec_no not defined"));
    assertInvalid("new index removes record type", metaData2, metaData3);
    validator.validate(metaData1, metaData3);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Example 89 with RecordMetaData

use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.

the class MetaDataEvolutionValidatorTest method swapIsomorphicRecordTypesWithExplicitKeys.

@Test
public void swapIsomorphicRecordTypesWithExplicitKeys() {
    FileDescriptor updatedFile = mutateFile(fileBuilder -> {
        DescriptorProtos.DescriptorProto newMessageType = fileBuilder.getMessageTypeList().stream().filter(messageType -> messageType.getName().equals("MyOtherRecord")).findFirst().get().toBuilder().setName("MyOtherOtherRecord").build();
        fileBuilder.addMessageType(newMessageType);
        fileBuilder.getMessageTypeBuilderList().forEach(messageType -> {
            if (messageType.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
                messageType.addField(DescriptorProtos.FieldDescriptorProto.newBuilder().setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL).setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE).setTypeName("MyOtherOtherRecord").setName("_MyOtherOtherRecord").setNumber(messageType.getFieldList().stream().mapToInt(DescriptorProtos.FieldDescriptorProto::getNumber).max().orElse(0) + 1));
            }
        });
    });
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(updatedFile);
    metaDataBuilder.getRecordType("MyOtherRecord").setRecordTypeKey("other");
    metaDataBuilder.getRecordType("MyOtherOtherRecord").setRecordTypeKey("other_other");
    RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
    assertEquals("other", metaData1.getRecordType("MyOtherRecord").getRecordTypeKey());
    assertEquals("other_other", metaData1.getRecordType("MyOtherOtherRecord").getRecordTypeKey());
    // Swap the definitions in the union descriptor
    FileDescriptor secondFile = mutateFile(updatedFile, fileBuilder -> fileBuilder.getMessageTypeBuilderList().forEach(messageType -> {
        if (messageType.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
            messageType.getFieldBuilderList().forEach(field -> {
                if (field.getName().equals("_MyOtherRecord")) {
                    field.setTypeName("MyOtherOtherRecord");
                } else if (field.getName().equals("_MyOtherOtherRecord")) {
                    field.setTypeName("MyOtherRecord");
                }
            });
        }
    }));
    RecordMetaData metaData2 = replaceRecordsDescriptor(metaData1, secondFile);
    assertEquals("other", metaData2.getRecordType("MyOtherRecord").getRecordTypeKey());
    assertEquals("other_other", metaData2.getRecordType("MyOtherOtherRecord").getRecordTypeKey());
    assertInvalid("record type key changed", metaData1, metaData2);
    // Swap the definitions in the record type descriptor list
    RecordMetaData metaData3 = replaceRecordsDescriptor(metaData1, secondFile, metaDataProtoBuilder -> metaDataProtoBuilder.getRecordTypesBuilderList().forEach(recordType -> {
        if (recordType.getName().equals("MyOtherRecord")) {
            recordType.setName("MyOtherOtherRecord");
        } else if (recordType.getName().equals("MyOtherOtherRecord")) {
            recordType.setName("MyOtherRecord");
        }
    }));
    assertEquals("other", metaData3.getRecordType("MyOtherOtherRecord").getRecordTypeKey());
    assertEquals("other_other", metaData3.getRecordType("MyOtherRecord").getRecordTypeKey());
    validator.validate(metaData1, metaData3);
    // Verify that using "update records" updates the record type keys
    RecordMetaDataBuilder metaDataBuilder4 = RecordMetaData.newBuilder().setRecords(metaData1.toProto());
    metaDataBuilder4.updateRecords(secondFile);
    RecordMetaData metaData4 = metaDataBuilder4.getRecordMetaData();
    assertEquals("other", metaData4.getRecordType("MyOtherOtherRecord").getRecordTypeKey());
    assertEquals("other_other", metaData4.getRecordType("MyOtherRecord").getRecordTypeKey());
    validator.validate(metaData1, metaData4);
}
Also used : DescriptorProtos(com.google.protobuf.DescriptorProtos) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Descriptor(com.google.protobuf.Descriptors.Descriptor) Descriptors(com.google.protobuf.Descriptors) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) PrefixTextTokenizer(com.apple.foundationdb.record.provider.common.text.PrefixTextTokenizer) UnaryOperator(java.util.function.UnaryOperator) TestSplitNestedTypesProto(com.apple.foundationdb.record.evolution.TestSplitNestedTypesProto) TestNewRecordTypeProto(com.apple.foundationdb.record.evolution.TestNewRecordTypeProto) TestSelfReferenceUnspooledProto(com.apple.foundationdb.record.evolution.TestSelfReferenceUnspooledProto) ArrayList(java.util.ArrayList) Tuple(com.apple.foundationdb.tuple.Tuple) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) RecordMetaDataProto(com.apple.foundationdb.record.RecordMetaDataProto) RecordMetaDataOptionsProto(com.apple.foundationdb.record.RecordMetaDataOptionsProto) DefaultTextTokenizer(com.apple.foundationdb.record.provider.common.text.DefaultTextTokenizer) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TestSelfReferenceProto(com.apple.foundationdb.record.evolution.TestSelfReferenceProto) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) TestUnmergedNestedTypesProto(com.apple.foundationdb.record.evolution.TestUnmergedNestedTypesProto) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) TextTokenizer(com.apple.foundationdb.record.provider.common.text.TextTokenizer) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) TestHeaderAsGroupProto(com.apple.foundationdb.record.evolution.TestHeaderAsGroupProto) RankedSet(com.apple.foundationdb.async.RankedSet) TestRecordsEnumProto(com.apple.foundationdb.record.TestRecordsEnumProto) TestRecordsWithHeaderProto(com.apple.foundationdb.record.TestRecordsWithHeaderProto) Matchers.is(org.hamcrest.Matchers.is) TestMergedNestedTypesProto(com.apple.foundationdb.record.evolution.TestMergedNestedTypesProto) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) AllSuffixesTextTokenizer(com.apple.foundationdb.record.provider.common.text.AllSuffixesTextTokenizer) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) DescriptorProtos(com.google.protobuf.DescriptorProtos) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) Test(org.junit.jupiter.api.Test)

Example 90 with RecordMetaData

use of com.apple.foundationdb.record.RecordMetaData in project fdb-record-layer by FoundationDB.

the class MetaDataEvolutionValidatorTest method changeFormerIndexName.

@Test
public void changeFormerIndexName() {
    RecordMetaDataBuilder metaData1Builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaData1Builder.removeIndex("MySimpleRecord$str_value_indexed");
    RecordMetaData metaData1 = metaData1Builder.getRecordMetaData();
    RecordMetaDataProto.MetaData.Builder metaData2ProtoBuilder = metaData1.toProto().toBuilder().setVersion(metaData1.getVersion() + 1);
    metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).setFormerName("some_other_name"));
    RecordMetaData metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
    assertInvalid("name of former index differs from prior version", metaData1, metaData2);
    metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).clearFormerName());
    metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
    assertInvalid("name of former index differs from prior version", metaData1, metaData2);
    // For existing former indexes, changing the name is not allowed even with the laxer validation option
    MetaDataEvolutionValidator laxerValidator = MetaDataEvolutionValidator.newBuilder().setAllowMissingFormerIndexNames(true).build();
    assertInvalid("name of former index differs from prior version", laxerValidator, metaData1, metaData2);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) Test(org.junit.jupiter.api.Test)

Aggregations

RecordMetaData (com.apple.foundationdb.record.RecordMetaData)168 Test (org.junit.jupiter.api.Test)130 RecordMetaDataBuilder (com.apple.foundationdb.record.RecordMetaDataBuilder)81 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)66 Nonnull (javax.annotation.Nonnull)47 Descriptors (com.google.protobuf.Descriptors)44 RecordMetaDataProto (com.apple.foundationdb.record.RecordMetaDataProto)39 MetaDataException (com.apple.foundationdb.record.metadata.MetaDataException)39 MetaDataProtoTest (com.apple.foundationdb.record.metadata.MetaDataProtoTest)38 Tuple (com.apple.foundationdb.tuple.Tuple)36 List (java.util.List)33 ArrayList (java.util.ArrayList)31 TestRecords1Proto (com.apple.foundationdb.record.TestRecords1Proto)30 Index (com.apple.foundationdb.record.metadata.Index)30 DescriptorProtos (com.google.protobuf.DescriptorProtos)30 Collectors (java.util.stream.Collectors)30 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)27 ByteString (com.google.protobuf.ByteString)27 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)27 RecordMetaDataOptionsProto (com.apple.foundationdb.record.RecordMetaDataOptionsProto)26