Search in sources :

Example 16 with RecordMetaData

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

the class MetaDataEvolutionValidatorTest method newTypeWithoutSinceVersion.

@Test
public void newTypeWithoutSinceVersion() {
    RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
    RecordMetaData metaData2 = addNewRecordType(metaData1, RecordMetaDataProto.RecordType.Builder::clearSinceVersion);
    assertInvalid("new record type is missing since version", metaData1, metaData2);
    MetaDataEvolutionValidator laxerValidator = MetaDataEvolutionValidator.newBuilder().setAllowNoSinceVersion(true).build();
    laxerValidator.validate(metaData1, metaData2);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) RecordMetaDataProto(com.apple.foundationdb.record.RecordMetaDataProto) Test(org.junit.jupiter.api.Test)

Example 17 with RecordMetaData

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

the class MetaDataEvolutionValidatorTest method rankLevelsChanged.

@Test
public void rankLevelsChanged() {
    final String indexName = "MySimpleRecord$rank(num_value_2)";
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaDataBuilder.addIndex("MySimpleRecord", new Index(indexName, Key.Expressions.field("num_value_2").ungrouped(), IndexTypes.RANK));
    RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
    validateIndexMutation("rank levels changed", metaData1, indexName, indexProto -> changeOption(indexProto, IndexOptions.RANK_NLEVELS, "4"));
    validateIndexMutation("rank levels changed", metaData1, indexName, indexProto -> changeOption(indexProto, IndexOptions.RANK_NLEVELS, "" + RankedSet.MAX_LEVELS));
    // Setting the default explicitly is fine
    RecordMetaData metaData2 = replaceIndex(metaData1, indexName, indexProto -> changeOption(indexProto, IndexOptions.RANK_NLEVELS, "" + RankedSet.DEFAULT_LEVELS));
    validator.validate(metaData1, metaData2);
    RecordMetaData metaData3 = replaceIndex(metaData2, indexName, this::clearOptions);
    validator.validate(metaData2, metaData3);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) ByteString(com.google.protobuf.ByteString) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 18 with RecordMetaData

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

the class MetaDataEvolutionValidatorTest method indexAddedVersionChanged.

@Test
public void indexAddedVersionChanged() {
    RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
    RecordMetaData metaData2 = replaceIndex(metaData1, "MySimpleRecord$str_value_indexed", indexProto -> indexProto.toBuilder().setAddedVersion(metaData1.getVersion() + 1).setLastModifiedVersion(metaData1.getVersion() + 1).build());
    assertInvalid("new index added version does not match old index added version", metaData1, metaData2);
    metaData2 = replaceIndex(metaData2, "MySimpleRecord$str_value_indexed", indexProto -> indexProto.toBuilder().setAddedVersion(indexProto.getAddedVersion() - 1).build());
    assertInvalid("new index added version does not match old index added version", metaData1, metaData2);
}
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) Test(org.junit.jupiter.api.Test)

Example 19 with RecordMetaData

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

the class MetaDataEvolutionValidatorTest method changeReplacedByIndex.

@Test
public void changeReplacedByIndex() {
    RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
    RecordMetaData metaData2 = replaceIndex(metaData1, "MySimpleRecord$str_value_indexed", indexProto -> changeOption(indexProto, IndexOptions.REPLACED_BY_OPTION_PREFIX, "MySimpleRecord$num_value_3_indexed"));
    assertEquals(Collections.singletonList("MySimpleRecord$num_value_3_indexed"), metaData2.getIndex("MySimpleRecord$str_value_indexed").getReplacedByIndexNames());
    validator.validate(metaData1, metaData2);
    RecordMetaData metaData3 = replaceIndex(metaData2, "MySimpleRecord$str_value_indexed", this::clearOptions);
    assertEquals(Collections.emptyList(), metaData3.getIndex("MySimpleRecord$str_value_indexed").getReplacedByIndexNames());
    validator.validate(metaData2, metaData3);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) Test(org.junit.jupiter.api.Test)

