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();
}
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"));
}
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());
}
Aggregations