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