Search in sources :

Example 31 with MetaDataException

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

the class FDBRecordStoreReplaceIndexTest method replacementIndexPartiallyMissingInMetaDataFails.

@Test
public void replacementIndexPartiallyMissingInMetaDataFails() {
    try (FDBRecordContext context = openContext()) {
        MetaDataException err = assertThrows(MetaDataException.class, () -> openSimpleRecordStore(context, metaDataBuilder -> {
            final Index index = new Index("indexWithOneFakeReplacement", Key.Expressions.field("num_value_2"), IndexTypes.VALUE, ImmutableMap.of(IndexOptions.REPLACED_BY_OPTION_PREFIX + "_00", "fakeIndex", IndexOptions.REPLACED_BY_OPTION_PREFIX + "_01", "MySimpleRecord$str_value_indexed"));
            metaDataBuilder.addIndex("MySimpleRecord", index);
        }));
        assertThat(err.getMessage(), containsString("Index indexWithOneFakeReplacement has replacement index fakeIndex that is not in the meta-data"));
    }
}
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 32 with MetaDataException

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

the class FDBRecordStoreReplaceIndexTest method replacementIndexCycleFails.

@Test
public void replacementIndexCycleFails() {
    try (FDBRecordContext context = openContext()) {
        MetaDataException err = assertThrows(MetaDataException.class, () -> openSimpleRecordStore(context, metaDataBuilder -> {
            final Index index1 = new Index("firstIndex", Key.Expressions.field("num_value_2"), IndexTypes.VALUE, Collections.singletonMap(IndexOptions.REPLACED_BY_OPTION_PREFIX, "secondIndex"));
            final Index index2 = new Index("secondIndex", Key.Expressions.field("num_value_2"), IndexTypes.VALUE, Collections.singletonMap(IndexOptions.REPLACED_BY_OPTION_PREFIX, "firstIndex"));
            metaDataBuilder.addIndex("MySimpleRecord", index1);
            metaDataBuilder.addIndex("MySimpleRecord", index2);
        }));
        assertThat(err.getMessage(), containsString("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 33 with MetaDataException

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

the class FDBRecordStoreReplaceIndexTest method replacementLineFails.

@Test
public void replacementLineFails() {
    try (FDBRecordContext context = openContext()) {
        MetaDataException err = assertThrows(MetaDataException.class, () -> openSimpleRecordStore(context, metaDataBuilder -> {
            final KeyExpression expr = Key.Expressions.field("num_value_2");
            final Index indexA = new Index("indexA", expr, IndexTypes.VALUE, Collections.singletonMap(IndexOptions.REPLACED_BY_OPTION_PREFIX, "indexB"));
            final Index indexB = new Index("indexB", expr, IndexTypes.VALUE, Collections.singletonMap(IndexOptions.REPLACED_BY_OPTION_PREFIX, "indexC"));
            final Index indexC = new Index("indexC", expr);
            metaDataBuilder.addIndex("MySimpleRecord", indexA);
            metaDataBuilder.addIndex("MySimpleRecord", indexB);
            metaDataBuilder.addIndex("MySimpleRecord", indexC);
        }));
        assertThat(err.getMessage(), containsString("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) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) Index(com.apple.foundationdb.record.metadata.Index) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Test(org.junit.jupiter.api.Test)

Example 34 with MetaDataException

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

the class LuceneAnalyzerRegistryImpl method getLuceneAnalyzerPair.

@Nonnull
@Override
public Pair<Analyzer, Analyzer> getLuceneAnalyzerPair(@Nonnull Index index) {
    final String name = index.getOption(IndexOptions.TEXT_ANALYZER_NAME_OPTION);
    // TODO: Get rid of the condition after OR operator, after having all analyzers registered with this registry
    if (name == null || !registry.containsKey(name)) {
        final Analyzer standardAnalyzer = new StandardAnalyzer();
        return Pair.of(standardAnalyzer, standardAnalyzer);
    } else {
        LuceneAnalyzerFactory analyzerFactory = registry.get(name);
        if (analyzerFactory == null) {
            throw new MetaDataException("unrecognized lucene analyzer for tokenizer", LogMessageKeys.ANALYZER_NAME, name);
        }
        final Analyzer indexAnalyzer = analyzerFactory.getIndexAnalyzer(index);
        return Pair.of(indexAnalyzer, analyzerFactory.getQueryAnalyzer(index, indexAnalyzer));
    }
}
Also used : StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) Nonnull(javax.annotation.Nonnull)

Example 35 with MetaDataException

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

the class FDBMetaDataStoreTest method fields.

@Test
public void fields() {
    int version;
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        RecordMetaData metaData = RecordMetaData.build(TestRecords1Proto.getDescriptor());
        version = metaData.getVersion();
        metaDataStore.saveRecordMetaData(metaData);
        context.commit();
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
    }
    // Add a new field
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        assertEquals(version, metaDataStore.getRecordMetaData().getVersion());
        DescriptorProtos.FieldDescriptorProto field = DescriptorProtos.FieldDescriptorProto.newBuilder().setName("newField").setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_INT32).setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL).setNumber(10).build();
        addField("MySimpleRecord", field);
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        assertNotNull(metaDataStore.getRecordMetaData().getRecordsDescriptor().findMessageTypeByName("MySimpleRecord").findFieldByName("newField"));
        assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
        // Add it again should fail
        MetaDataException e = assertThrows(MetaDataException.class, () -> addField("MySimpleRecord", field));
        assertEquals(e.getMessage(), "Field newField already exists in record type MySimpleRecord");
        context.commit();
    }
    // Add a field with non-existent record type
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
        DescriptorProtos.FieldDescriptorProto field = DescriptorProtos.FieldDescriptorProto.newBuilder().setName("newFieldWithNonExistentRecordType").setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE).setTypeName("NonExistentType").setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL).setNumber(10).build();
        MetaDataException e = assertThrows(MetaDataException.class, () -> addField("MySimpleRecord", field));
        assertEquals(e.getMessage(), "Error converting from protobuf");
        assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
        context.commit();
    }
    // Deprecate field should fail if record type or field does not exist
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
        MetaDataException e = assertThrows(MetaDataException.class, () -> deprecateField("NonExistentRecordType", "field"));
        assertEquals(e.getMessage(), "Record type NonExistentRecordType does not exist");
        e = assertThrows(MetaDataException.class, () -> deprecateField("MySimpleRecord", "nonExistentField"));
        assertEquals(e.getMessage(), "Field nonExistentField not found in record type MySimpleRecord");
        context.commit();
    }
    // Deprecate a field
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        assertNotNull(metaDataStore.getRecordMetaData().getRecordsDescriptor().findMessageTypeByName("MySimpleRecord").findFieldByName("num_value_2"));
        assertFalse(metaDataStore.getRecordMetaData().getRecordsDescriptor().findMessageTypeByName("MySimpleRecord").findFieldByName("num_value_2").getOptions().hasDeprecated());
        assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
        deprecateField("MySimpleRecord", "num_value_2");
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        assertTrue(metaDataStore.getRecordMetaData().getRecordsDescriptor().findMessageTypeByName("MySimpleRecord").findFieldByName("num_value_2").getOptions().getDeprecated());
        assertEquals(version + 2, metaDataStore.getRecordMetaData().getVersion());
        context.commit();
    }
    // Deprecate the newly added field
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        assertNotNull(metaDataStore.getRecordMetaData().getRecordsDescriptor().findMessageTypeByName("MySimpleRecord").findFieldByName("newField"));
        assertFalse(metaDataStore.getRecordMetaData().getRecordsDescriptor().findMessageTypeByName("MySimpleRecord").findFieldByName("newField").getOptions().hasDeprecated());
        assertEquals(version + 2, metaDataStore.getRecordMetaData().getVersion());
        deprecateField("MySimpleRecord", "newField");
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        assertTrue(metaDataStore.getRecordMetaData().getRecordsDescriptor().findMessageTypeByName("MySimpleRecord").findFieldByName("newField").getOptions().getDeprecated());
        assertEquals(version + 3, metaDataStore.getRecordMetaData().getVersion());
        context.commit();
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) DescriptorProtos(com.google.protobuf.DescriptorProtos) 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