Search in sources :

Example 41 with MetaDataException

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

the class FDBRecordStoreReplaceIndexTest method replacementIndexWithSelfCycleFails.

@Test
public void replacementIndexWithSelfCycleFails() {
    try (FDBRecordContext context = openContext()) {
        MetaDataException err = assertThrows(MetaDataException.class, () -> openSimpleRecordStore(context, metaDataBuilder -> {
            final Index index = new Index("indexWithSelfReplacement", Key.Expressions.field("num_value_2"), IndexTypes.VALUE, Collections.singletonMap(IndexOptions.REPLACED_BY_OPTION_PREFIX, "indexWithSelfReplacement"));
            metaDataBuilder.addIndex("MySimpleRecord", index);
        }));
        assertThat(err.getMessage(), containsString("Index indexWithSelfReplacement has replacement index indexWithSelfReplacement that itself has replacement indexes"));
    }
}
Also used : IndexEntry(com.apple.foundationdb.record.IndexEntry) IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Key(com.apple.foundationdb.record.metadata.Key) IndexScanType(com.apple.foundationdb.record.IndexScanType) Tuple(com.apple.foundationdb.tuple.Tuple) ScanProperties(com.apple.foundationdb.record.ScanProperties) BiConsumer(java.util.function.BiConsumer) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Tag(org.junit.jupiter.api.Tag) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) Matchers.empty(org.hamcrest.Matchers.empty) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) IndexOptions(com.apple.foundationdb.record.metadata.IndexOptions) ImmutableMap(com.google.common.collect.ImmutableMap) Tags(com.apple.test.Tags) Collectors(java.util.stream.Collectors) TupleRange(com.apple.foundationdb.record.TupleRange) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) KeySpacePath(com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpacePath) List(java.util.List) Index(com.apple.foundationdb.record.metadata.Index) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Message(com.google.protobuf.Message) IndexTypes(com.apple.foundationdb.record.metadata.IndexTypes) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) Index(com.apple.foundationdb.record.metadata.Index) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Test(org.junit.jupiter.api.Test)

Example 42 with MetaDataException

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

the class FDBMetaDataStoreTest method withoutBumpingVersion.

@Test
public void withoutBumpingVersion() {
    RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        metaDataStore.saveRecordMetaData(metaData);
        MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.saveRecordMetaData(metaData));
        assertThat(e.getMessage(), containsString("meta-data version must increase"));
        context.commit();
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Test(org.junit.jupiter.api.Test) MetaDataProtoTest(com.apple.foundationdb.record.metadata.MetaDataProtoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with MetaDataException

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

the class FDBMetaDataStoreTest method identityRename.

/**
 * Validate that the identity rename works and changes nothing (except the meta-data version).
 */
@Test
public void identityRename() {
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
        metaDataStore.saveRecordMetaData(metaData);
        context.commit();
    }
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        RecordMetaDataProto.MetaData metaDataProto = metaDataStore.getRecordMetaData().toProto();
        renameRecordType("MySimpleRecord", "MySimpleRecord");
        assertThat(metaDataProto.getVersion(), lessThan(metaDataStore.getRecordMetaData().getVersion()));
        RecordMetaDataProto.MetaData mutatedMetaDataProto = metaDataStore.getRecordMetaData().toProto().toBuilder().setVersion(metaDataProto.getVersion()).build();
        assertEquals(metaDataProto, mutatedMetaDataProto);
        MetaDataException e = assertThrows(MetaDataException.class, () -> renameRecordType("MyNonExistentRecord", "MyNonExistentRecord"));
        assertEquals("No record type found with name MyNonExistentRecord", e.getMessage());
        context.commit();
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataProto(com.apple.foundationdb.record.RecordMetaDataProto) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Test(org.junit.jupiter.api.Test) MetaDataProtoTest(com.apple.foundationdb.record.metadata.MetaDataProtoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 44 with MetaDataException

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

the class FDBMetaDataStoreTest method noUnionUpdateRecords.

@ParameterizedTest(name = "noUnionUpdateRecords [repeatSaveOrDoUpdate = {0}]")
@BooleanSource
public void noUnionUpdateRecords(boolean repeatSaveOrDoUpdate) {
    int version;
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        metaDataStore.saveRecordMetaData(TestNoUnionProto.getDescriptor());
        context.commit();
        version = metaDataStore.getRecordMetaData().getVersion();
    }
    // Update records with an evolved proto. A new record type is added earlier in the file.
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertEquals(version, metaDataStore.getRecordMetaData().getVersion());
        if (repeatSaveOrDoUpdate) {
            metaDataStore.updateRecords(TestNoUnionEvolvedProto.getDescriptor());
        } else {
            metaDataStore.saveRecordMetaData(TestNoUnionEvolvedProto.getDescriptor());
        }
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MyOtherRecord"));
        assertEquals("_MySimpleRecord", metaDataStore.getRecordMetaData().getUnionDescriptor().findFieldByNumber(1).getName());
        assertEquals("_MyOtherRecord", metaDataStore.getRecordMetaData().getUnionDescriptor().findFieldByNumber(2).getName());
        assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
        context.commit();
    }
    // Renaming a record type is not allowed
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
        MetaDataException e;
        if (repeatSaveOrDoUpdate) {
            e = assertThrows(MetaDataException.class, () -> metaDataStore.updateRecords(TestNoUnionEvolvedRenamedRecordTypeProto.getDescriptor()));
        } else {
            e = assertThrows(MetaDataException.class, () -> metaDataStore.saveRecordMetaData(TestNoUnionEvolvedRenamedRecordTypeProto.getDescriptor()));
        }
        assertEquals("Record type MySimpleRecord removed", e.getMessage());
        context.commit();
    }
}
Also used : MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 45 with MetaDataException

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

