Search in sources :

Example 1 with ApplicationBuilder

use of com.yahoo.application.ApplicationBuilder in project vespa by vespa-engine.

the class JDiscContainerDocprocTest method requireThatLaterDocumentProcessingWorks.

@Test
public void requireThatLaterDocumentProcessingWorks() throws Exception {
    try (Application app = new ApplicationBuilder().servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())).networking(Networking.disable).documentType("music", DOCUMENT).build()) {
        JDisc container = app.getJDisc("container");
        DocumentProcessing docProc = container.documentProcessing();
        DocumentType type = docProc.getDocumentTypes().get("music");
        ChainRegistry<DocumentProcessor> chains = docProc.getChains();
        assertTrue(chains.allComponentsById().containsKey(new ComponentId(CHAIN_NAME)));
        Document doc = new Document(type, "doc:this:is:a:great:album");
        doc.setFieldValue("title", "Great Album!");
        com.yahoo.docproc.Processing processing;
        DocumentProcessor.Progress progress;
        DocumentPut put = new DocumentPut(doc);
        processing = com.yahoo.docproc.Processing.of(put);
        progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, instanceOf(DocumentProcessor.LaterProgress.class));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
        progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, instanceOf(DocumentProcessor.LaterProgress.class));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
        progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Terng Nyohz!"));
    }
}
Also used : Rot13DocumentProcessor(com.yahoo.application.container.docprocs.Rot13DocumentProcessor) Rot13DocumentProcessor(com.yahoo.application.container.docprocs.Rot13DocumentProcessor) DocumentProcessor(com.yahoo.docproc.DocumentProcessor) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) ApplicationBuilder(com.yahoo.application.ApplicationBuilder) Application(com.yahoo.application.Application) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 2 with ApplicationBuilder

use of com.yahoo.application.ApplicationBuilder in project vespa by vespa-engine.

the class JDiscContainerDocprocTest method requireThatBasicDocumentProcessingWorks.

@Test
public void requireThatBasicDocumentProcessingWorks() throws Exception {
    try (Application app = new ApplicationBuilder().servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())).documentType("music", DOCUMENT).build()) {
        JDisc container = app.getJDisc("container");
        DocumentProcessing docProc = container.documentProcessing();
        DocumentType type = docProc.getDocumentTypes().get("music");
        ChainRegistry<DocumentProcessor> chains = docProc.getChains();
        assertTrue(chains.allComponentsById().containsKey(new ComponentId(CHAIN_NAME)));
        Document doc = new Document(type, "doc:this:is:a:great:album");
        doc.setFieldValue("title", "Great Album!");
        com.yahoo.docproc.Processing processing;
        DocumentProcessor.Progress progress;
        DocumentPut put = new DocumentPut(doc);
        processing = com.yahoo.docproc.Processing.of(put);
        progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Terng Nyohz!"));
        processing = com.yahoo.docproc.Processing.of(put);
        progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
    }
}
Also used : Rot13DocumentProcessor(com.yahoo.application.container.docprocs.Rot13DocumentProcessor) DocumentProcessor(com.yahoo.docproc.DocumentProcessor) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) ApplicationBuilder(com.yahoo.application.ApplicationBuilder) Application(com.yahoo.application.Application) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Aggregations

Application (com.yahoo.application.Application)2 ApplicationBuilder (com.yahoo.application.ApplicationBuilder)2 Rot13DocumentProcessor (com.yahoo.application.container.docprocs.Rot13DocumentProcessor)2 ComponentId (com.yahoo.component.ComponentId)2 DocumentProcessor (com.yahoo.docproc.DocumentProcessor)2 Document (com.yahoo.document.Document)2 DocumentPut (com.yahoo.document.DocumentPut)2 DocumentType (com.yahoo.document.DocumentType)2 Test (org.junit.Test)2