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"));
}
}
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"));
}
}
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"));
}
}
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));
}
}
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();
}
}
Aggregations