Search in sources :

Example 76 with RecordMetaDataBuilder

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

the class MetaDataEvolutionValidatorTest method doNotChangeVersion.

@Test
public void doNotChangeVersion() {
    // Check if a naive removal of the index without updating the version is checked
    RecordMetaData metaData1 = RecordMetaData.build(TestRecords1Proto.getDescriptor());
    assertInvalid("new meta-data does not have newer version", metaData1, metaData1);
    RecordMetaDataBuilder metaData2Builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaData2Builder.removeIndex("MySimpleRecord$str_value_indexed");
    validator.validate(metaData1, metaData2Builder.getRecordMetaData());
    metaData2Builder.setVersion(metaData1.getVersion());
    assertInvalid("new meta-data does not have newer version", metaData1, metaData2Builder.build(false));
    // If the validator allows not changing the version, it should make sure all of the changes are compatible
    MetaDataEvolutionValidator validatorAcceptingSameVersion = MetaDataEvolutionValidator.newBuilder().setAllowNoVersionChange(true).build();
    validatorAcceptingSameVersion.validate(metaData1, metaData1);
    // Confirm with the laxer validator that the removed index is noticed
    metaData2Builder.setVersion(metaData1.getVersion() + 1);
    RecordMetaDataBuilder metaData3Builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaData3Builder.setVersion(metaData1.getVersion() + 1);
    RecordMetaData metaData3 = metaData3Builder.getRecordMetaData();
    RecordMetaData metaData4 = metaData2Builder.getRecordMetaData();
    assertInvalid("new meta-data does not have newer version", metaData3, metaData4);
    assertInvalid("new former index has removed version that is not newer than the old meta-data version", validatorAcceptingSameVersion, metaData3, metaData4);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Example 77 with RecordMetaDataBuilder

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

the class MetaDataEvolutionValidatorTest method indexUsedWhereFormerIndexWas.

@Test
public void indexUsedWhereFormerIndexWas() {
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaDataBuilder.removeIndex("MySimpleRecord$str_value_indexed");
    RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
    RecordMetaDataBuilder metaData2Builder = RecordMetaData.newBuilder().setRecords(metaData1.toProto().toBuilder().clearFormerIndexes().build());
    Index newIndex = new Index("newIndex", "str_value_indexed");
    newIndex.setSubspaceKey("MySimpleRecord$str_value_indexed");
    metaData2Builder.addIndex("MySimpleRecord", newIndex);
    RecordMetaData metaData2 = metaData2Builder.getRecordMetaData();
    assertInvalid("former index key used for new index in meta-data", metaData1, metaData2);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Example 78 with RecordMetaDataBuilder

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

the class MetaDataEvolutionValidatorTest method indexPrimaryKeyComponentsChanged.

@Test
public void indexPrimaryKeyComponentsChanged() {
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaDataBuilder.addIndex("MySimpleRecord", "rec_no", "rec_no");
    RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
    assertThat(metaData1.getIndex("rec_no").hasPrimaryKeyComponentPositions(), is(true));
    RecordMetaData tempMetaData = addNewRecordType(metaData1);
    RecordMetaData metaData2 = replaceIndex(tempMetaData, "rec_no", indexProto -> indexProto.toBuilder().addRecordType("NewRecord").build());
    assertInvalid("new index drops primary key component positions", metaData1, metaData2);
    // This is essentially the behavior change outlined by: https://github.com/FoundationDB/fdb-record-layer/issues/93
    metaData2.getIndex("rec_no").setPrimaryKeyComponentPositions(new int[] { 0 });
    validator.validate(metaData1, metaData2);
    metaData1.getIndex("rec_no").setPrimaryKeyComponentPositions(null);
    assertInvalid("new index adds primary key component positions", metaData1, metaData2);
    metaData1.getIndex("rec_no").setPrimaryKeyComponentPositions(new int[] { 0 });
    metaData2.getIndex("rec_no").setPrimaryKeyComponentPositions(new int[] { 1 });
    assertInvalid("new index changes primary key component positions", metaData1, metaData2);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) Test(org.junit.jupiter.api.Test)

Example 79 with RecordMetaDataBuilder

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

the class MetaDataEvolutionValidatorTest method removeIndexAndDropAddedVersion.

@Test
public void removeIndexAndDropAddedVersion() {
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    RecordMetaData metaData1 = RecordMetaData.build(metaDataBuilder.getRecordMetaData().toProto());
    metaDataBuilder.removeIndex("MySimpleRecord$str_value_indexed");
    RecordMetaDataProto.MetaData metaData2Proto = metaDataBuilder.getRecordMetaData().toProto();
    RecordMetaData metaData2 = RecordMetaData.build(metaData2Proto.toBuilder().removeFormerIndexes(0).addFormerIndexes(metaData2Proto.getFormerIndexes(0).toBuilder().clearAddedVersion()).build());
    assertInvalid("former index reports added version older than replacing index", metaData1, metaData2);
    // With the option set, it should validate
    MetaDataEvolutionValidator laxerValidator = MetaDataEvolutionValidator.newBuilder().setAllowOlderFormerIndexAddedVerions(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 80 with RecordMetaDataBuilder

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

the class MetaDataEvolutionValidatorTest method changeFormerIndexVersion.

@Test
public void changeFormerIndexVersion() {
    RecordMetaDataBuilder metaData1Builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaData1Builder.removeIndex("MySimpleRecord$str_value_indexed");
    RecordMetaData metaData1 = metaData1Builder.getRecordMetaData();
    RecordMetaDataProto.MetaData.Builder metaData2ProtoBuilder = metaData1.toProto().toBuilder().setVersion(metaData1.getVersion() + 1);
    metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).setRemovedVersion(metaData1.getVersion() + 1));
    RecordMetaData metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
    assertInvalid("removed version of former index differs from prior version", metaData1, metaData2);
    metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).setRemovedVersion(metaData1.getVersion()).setAddedVersion(metaData1.getVersion() - 2));
    metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
    assertInvalid("added version of former index differs from prior version", metaData1, metaData2);
    metaData2ProtoBuilder.setFormerIndexes(0, metaData2ProtoBuilder.getFormerIndexesBuilder(0).clearAddedVersion());
    metaData2 = RecordMetaData.build(metaData2ProtoBuilder.build());
    assertInvalid("added version of former index differs from prior version", metaData1, metaData2);
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) 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