Search in sources :

Example 61 with RecordMetaDataBuilder

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

the class LuceneQueryIntegrationTest method openRecordStore.

protected void openRecordStore(FDBRecordContext context, RecordMetaDataHook hook) {
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecordsTextProto.getDescriptor());
    metaDataBuilder.getRecordType(TextIndexTestUtils.COMPLEX_DOC).setPrimaryKey(concatenateFields("group", "doc_id"));
    metaDataBuilder.removeIndex("SimpleDocument$text");
    hook.apply(metaDataBuilder);
    recordStore = getStoreBuilder(context, metaDataBuilder.getRecordMetaData()).setSerializer(TextIndexTestUtils.COMPRESSING_SERIALIZER).uncheckedOpen();
    setupPlanner(null);
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder)

Example 62 with RecordMetaDataBuilder

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

the class FDBMetaDataStoreTest method withToProto.

@Test
public void withToProto() {
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecordsParentChildRelationshipProto.getDescriptor());
    metaDataBuilder.addIndex("MyChildRecord", "MyChildRecord$str_value", Key.Expressions.field("str_value"));
    metaDataBuilder.removeIndex("MyChildRecord$parent_rec_no");
    metaDataBuilder.addIndex("MyChildRecord", new Index("MyChildRecord$parent&str", Key.Expressions.concatenateFields("parent_rec_no", "str_value"), Index.EMPTY_VALUE, IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
    metaDataBuilder.removeIndex("MyParentRecord$str_value_indexed");
    metaDataBuilder.addIndex("MyParentRecord", "MyParentRecord$str&child", Key.Expressions.concat(Key.Expressions.field("str_value_indexed"), Key.Expressions.field("child_rec_nos", KeyExpression.FanType.FanOut)));
    metaDataBuilder.addMultiTypeIndex(Arrays.asList(metaDataBuilder.getRecordType("MyChildRecord"), metaDataBuilder.getRecordType("MyParentRecord")), new Index("all$rec_nos", Key.Expressions.field("rec_no")));
    RecordMetaData metaData = metaDataBuilder.getRecordMetaData();
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        metaDataStore.saveRecordMetaData(metaData);
        context.commit();
    }
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        RecordMetaData retrievedMetaData = metaDataStore.getRecordMetaData();
        MetaDataProtoTest.verifyEquals(metaData, retrievedMetaData);
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Index(com.apple.foundationdb.record.metadata.Index) Test(org.junit.jupiter.api.Test) MetaDataProtoTest(com.apple.foundationdb.record.metadata.MetaDataProtoTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 63 with RecordMetaDataBuilder

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

the class FDBRecordStoreSplitRecordsTest method clearOmitUnsplitRecordSuffixTyped.

@Test
public void clearOmitUnsplitRecordSuffixTyped() {
    final RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    final KeyExpression pkey = concat(Key.Expressions.recordType(), field("rec_no"));
    metaData.getRecordType("MySimpleRecord").setPrimaryKey(pkey);
    metaData.getRecordType("MyOtherRecord").setPrimaryKey(pkey);
    FDBRecordStore.Builder builder = FDBRecordStore.newBuilder().setKeySpacePath(path).setMetaDataProvider(metaData).setFormatVersion(FDBRecordStore.FORMAT_CONTROL_FORMAT_VERSION);
    final FDBStoredRecord<Message> saved;
    try (FDBRecordContext context = openContext()) {
        recordStore = builder.setContext(context).create();
        TestRecords1Proto.MyOtherRecord record = TestRecords1Proto.MyOtherRecord.newBuilder().setRecNo(1L).build();
        saved = recordStore.saveRecord(record);
        commit(context);
    }
    metaData.addIndex("MySimpleRecord", "num_value_2");
    builder.setFormatVersion(FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION);
    try (FDBRecordContext context = openContext()) {
        recordStore = builder.setContext(context).open();
        FDBStoredRecord<Message> loaded = recordStore.loadRecord(saved.getPrimaryKey());
        assertNotNull(loaded);
        assertEquals(saved.getRecord(), loaded.getRecord());
        assertTrue(recordStore.getRecordStoreState().getStoreHeader().getOmitUnsplitRecordSuffix());
    }
}
Also used : TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) Message(com.google.protobuf.Message) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with RecordMetaDataBuilder

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

the class FDBRecordStoreSplitRecordsTest method clearOmitUnsplitRecordSuffix.

@EnumSource(ClearOmitUnsplitRecordSuffixMode.class)
@ParameterizedTest(name = "clearOmitUnsplitRecordSuffix [mode = {0}]")
public void clearOmitUnsplitRecordSuffix(ClearOmitUnsplitRecordSuffixMode mode) {
    final RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    FDBRecordStore.Builder builder = FDBRecordStore.newBuilder().setKeySpacePath(path).setMetaDataProvider(metaData).setFormatVersion(FDBRecordStore.FORMAT_CONTROL_FORMAT_VERSION);
    try (FDBRecordContext context = openContext()) {
        recordStore = builder.setContext(context).create();
        if (mode != ClearOmitUnsplitRecordSuffixMode.EMPTY) {
            TestRecords1Proto.MySimpleRecord record = TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1L).setStrValueIndexed("abc").build();
            recordStore.saveRecord(record);
        }
        commit(context);
    }
    if (mode == ClearOmitUnsplitRecordSuffixMode.DELETE) {
        try (FDBRecordContext context = openContext()) {
            recordStore = builder.setContext(context).open();
            recordStore.deleteRecord(Tuple.from(1L));
            commit(context);
        }
    }
    metaData.addIndex("MySimpleRecord", "num_value_2");
    builder.setFormatVersion(FDBRecordStore.MAX_SUPPORTED_FORMAT_VERSION);
    try (FDBRecordContext context = openContext()) {
        recordStore = builder.setContext(context).open();
        assertEquals(mode == ClearOmitUnsplitRecordSuffixMode.SAVE, recordStore.getRecordStoreState().getStoreHeader().getOmitUnsplitRecordSuffix());
    }
}
Also used : TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with RecordMetaDataBuilder

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

