use of com.yahoo.document.config.DocumentmanagerConfig in project vespa by vespa-engine.
the class FieldOfTypeDocumentTestCase method testDocument.
@Test
public void testDocument() throws IOException, ParseException {
List<String> sds = new ArrayList<>();
sds.add("src/test/examples/music.sd");
sds.add("src/test/examples/fieldoftypedocument.sd");
DocumentmanagerConfig.Builder value = Deriver.getDocumentManagerConfig(sds);
assertConfigFile("src/test/examples/fieldoftypedocument.cfg", new DocumentmanagerConfig(value).toString() + "\n");
DocumentTypeManager manager = new DocumentTypeManager();
DocumentTypeManagerConfigurer.configure(manager, "raw:" + new DocumentmanagerConfig(value).toString());
DocumentType musicType = manager.getDocumentType("music");
assertEquals(5, musicType.getFieldCount());
Field intField = musicType.getField("intfield");
assertEquals(DataType.INT, intField.getDataType());
Field stringField = musicType.getField("stringfield");
assertEquals(DataType.STRING, stringField.getDataType());
Field longField = musicType.getField("longfield");
assertEquals(DataType.LONG, longField.getDataType());
Field summaryfeatures = musicType.getField("summaryfeatures");
assertEquals(DataType.STRING, summaryfeatures.getDataType());
Field rankfeatures = musicType.getField("rankfeatures");
assertEquals(DataType.STRING, rankfeatures.getDataType());
DocumentType bookType = manager.getDocumentType("book");
assertEquals(3, bookType.getFieldCount());
Field musicField = bookType.getField("soundtrack");
assertSame(musicType, musicField.getDataType());
summaryfeatures = musicType.getField("summaryfeatures");
assertEquals(DataType.STRING, summaryfeatures.getDataType());
rankfeatures = musicType.getField("rankfeatures");
assertEquals(DataType.STRING, rankfeatures.getDataType());
}
use of com.yahoo.document.config.DocumentmanagerConfig in project vespa by vespa-engine.
the class InheritanceTestCase method requireThatStructTypesAreInheritedThroughDiamond.
@Test
public void requireThatStructTypesAreInheritedThroughDiamond() throws IOException, ParseException {
String dir = "src/test/derived/inheritdiamond/";
List<String> files = Arrays.asList("grandparent.sd", "mother.sd", "father.sd", "child.sd");
File outDir = tmpDir.newFolder("out");
for (int startIdx = 0; startIdx < files.size(); ++startIdx) {
SearchBuilder builder = new SearchBuilder();
for (int fileIdx = startIdx; fileIdx < startIdx + files.size(); ++fileIdx) {
String fileName = files.get(fileIdx % files.size());
builder.importFile(dir + fileName);
}
builder.build();
DocumentmanagerConfig.Builder b = new DocumentmanagerConfig.Builder();
DerivedConfiguration.exportDocuments(new DocumentManager().produce(builder.getModel(), b), outDir.getPath());
DocumentmanagerConfig dc = new DocumentmanagerConfig(b);
assertEquals(17, dc.datatype().size());
assertNotNull(structType("child.body", dc));
DocumentmanagerConfig.Datatype.Structtype childHeader = structType("child.header", dc);
assertEquals(childHeader.field(0).name(), "foo");
assertEquals(childHeader.field(1).name(), "bar");
assertEquals(childHeader.field(2).name(), "baz");
assertEquals(childHeader.field(3).name(), "cox");
DocumentmanagerConfig.Datatype.Documenttype child = documentType("child", dc);
assertEquals(child.inherits(0).name(), "document");
assertEquals(child.inherits(1).name(), "father");
assertEquals(child.inherits(2).name(), "mother");
DocumentmanagerConfig.Datatype.Documenttype mother = documentType("mother", dc);
assertEquals(mother.inherits(0).name(), "grandparent");
assertEquals(mother.inherits(1).name(), "document");
}
}
use of com.yahoo.document.config.DocumentmanagerConfig in project vespa by vespa-engine.
the class FeedTesterV3 method setupFeederHandler.
FeedHandlerV3 setupFeederHandler() throws Exception {
Executor threadPool = Executors.newCachedThreadPool();
DocumentmanagerConfig docMan = new DocumentmanagerConfig(new DocumentmanagerConfig.Builder().enablecompression(true));
FeedHandlerV3 feedHandlerV3 = new FeedHandlerV3(new FeedHandlerV3.Context(threadPool, AccessLog.voidAccessLog(), new NullFeedMetric()), docMan, null, /* session cache */
null, /* thread pool config */
new DocumentApiMetrics(MetricReceiver.nullImplementation, "test")) {
@Override
protected ReferencedResource<SharedSourceSession> retainSource(SessionCache sessionCache, SourceSessionParams sessionParams) {
SharedSourceSession sharedSourceSession = mock(SharedSourceSession.class);
try {
Mockito.stub(sharedSourceSession.sendMessageBlocking(anyObject())).toAnswer((Answer) invocation -> {
Object[] args = invocation.getArguments();
PutDocumentMessage putDocumentMessage = (PutDocumentMessage) args[0];
ReplyContext replyContext = (ReplyContext) putDocumentMessage.getContext();
replyContext.feedReplies.add(new OperationStatus("message", replyContext.docId, ErrorCode.OK, false, "trace"));
Result result = mock(Result.class);
when(result.isAccepted()).thenReturn(true);
return result;
});
} catch (InterruptedException e) {
e.printStackTrace();
}
Result result = mock(Result.class);
when(result.isAccepted()).thenReturn(true);
ReferencedResource<SharedSourceSession> refSharedSessopn = new ReferencedResource<>(sharedSourceSession, () -> {
});
return refSharedSessopn;
}
};
feedHandlerV3.injectDocumentManangerForTests(createDoctypeManager());
return feedHandlerV3;
}
use of com.yahoo.document.config.DocumentmanagerConfig in project vespa by vespa-engine.
the class DocumentTypeManagerConfigurer method setupAnnotationRefTypes.
private static void setupAnnotationRefTypes(DocumentmanagerConfig config, DocumentTypeManager manager) {
for (int i = 0; i < config.datatype().size(); i++) {
DocumentmanagerConfig.Datatype thisDataType = config.datatype(i);
int id = thisDataType.id();
for (Object o : thisDataType.annotationreftype()) {
DocumentmanagerConfig.Datatype.Annotationreftype annRefType = (DocumentmanagerConfig.Datatype.Annotationreftype) o;
AnnotationType annotationType = manager.getAnnotationTypeRegistry().getType(annRefType.annotation());
if (annotationType == null) {
throw new IllegalArgumentException("Found reference to " + annRefType.annotation() + ", which does not exist!");
}
AnnotationReferenceDataType type = new AnnotationReferenceDataType(annotationType, id);
manager.register(type);
}
}
}
use of com.yahoo.document.config.DocumentmanagerConfig in project vespa by vespa-engine.
the class DocumentTypeManagerConfigurer method setupAnnotationTypesWithoutPayloads.
private static void setupAnnotationTypesWithoutPayloads(DocumentmanagerConfig config, DocumentTypeManager manager) {
for (DocumentmanagerConfig.Annotationtype annType : config.annotationtype()) {
AnnotationType annotationType = new AnnotationType(annType.name(), annType.id());
manager.getAnnotationTypeRegistry().register(annotationType);
}
}
Aggregations