Search in sources :

Example 96 with DocumentType

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

the class AbstractDocumentApiTestCase method requireThatAsyncSessionWorks.

@Test
public void requireThatAsyncSessionWorks() throws InterruptedException {
    AsyncSession session = access().createAsyncSession(new AsyncParameters());
    HashMap<Long, Response> results = new LinkedHashMap<>();
    Result result;
    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"));
    result = session.put(doc1);
    assertTrue(result.isSuccess());
    results.put(result.getRequestId(), new Response(result.getRequestId()));
    result = session.put(doc2);
    assertTrue(result.isSuccess());
    results.put(result.getRequestId(), new Response(result.getRequestId()));
    List<Response> responses = new ArrayList<>();
    waitForAcks(session, 2, responses);
    result = session.get(new DocumentId("doc:music:1"));
    assertTrue(result.isSuccess());
    results.put(result.getRequestId(), new DocumentResponse(result.getRequestId(), doc1));
    result = session.get(new DocumentId("doc:music:2"));
    assertTrue(result.isSuccess());
    results.put(result.getRequestId(), new DocumentResponse(result.getRequestId(), doc2));
    // These Gets shall observe the ACKed Puts sent for the same document IDs.
    waitForAcks(session, 2, responses);
    result = session.remove(new DocumentId("doc:music:1"));
    assertTrue(result.isSuccess());
    results.put(result.getRequestId(), new Response(result.getRequestId()));
    waitForAcks(session, 1, responses);
    result = session.get(new DocumentId("doc:music:1"));
    assertTrue(result.isSuccess());
    results.put(result.getRequestId(), new DocumentResponse(result.getRequestId()));
    result = session.get(new DocumentId("doc:music:2"));
    assertTrue(result.isSuccess());
    results.put(result.getRequestId(), new DocumentResponse(result.getRequestId(), doc2));
    waitForAcks(session, 2, responses);
    result = session.remove(new DocumentId("doc:music:2"));
    assertTrue(result.isSuccess());
    results.put(result.getRequestId(), new Response(result.getRequestId()));
    waitForAcks(session, 1, responses);
    result = session.get(new DocumentId("doc:music:1"));
    assertTrue(result.isSuccess());
    results.put(result.getRequestId(), new DocumentResponse(result.getRequestId()));
    result = session.get(new DocumentId("doc:music:2"));
    assertTrue(result.isSuccess());
    results.put(result.getRequestId(), new DocumentResponse(result.getRequestId()));
    waitForAcks(session, 2, responses);
    for (Response response : responses) {
        assertTrue(response.isSuccess());
        assertEquals(results.get(response.getRequestId()), response);
    }
    session.destroy();
}
Also used : DocumentId(com.yahoo.document.DocumentId) ArrayList(java.util.ArrayList) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 97 with DocumentType

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

the class SimpleAdapterFactoryTestCase method requireThatFieldUpdateCanHaveManyPartialUpdatesForOneField.

@Test
public void requireThatFieldUpdateCanHaveManyPartialUpdatesForOneField() {
    DocumentType docType = new DocumentType("my_type");
    DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:foo:1");
    Field field = new Field("my_int", DataType.INT);
    docType.addField(field);
    FieldUpdate fieldUpdate = FieldUpdate.create(field);
    fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(1));
    fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(2));
    fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(4));
    docUpdate.addFieldUpdate(fieldUpdate);
    SimpleAdapterFactory factory = new SimpleAdapterFactory();
    List<UpdateAdapter> adapters = factory.newUpdateAdapterList(docUpdate);
    assertEquals(4, adapters.size());
    UpdateAdapter adapter = adapters.get(0);
    assertNotNull(adapter);
    assertEquals(new IntegerFieldValue(1), adapter.getInputValue("my_int"));
    assertNotNull(adapter = adapters.get(1));
    assertEquals(new IntegerFieldValue(2), adapter.getInputValue("my_int"));
    assertNotNull(adapter = adapters.get(2));
    assertEquals(new IntegerFieldValue(4), adapter.getInputValue("my_int"));
    assertNotNull(adapter = adapters.get(3));
    // always add an adapter for complete updates
    assertNull(adapter.getInputValue("my_int"));
}
Also used : Field(com.yahoo.document.Field) DocumentUpdate(com.yahoo.document.DocumentUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 98 with DocumentType

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

the class SimpleAdapterFactoryTestCase method requireThatCompleteUpdatesAreCombined.

@Test
public void requireThatCompleteUpdatesAreCombined() {
    DocumentType docType = new DocumentType("my_type");
    DocumentUpdate update = new DocumentUpdate(docType, "doc:foo:1");
    Field field1 = new Field("int1", DataType.INT);
    Field field2 = new Field("int2", DataType.INT);
    Field field3 = new Field("int3", DataType.INT);
    docType.addField(field1);
    docType.addField(field2);
    docType.addField(field3);
    update.addFieldUpdate(FieldUpdate.createAssign(field1, new IntegerFieldValue(10)));
    update.addFieldUpdate(FieldUpdate.createAssign(field2, new IntegerFieldValue(20)));
    update.addFieldUpdate(FieldUpdate.createIncrement(field3, 30));
    SimpleAdapterFactory factory = new SimpleAdapterFactory();
    List<UpdateAdapter> adapters = factory.newUpdateAdapterList(update);
    assertEquals(2, adapters.size());
}
Also used : Field(com.yahoo.document.Field) DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) 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