Search in sources :

Example 26 with DocumentId

use of com.yahoo.document.DocumentId 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 27 with DocumentId

use of com.yahoo.document.DocumentId 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 28 with DocumentId

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

the class Simulator method getIdealTarget.

private Integer getIdealTarget(String idString, String clusterState) {
    DocumentId did = new DocumentId(idString);
    BucketIdFactory factory = new BucketIdFactory();
    BucketId bid = factory.getBucketId(did);
    try {
        return policyFactory.getLastParameters().createDistribution(null).getIdealDistributorNode(new ClusterState(clusterState), bid, "uim");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DocumentId(com.yahoo.document.DocumentId) BucketId(com.yahoo.document.BucketId) BucketIdFactory(com.yahoo.document.BucketIdFactory)

Example 29 with DocumentId

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

the class VespaDocumentDeserializer42 method read.

public void read(DocumentUpdate update) {
    short serializationVersion = getShort(null);
    update.setId(new DocumentId(this));
    byte contents = getByte(null);
    if ((contents & 0x1) == 0) {
        throw new DeserializationException("Cannot deserialize DocumentUpdate without doctype");
    }
    update.setDocumentType(readDocumentType());
    int size = getInt(null);
    for (int i = 0; i < size; i++) {
        // TODO: Should use checked method, but doesn't work according to test now.
        update.addFieldUpdateNoCheck(new FieldUpdate(this, update.getDocumentType(), serializationVersion));
    }
}
Also used : DocumentId(com.yahoo.document.DocumentId) FieldUpdate(com.yahoo.document.update.FieldUpdate)

Example 30 with DocumentId

use of com.yahoo.document.DocumentId 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)

Aggregations

DocumentId (com.yahoo.document.DocumentId)61 Test (org.junit.Test)28 DocumentType (com.yahoo.document.DocumentType)20 Document (com.yahoo.document.Document)16 DocumentPut (com.yahoo.document.DocumentPut)12 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)9 BucketId (com.yahoo.document.BucketId)7 DocumentRemove (com.yahoo.document.DocumentRemove)5 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 BucketIdFactory (com.yahoo.document.BucketIdFactory)4 FieldUpdate (com.yahoo.document.update.FieldUpdate)4 DocumentOperation (com.yahoo.document.DocumentOperation)3 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 Hit (com.yahoo.search.result.Hit)3 HashMap (java.util.HashMap)3 TestDocumentProcessor1 (com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1)2 Field (com.yahoo.document.Field)2 GlobalId (com.yahoo.document.GlobalId)2 StructDataType (com.yahoo.document.StructDataType)2 Struct (com.yahoo.document.datatypes.Struct)2