Search in sources :

Example 31 with RecordMetaDataBuilder

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

the class MetaDataValidatorTest method duplicateByteArrayRecordTypeKey.

@Test
public void duplicateByteArrayRecordTypeKey() {
    RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    byte[] recordTypeKey = new byte[] { (byte) 0x0f, (byte) 0xdb };
    metaData.getRecordType("MySimpleRecord").setRecordTypeKey(recordTypeKey);
    metaData.getRecordType("MyOtherRecord").setRecordTypeKey(Arrays.copyOf(recordTypeKey, recordTypeKey.length));
    assertInvalid("Same record type key", metaData);
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Example 32 with RecordMetaDataBuilder

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

the class MetaDataValidatorTest method badIndexField.

@Test
public void badIndexField() {
    RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaData.addIndex("MySimpleRecord", "no_such_field");
    assertInvalid(KeyExpression.InvalidExpressionException.class, "Descriptor MySimpleRecord does not have field: no_such_field", metaData);
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) Test(org.junit.jupiter.api.Test)

Example 33 with RecordMetaDataBuilder

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

the class MetaDataValidatorTest method badPrimaryKeyType.

@Test
public void badPrimaryKeyType() {
    RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords4Proto.getDescriptor());
    metaData.getRecordType("RestaurantReviewer").setPrimaryKey(Key.Expressions.field("stats"));
    assertInvalid(Query.InvalidExpressionException.class, "stats is a nested message, but accessed as a scalar", metaData);
}
Also used : Query(com.apple.foundationdb.record.query.expressions.Query) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Example 34 with RecordMetaDataBuilder

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

the class MetaDataValidatorTest method duplicateEnumSubspaceKey.

@Test
public void duplicateEnumSubspaceKey() {
    // This exact use case is somewhat contrived, but one could imagine maintaining an enum with one entry per index
    RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    final Descriptors.EnumValueDescriptor enumValueDescriptor = TestRecordsEnumProto.MyShapeRecord.Size.SMALL.getValueDescriptor();
    metaData.getIndex("MySimpleRecord$str_value_indexed").setSubspaceKey((long) enumValueDescriptor.getNumber());
    metaData.getIndex("MySimpleRecord$num_value_3_indexed").setSubspaceKey(enumValueDescriptor);
    assertInvalid("Same subspace key " + enumValueDescriptor.getNumber() + " used by both", metaData);
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Descriptors(com.google.protobuf.Descriptors) Test(org.junit.jupiter.api.Test)

Example 35 with RecordMetaDataBuilder

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

the class MetaDataValidatorTest method badFormerRemovedBeforeAdded.

@Test
public void badFormerRemovedBeforeAdded() {
    RecordMetaDataBuilder metaData = RecordMetaData.newBuilder().setRecords(RecordMetaData.build(TestRecords1Proto.getDescriptor()).toProto().toBuilder().addFormerIndexes(RecordMetaDataProto.FormerIndex.newBuilder().setSubspaceKey(ByteString.copyFrom(Tuple.from("dropped_index").pack())).setAddedVersion(2).setRemovedVersion(1)).build());
    assertInvalid("Former index has added version 2 which is greater than the removed version 1", metaData);
    RecordMetaDataProto.MetaData.Builder protoBuilder = metaData.build(false).toProto().toBuilder();
    protoBuilder.getFormerIndexesBuilder(0).setFormerName("dropped_index");
    metaData = RecordMetaData.newBuilder().setRecords(protoBuilder.build());
    assertInvalid("Former index dropped_index has added version 2 which is greater than the removed version 1", metaData);
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) Test(org.junit.jupiter.api.Test)

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