Search in sources :

Example 41 with DocumentType

use of com.yahoo.document.DocumentType in project vespa by vespa-engine.

the class XMLNumericFieldErrorMsgTestCase method setupTypes.

private static DocumentTypeManager setupTypes() {
    DocumentTypeManager dtm = new DocumentTypeManager();
    DocumentType docType = new DocumentType("doctype");
    docType.addField("bytefield", DataType.BYTE);
    docType.addField("intfield", DataType.INT);
    docType.addField("longfield", DataType.LONG);
    docType.addField("floatfield", DataType.FLOAT);
    docType.addField("doublefield", DataType.DOUBLE);
    dtm.register(docType);
    return dtm;
}
Also used : DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType)

Example 42 with DocumentType

use of com.yahoo.document.DocumentType in project vespa by vespa-engine.

the class AbstractDocumentApiTestCase method requireThatSyncSessionWorks.

@Test
public void requireThatSyncSessionWorks() {
    SyncSession session = access().createSyncSession(new SyncParameters());
    DocumentType type = access().getDocumentTypeManager().getDocumentType("music");
    Document doc1 = new Document(type, new DocumentId("doc:music:1"));
    Document doc2 = new Document(type, new DocumentId("doc:music:2"));
    session.put(new DocumentPut(doc1));
    session.put(new DocumentPut(doc2));
    assertEquals(doc1, session.get(new DocumentId("doc:music:1")));
    assertEquals(doc2, session.get(new DocumentId("doc:music:2")));
    session.remove(new DocumentRemove(new DocumentId("doc:music:1")));
    assertNull(session.get(new DocumentId("doc:music:1")));
    assertEquals(doc2, session.get(new DocumentId("doc:music:2")));
    session.remove(new DocumentRemove(new DocumentId("doc:music:2")));
    assertNull(session.get(new DocumentId("doc:music:1")));
    assertNull(session.get(new DocumentId("doc:music:2")));
    session.destroy();
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) DocumentId(com.yahoo.document.DocumentId) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 43 with DocumentType

use of com.yahoo.document.DocumentType in project vespa by vespa-engine.

the class AbstractDocumentApiTestCase method requireThatAsyncHandlerWorks.

@Test
public void requireThatAsyncHandlerWorks() throws InterruptedException {
    MyHandler handler = new MyHandler();
    AsyncSession session = access().createAsyncSession(new AsyncParameters().setResponseHandler(handler));
    DocumentType type = access().getDocumentTypeManager().getDocumentType("music");
    Document doc1 = new Document(type, new DocumentId("doc:music:1"));
    assertTrue(session.put(doc1).isSuccess());
    assertTrue(handler.latch.await(60, TimeUnit.SECONDS));
    assertNotNull(handler.response);
    session.destroy();
}
Also used : DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 44 with DocumentType

use of com.yahoo.document.DocumentType in project vespa by vespa-engine.

the class VespaXMLFieldReader method read.

public void read(FieldBase field, Document document) {
    try {
        // workaround for documents inside array <item>
        if (reader.getEventType() != XMLStreamReader.START_ELEMENT || !"document".equals(reader.getName().toString())) {
            while (reader.hasNext()) {
                if (reader.getEventType() == XMLStreamReader.START_ELEMENT && "document".equals(reader.getName().toString())) {
                    break;
                }
                reader.next();
            }
        }
        // First fetch attributes.
        String typeName = null;
        for (int i = 0; i < reader.getAttributeCount(); i++) {
            final String attributeName = reader.getAttributeName(i).toString();
            if ("documentid".equals(attributeName) || "id".equals(attributeName)) {
                document.setId(new DocumentId(reader.getAttributeValue(i)));
            } else if ("documenttype".equals(attributeName) || "type".equals(attributeName)) {
                typeName = reader.getAttributeValue(i);
            } else if ("condition".equals(attributeName)) {
                condition = Optional.of(reader.getAttributeValue(i));
            }
        }
        if (document.getId() != null) {
            if (field == null) {
                field = new FieldBase(document.getId().toString());
            }
        }
        DocumentType doctype = docTypeManager.getDocumentType(typeName);
        if (doctype == null) {
            throw newDeserializeException(field, "Must specify an existing document type, not '" + typeName + "'");
        } else {
            document.setDataType(doctype);
        }
        // Then fetch fields
        while (reader.hasNext()) {
            int type = reader.next();
            if (type == XMLStreamReader.START_ELEMENT) {
                Field f = doctype.getField(reader.getName().toString());
                if (f == null) {
                    throw newDeserializeException(field, "Field " + reader.getName() + " not found.");
                }
                FieldValue fv = f.getDataType().createFieldValue();
                fv.deserialize(f, this);
                document.setFieldValue(f, fv);
                skipToEnd(f.getName());
            } else if (type == XMLStreamReader.END_ELEMENT) {
                return;
            }
        }
    } catch (XMLStreamException e) {
        throw newException(field, e);
    }
}
Also used : Field(com.yahoo.document.Field) XMLStreamException(javax.xml.stream.XMLStreamException) DocumentId(com.yahoo.document.DocumentId) FieldBase(com.yahoo.vespa.objects.FieldBase) DocumentType(com.yahoo.document.DocumentType)

Example 45 with DocumentType

use of com.yahoo.document.DocumentType in project vespa by vespa-engine.

the class ApplicationTest method client.

@Test
public void client() throws Exception {
    try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().documentType("test", IOUtils.toString(this.getClass().getResourceAsStream("/test.sd"))).container("default", new Application.Builder.Container().client("mbus://*/*", MockClient.class).documentProcessor(MockDispatchDocproc.class))))) {
        Map<String, DocumentType> typeMap = app.application().getJDisc("jdisc").documentProcessing().getDocumentTypes();
        assertNotNull(typeMap);
        DocumentType docType = typeMap.get("test");
        Document doc = new Document(docType, "id:foo:test::bar");
        doc.setFieldValue("title", "hello");
        assertEquals(DocumentProcessor.Progress.DONE, app.process(new DocumentPut(doc)));
        MockClient client = (MockClient) app.getClientById(MockClient.class.getName());
        assertNotNull(client);
        assertEquals(1, client.getCounter());
        MockDispatchDocproc docproc = (MockDispatchDocproc) app.getComponentById(MockDispatchDocproc.class.getName() + "@default");
        assertNotNull(docproc);
        assertEquals(1, docproc.getResponses().size());
        assertEquals(200, docproc.getResponses().get(0).getStatus());
    }
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) MockDispatchDocproc(com.yahoo.application.container.docprocs.MockDispatchDocproc) Document(com.yahoo.document.Document) MockClient(com.yahoo.application.container.MockClient) Test(org.junit.Test)

Aggregations

DocumentType (com.yahoo.document.DocumentType)98 Test (org.junit.Test)45 Document (com.yahoo.document.Document)41 DocumentPut (com.yahoo.document.DocumentPut)35 Field (com.yahoo.document.Field)24 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)24 DocumentId (com.yahoo.document.DocumentId)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19 InputStream (java.io.InputStream)19 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)17 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)17 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)17 DocumentUpdate (com.yahoo.document.DocumentUpdate)15 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)15 StructDataType (com.yahoo.document.StructDataType)14 TensorDataType (com.yahoo.document.TensorDataType)12 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)11 ArrayDataType (com.yahoo.document.ArrayDataType)10 MapDataType (com.yahoo.document.MapDataType)10 ReferenceDataType (com.yahoo.document.ReferenceDataType)10