the class FDBRecordStoreTest method testUserVersionDeterminesMetaData.

@Test
public void testUserVersionDeterminesMetaData() {
    final RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    builder.setVersion(101);
    final RecordMetaData metaData1 = builder.getRecordMetaData();
    builder.setVersion(102);
    final RecordMetaData metaData2 = builder.getRecordMetaData();
    final SwitchingProvider oldProvider = new SwitchingProvider(101, metaData1, metaData1);
    final SwitchingProvider newProvider = new SwitchingProvider(102, metaData1, metaData2);
    try (FDBRecordContext context = openContext()) {
        recordStore = FDBRecordStore.newBuilder().setContext(context).setKeySpacePath(path).setMetaDataProvider(oldProvider).setUserVersionChecker(oldProvider).create();
        assertEquals(101, recordStore.getUserVersion());
        assertEquals(metaData1, recordStore.getRecordMetaData());
        assertEquals(metaData1.getVersion(), recordStore.getRecordStoreState().getStoreHeader().getMetaDataversion());
        context.commit();
    }
    try (FDBRecordContext context = openContext()) {
        recordStore = FDBRecordStore.newBuilder().setContext(context).setKeySpacePath(path).setMetaDataProvider(newProvider).setUserVersionChecker(newProvider).open();
        assertEquals(101, recordStore.getUserVersion());
        assertEquals(metaData1, recordStore.getRecordMetaData());
        assertEquals(metaData1.getVersion(), recordStore.getRecordStoreState().getStoreHeader().getMetaDataversion());
        context.commit();
    }
    final SwitchingProvider newProvider2 = new SwitchingProvider(102, metaData1, metaData2);
    try (FDBRecordContext context = openContext()) {
        FDBRecordStore.deleteStore(context, path);
        recordStore = FDBRecordStore.newBuilder().setContext(context).setKeySpacePath(path).setMetaDataProvider(newProvider2).setUserVersionChecker(newProvider2).create();
        assertEquals(102, recordStore.getUserVersion());
        assertEquals(metaData2, recordStore.getRecordMetaData());
        assertEquals(metaData2.getVersion(), recordStore.getRecordStoreState().getStoreHeader().getMetaDataversion());
        context.commit();
    }
}
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