Search in sources :

Example 1 with DocumentmanagerConfig

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());
}
Also used : DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with DocumentmanagerConfig

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");
    }
}
Also used : DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) SearchBuilder(com.yahoo.searchdefinition.SearchBuilder) DocumentManager(com.yahoo.vespa.configmodel.producers.DocumentManager) File(java.io.File) Test(org.junit.Test)

Example 3 with DocumentmanagerConfig

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;
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) DataType(com.yahoo.document.DataType) ReplyContext(com.yahoo.vespa.http.server.ReplyContext) DocumentType(com.yahoo.document.DocumentType) OperationStatus(com.yahoo.vespa.http.client.core.OperationStatus) Assert.assertThat(org.junit.Assert.assertThat) Answer(org.mockito.stubbing.Answer) ByteArrayInputStream(java.io.ByteArrayInputStream) SharedSourceSession(com.yahoo.messagebus.shared.SharedSourceSession) ErrorCode(com.yahoo.vespa.http.client.core.ErrorCode) Matchers.anyObject(org.mockito.Matchers.anyObject) SessionCache(com.yahoo.container.jdisc.messagebus.SessionCache) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) MetricReceiver(com.yahoo.metrics.simple.MetricReceiver) Splitter(com.google.common.base.Splitter) FeedHandlerV3(com.yahoo.vespa.http.server.FeedHandlerV3) Executor(java.util.concurrent.Executor) Utf8(com.yahoo.text.Utf8) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) AccessLog(com.yahoo.container.logging.AccessLog) HttpRequest(com.yahoo.container.jdisc.HttpRequest) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ReferencedResource(com.yahoo.jdisc.ReferencedResource) Executors(java.util.concurrent.Executors) Result(com.yahoo.messagebus.Result) DocumentApiMetrics(com.yahoo.documentapi.metrics.DocumentApiMetrics) Mockito(org.mockito.Mockito) Headers(com.yahoo.vespa.http.client.core.Headers) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) SourceSessionParams(com.yahoo.messagebus.SourceSessionParams) HttpResponse(com.yahoo.container.jdisc.HttpResponse) InputStream(java.io.InputStream) Mockito.mock(org.mockito.Mockito.mock) ReferencedResource(com.yahoo.jdisc.ReferencedResource) SourceSessionParams(com.yahoo.messagebus.SourceSessionParams) SharedSourceSession(com.yahoo.messagebus.shared.SharedSourceSession) Result(com.yahoo.messagebus.Result) FeedHandlerV3(com.yahoo.vespa.http.server.FeedHandlerV3) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) Executor(java.util.concurrent.Executor) DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) DocumentApiMetrics(com.yahoo.documentapi.metrics.DocumentApiMetrics) OperationStatus(com.yahoo.vespa.http.client.core.OperationStatus) ReplyContext(com.yahoo.vespa.http.server.ReplyContext) SessionCache(com.yahoo.container.jdisc.messagebus.SessionCache) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric)

Example 4 with DocumentmanagerConfig

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);
        }
    }
}
Also used : DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 5 with DocumentmanagerConfig

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);
    }
}
Also used : DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Aggregations

DocumentmanagerConfig (com.yahoo.document.config.DocumentmanagerConfig)14 Test (org.junit.Test)7 AnnotationType (com.yahoo.document.annotation.AnnotationType)4 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)3 AnnotationReferenceDataType (com.yahoo.document.annotation.AnnotationReferenceDataType)3 DocumentManager (com.yahoo.vespa.configmodel.producers.DocumentManager)3 Splitter (com.google.common.base.Splitter)1 DocprocConfig (com.yahoo.config.docproc.DocprocConfig)1 SchemamappingConfig (com.yahoo.config.docproc.SchemamappingConfig)1 SplitterJoinerDocumentProcessorConfig (com.yahoo.config.docproc.SplitterJoinerDocumentProcessorConfig)1 ConfigGetter (com.yahoo.config.subscription.ConfigGetter)1 BundlesConfig (com.yahoo.container.BundlesConfig)1 ComponentsConfig (com.yahoo.container.ComponentsConfig)1 ChainsConfig (com.yahoo.container.core.ChainsConfig)1 ContainerMbusConfig (com.yahoo.container.jdisc.ContainerMbusConfig)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 SessionCache (com.yahoo.container.jdisc.messagebus.SessionCache)1 AccessLog (com.yahoo.container.logging.AccessLog)1 Processing (com.yahoo.docproc.Processing)1