Example 20 with RecordMetaData

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

the class MetaDataEvolutionValidatorTest method changeRecordTypeName.

@Test
public void changeRecordTypeName() {
    final MetaDataEvolutionValidator renameDisallowingValidator = MetaDataEvolutionValidator.newBuilder().setDisallowTypeRenames(true).build();
    // Update the record type name, but don't update any references in indexes
    FileDescriptor updatedFile = mutateFile(fileBuilder -> fileBuilder.getMessageTypeBuilderList().forEach(messageType -> {
        if (messageType.getName().equals("MyOtherRecord")) {
            messageType.setName("MyOtherOtherRecord");
        } else if (messageType.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
            messageType.getFieldBuilderList().forEach(field -> {
                if (field.getName().equals("_MyOtherRecord")) {
                    field.setName("_MyOtherOtherRecord");
                    field.setTypeName("MyOtherOtherRecord");
                }
            });
        }
    }));
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaDataBuilder.addIndex("MyOtherRecord", "num_value_3_indexed");
    RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
    MetaDataException e = assertThrows(MetaDataException.class, () -> replaceRecordsDescriptor(metaData1, updatedFile));
    assertThat(e.getMessage(), containsString("Unknown record type MyOtherRecord"));
    validator.validateUnion(metaData1.getUnionDescriptor(), updatedFile.findMessageTypeByName(RecordMetaDataBuilder.DEFAULT_UNION_NAME));
    // Changes the record type definition but not the indexes
    e = assertThrows(MetaDataException.class, () -> replaceRecordsDescriptor(metaData1, updatedFile, protoBuilder -> protoBuilder.getRecordTypesBuilderList().forEach(recordType -> {
        if (recordType.getName().equals("MyOtherRecord")) {
            recordType.setName("MyOtherOtherRecord");
        }
    })));
    assertThat(e.getMessage(), containsString("Unknown record type MyOtherRecord"));
    // This should be allowed because it replaces all index definitions with the new record type as well
    RecordMetaData metaData3 = replaceRecordsDescriptor(metaData1, updatedFile, protoBuilder -> {
        protoBuilder.getRecordTypesBuilderList().forEach(recordType -> {
            if (recordType.getName().equals("MyOtherRecord")) {
                recordType.setName("MyOtherOtherRecord");
            }
        });
        protoBuilder.getIndexesBuilderList().forEach(index -> {
            List<String> recordTypes = new ArrayList<>(index.getRecordTypeList());
            recordTypes.replaceAll(recordType -> recordType.equals("MyOtherRecord") ? "MyOtherOtherRecord" : recordType);
            index.clearRecordType();
            index.addAllRecordType(recordTypes);
        });
    });
    assertEquals(Collections.singletonList(metaData3.getRecordType("MyOtherOtherRecord")), metaData3.recordTypesForIndex(metaData3.getIndex("MyOtherRecord$num_value_3_indexed")));
    validator.validate(metaData1, metaData3);
    assertInvalid("record type name changed", renameDisallowingValidator, metaData1, metaData3);
    // Validate that calling update records with the new file descriptor produces a valid evolution
    RecordMetaDataBuilder metaDataBuilder4 = RecordMetaData.newBuilder().setRecords(metaData1.toProto());
    metaDataBuilder4.updateRecords(updatedFile);
    RecordMetaData metaData4 = metaDataBuilder4.getRecordMetaData();
    assertEquals(Collections.singletonList(metaData4.getRecordType("MyOtherOtherRecord")), metaData4.recordTypesForIndex(metaData4.getIndex("MyOtherRecord$num_value_3_indexed")));
    validator.validate(metaData1, metaData4);
    assertInvalid("record type name changed", renameDisallowingValidator, 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) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Matchers.containsString(org.hamcrest.Matchers.containsString) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) 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