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