the class FDBMetaDataStoreTest method extensionRegistryWithUnionDescriptor.

@Test
public void extensionRegistryWithUnionDescriptor() {
    try (FDBRecordContext context = fdb.openContext()) {
        // test_records_3.proto relies on the union field annotation type
        openMetaDataStore(context);
        RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecords3Proto.getDescriptor());
        builder.getRecordType("MyHierarchicalRecord").setPrimaryKey(Key.Expressions.concatenateFields("parent_path", "child_name"));
        RecordMetaData metaData = builder.build();
        metaDataStore.saveRecordMetaData(metaData);
        context.commit();
    }
    try (FDBRecordContext context = fdb.openContext()) {
        // Default registry parses options
        openMetaDataStore(context);
        RecordMetaData metaData = metaDataStore.getRecordMetaData();
        assertNotSame(metaData.getUnionDescriptor(), TestRecords3Proto.UnionDescriptor.getDescriptor());
        assertEquals(metaData.getUnionDescriptor().toProto(), TestRecords3Proto.UnionDescriptor.getDescriptor().toProto());
        // Empty registry does not
        openMetaDataStore(context);
        metaDataStore.setExtensionRegistry(ExtensionRegistry.getEmptyRegistry());
        final FDBMetaDataStore finalMetaDataStore = metaDataStore;
        MetaDataException e = assertThrows(MetaDataException.class, finalMetaDataStore::getRecordMetaData);
        assertThat(e.getMessage(), containsString("Union descriptor is required"));
        // Null registry behaves like the empty registry in proto2 and throws an exception in proto3
        openMetaDataStore(context);
        metaDataStore.setExtensionRegistry(null);
        if (ProtoVersionSupplier.getProtoVersion() == 2) {
            final FDBMetaDataStore secondFinalMetaDataStore = metaDataStore;
            e = assertThrows(MetaDataException.class, secondFinalMetaDataStore::getRecordMetaData);
            assertThat(e.getMessage(), containsString("Union descriptor is required"));
        } else {
            final FDBMetaDataStore secondFinalMetaDataStore = metaDataStore;
            assertThrows(NullPointerException.class, secondFinalMetaDataStore::getRecordMetaData);
        }
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Test(org.junit.jupiter.api.Test) MetaDataProtoTest(com.apple.foundationdb.record.metadata.MetaDataProtoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MetaDataException (com.apple.foundationdb.record.metadata.MetaDataException)61 Test (org.junit.jupiter.api.Test)33 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 MetaDataProtoTest (com.apple.foundationdb.record.metadata.MetaDataProtoTest)25 Nonnull (javax.annotation.Nonnull)24 Index (com.apple.foundationdb.record.metadata.Index)22 Descriptors (com.google.protobuf.Descriptors)14 Tuple (com.apple.foundationdb.tuple.Tuple)13 List (java.util.List)12 ScanProperties (com.apple.foundationdb.record.ScanProperties)11 TupleRange (com.apple.foundationdb.record.TupleRange)11 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)11 IndexEntry (com.apple.foundationdb.record.IndexEntry)10 IndexTypes (com.apple.foundationdb.record.metadata.IndexTypes)10 DescriptorProtos (com.google.protobuf.DescriptorProtos)10 TestRecords1Proto (com.apple.foundationdb.record.TestRecords1Proto)9 Message (com.google.protobuf.Message)9 Collectors (java.util.stream.Collectors)9 IndexScanType (com.apple.foundationdb.record.IndexScanType)8