use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class DocumentModelBuilder method extractNestedTypes.
private static void extractNestedTypes(NewDocumentType dt, DataType type) {
if (type instanceof StructDataType) {
StructDataType tmp = (StructDataType) type;
extractDataTypesFromFields(dt, tmp.getFieldsThisTypeOnly());
} else if (type instanceof DocumentType) {
throw new IllegalArgumentException("Can not handle nested document definitions. In document type '" + dt.getName().toString() + "', we can not define document type '" + type.toString());
} else if (type instanceof CollectionDataType) {
CollectionDataType tmp = (CollectionDataType) type;
extractNestedTypes(dt, tmp.getNestedType());
addType(dt, tmp.getNestedType());
} else if (type instanceof MapDataType) {
MapDataType tmp = (MapDataType) type;
extractNestedTypes(dt, tmp.getKeyType());
extractNestedTypes(dt, tmp.getValueType());
addType(dt, tmp.getKeyType());
addType(dt, tmp.getValueType());
} else if (type instanceof TemporaryAnnotationReferenceDataType) {
throw new IllegalArgumentException(type.toString());
}
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class JDiscContainerDocprocTest method requireThatBasicDocumentProcessingWorks.
@Test
public void requireThatBasicDocumentProcessingWorks() throws Exception {
try (Application app = new ApplicationBuilder().servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())).documentType("music", DOCUMENT).build()) {
JDisc container = app.getJDisc("container");
DocumentProcessing docProc = container.documentProcessing();
DocumentType type = docProc.getDocumentTypes().get("music");
ChainRegistry<DocumentProcessor> chains = docProc.getChains();
assertTrue(chains.allComponentsById().containsKey(new ComponentId(CHAIN_NAME)));
Document doc = new Document(type, "doc:this:is:a:great:album");
doc.setFieldValue("title", "Great Album!");
com.yahoo.docproc.Processing processing;
DocumentProcessor.Progress progress;
DocumentPut put = new DocumentPut(doc);
processing = com.yahoo.docproc.Processing.of(put);
progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
assertThat(doc.getFieldValue("title").toString(), equalTo("Terng Nyohz!"));
processing = com.yahoo.docproc.Processing.of(put);
progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
}
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class EntryTestCase method testEquals.
public void testEquals() {
DocumentTypeManager manager = new DocumentTypeManager();
DocumentTypeManagerConfigurer.configure(manager, "file:src/test/files/documentmanager.cfg");
DocumentType bmType = manager.getDocumentType("benchmark");
DocumentPut put1 = new DocumentPut(bmType, "userdoc:foo:99999999:1");
DocumentPut put2 = new DocumentPut(bmType, "userdoc:foo:99999999:2");
Entry entry1 = Entry.create(put1);
Entry entry2 = Entry.create(put1);
assert (entry1.equals(entry2));
Entry entry3 = Entry.create(put2);
assert (!entry1.equals(entry3));
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class EntryTestCase method testHashCode.
public void testHashCode() {
DocumentTypeManager manager = new DocumentTypeManager();
DocumentTypeManagerConfigurer.configure(manager, "file:src/test/files/documentmanager.cfg");
DocumentType bmType = manager.getDocumentType("benchmark");
DocumentPut put1 = new DocumentPut(bmType, "userdoc:foo:99999999:1");
DocumentPut put2 = new DocumentPut(bmType, "userdoc:foo:99999999:2");
Entry entry1 = Entry.create(put1);
Entry entry2 = Entry.create(put1);
assert (entry1.hashCode() == entry2.hashCode());
Entry entry3 = Entry.create(put2);
assert (entry1.hashCode() != entry3.hashCode());
}
use of com.yahoo.document.DocumentType in project vespa by vespa-engine.
the class VisitorSearcherTestCase method setUp.
@org.junit.Before
public void setUp() {
docMan = new DocumentTypeManager();
docType = new DocumentType("kittens");
docType.addHeaderField("name", DataType.STRING);
docType.addField("description", DataType.STRING);
docType.addField("image", DataType.RAW);
docType.addField("fluffiness", DataType.INT);
docType.addField("foo", DataType.RAW);
docMan.registerDocumentType(docType);
factory = new DocumentSessionFactory(docType);
}
Aggregations