diff options
author | Geir Storli <geirst@yahooinc.com> | 2023-03-13 13:55:29 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahooinc.com> | 2023-03-13 13:59:08 +0000 |
commit | 0c657642eff7d85c000464e9edba16ded4845e7d (patch) | |
tree | 3315f420e49dd85739089780388007ce1649672a /document/src | |
parent | a40183094fd45dbf320dd57f8d56a5a6fac7f247 (diff) |
Reduce creation of Document instances without DocumentTypeRepo.
Diffstat (limited to 'document/src')
20 files changed, 136 insertions, 131 deletions
diff --git a/document/src/tests/documentcalculatortestcase.cpp b/document/src/tests/documentcalculatortestcase.cpp index 7e27dcf2d36..dafc87f4ccd 100644 --- a/document/src/tests/documentcalculatortestcase.cpp +++ b/document/src/tests/documentcalculatortestcase.cpp @@ -24,7 +24,7 @@ TEST_F(DocumentCalculatorTest, testConstant) { auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "4.0"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); + Document doc(_testRepo.getTypeRepo(), *_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); EXPECT_EQ(4.0, calc.evaluate(doc, std::move(variables))); } @@ -32,7 +32,7 @@ TEST_F(DocumentCalculatorTest, testSimple) { auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "(3 + 5) / 2"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); + Document doc(_testRepo.getTypeRepo(), *_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); EXPECT_EQ(4.0, calc.evaluate(doc, std::move(variables))); } @@ -42,7 +42,7 @@ TEST_F(DocumentCalculatorTest, testVariables) { (*variables)["y"] = 5.0; DocumentCalculator calc(getRepo(), "($x + $y) / 2"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); + Document doc(_testRepo.getTypeRepo(), *_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); EXPECT_EQ(4.0, calc.evaluate(doc, std::move(variables))); } @@ -53,7 +53,7 @@ TEST_F(DocumentCalculatorTest, testFields) { DocumentCalculator calc(getRepo(), "(testdoctype1.headerval + testdoctype1" ".hfloatval) / testdoctype1.headerlongval"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); + Document doc(_testRepo.getTypeRepo(), *_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); doc.setValue(doc.getField("headerval"), IntFieldValue(5)); doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0)); doc.setValue(doc.getField("headerlongval"), LongFieldValue(2)); @@ -67,7 +67,7 @@ TEST_F(DocumentCalculatorTest, testFieldsDivZero) { DocumentCalculator calc(getRepo(), "(testdoctype1.headerval + testdoctype1" ".hfloatval) / testdoctype1.headerlongval"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); + Document doc(_testRepo.getTypeRepo(), *_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); doc.setValue(doc.getField("headerval"), IntFieldValue(5)); doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0)); doc.setValue(doc.getField("headerlongval"), LongFieldValue(0)); @@ -79,7 +79,7 @@ TEST_F(DocumentCalculatorTest, testDivideByZero) { auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "(3 + 5) / 0"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); + Document doc(_testRepo.getTypeRepo(), *_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); EXPECT_THROW(calc.evaluate(doc, std::move(variables)), vespalib::IllegalArgumentException); } @@ -88,7 +88,7 @@ TEST_F(DocumentCalculatorTest, testModByZero) { auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "(3 + 5) % 0"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); + Document doc(_testRepo.getTypeRepo(), *_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); EXPECT_THROW(calc.evaluate(doc, std::move(variables)), vespalib::IllegalArgumentException); } @@ -98,7 +98,7 @@ TEST_F(DocumentCalculatorTest, testFieldNotSet) { DocumentCalculator calc(getRepo(), "(testdoctype1.headerval + testdoctype1" ".hfloatval) / testdoctype1.headerlongval"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); + Document doc(_testRepo.getTypeRepo(), *_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0)); doc.setValue(doc.getField("headerlongval"), LongFieldValue(2)); EXPECT_THROW(calc.evaluate(doc, std::move(variables)), @@ -111,7 +111,7 @@ TEST_F(DocumentCalculatorTest, testFieldNotFound) { "(testdoctype1.mynotfoundfield + testdoctype1" ".hfloatval) / testdoctype1.headerlongval"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); + Document doc(_testRepo.getTypeRepo(), *_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0)); doc.setValue(doc.getField("headerlongval"), LongFieldValue(2)); EXPECT_THROW(calc.evaluate(doc, std::move(variables)), @@ -122,7 +122,7 @@ TEST_F(DocumentCalculatorTest, testByteSubtractionZeroResult) { auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "testdoctype1.byteval - 3"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); + Document doc(_testRepo.getTypeRepo(), *_testRepo.getDocumentType("testdoctype1"), DocumentId("id:ns:testdoctype1::foo")); doc.setValue(doc.getField("byteval"), ByteFieldValue(3)); EXPECT_EQ(0.0, calc.evaluate(doc, std::move(variables))); } diff --git a/document/src/tests/documentselectparsertest.cpp b/document/src/tests/documentselectparsertest.cpp index 5e14a080f27..13ad2873bfa 100644 --- a/document/src/tests/documentselectparsertest.cpp +++ b/document/src/tests/documentselectparsertest.cpp @@ -120,7 +120,7 @@ Document::SP DocumentSelectParserTest::createDoc( uint64_t hlong) { const DocumentType* type = _repo->getDocumentType(doctype); - auto doc = std::make_shared<Document>(*type, DocumentId(id)); + auto doc = std::make_shared<Document>(*_repo, *type, DocumentId(id)); doc->setValue(doc->getField("headerval"), IntFieldValue(hint)); if (hlong != 0) { @@ -1662,7 +1662,7 @@ TEST_F(DocumentSelectParserTest, test_parse_utilities_handle_malformed_input) TEST_F(DocumentSelectParserTest, imported_field_references_are_treated_as_valid_field_with_missing_value) { const DocumentType* type = _repo->getDocumentType("with_imported"); ASSERT_TRUE(type != nullptr); - Document doc(*type, DocumentId("id::with_imported::foo")); + Document doc(*_repo, *type, DocumentId("id::with_imported::foo")); PARSE("with_imported.my_imported_field == null", doc, True); PARSE("with_imported.my_imported_field != null", doc, False); @@ -1674,7 +1674,7 @@ TEST_F(DocumentSelectParserTest, imported_field_references_are_treated_as_valid_ TEST_F(DocumentSelectParserTest, imported_field_references_only_support_for_simple_expressions) { const DocumentType* type = _repo->getDocumentType("with_imported"); ASSERT_TRUE(type != nullptr); - Document doc(*type, DocumentId("id::with_imported::foo")); + Document doc(*_repo, *type, DocumentId("id::with_imported::foo")); PARSE("with_imported.my_imported_field.foo", doc, Invalid); PARSE("with_imported.my_imported_field[0]", doc, Invalid); diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index bc4065438e6..2e9e783470c 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -136,8 +136,8 @@ TEST(DocumentTest, testTraversing) type.addField(primitive1); type.addField(structl1s1); - Document doc(type, DocumentId("id:ns:test::1")); - doc.setValue(primitive1, IntFieldValue(1)); + auto doc = Document::make_without_repo(type, DocumentId("id:ns:test::1")); + doc->setValue(primitive1, IntFieldValue(1)); StructFieldValue l1s1(struct3); l1s1.setValue(primitive1, IntFieldValue(2)); @@ -159,11 +159,11 @@ TEST(DocumentTest, testTraversing) l2s1.setValue(sarrF, sarr1); l1s1.setValue(s2, l2s1); - doc.setValue(structl1s1, l1s1); + doc->setValue(structl1s1, l1s1); Handler fullTraverser; FieldPath empty; - doc.iterateNested(empty.getFullRange(), fullTraverser); + doc->iterateNested(empty.getFullRange(), fullTraverser); EXPECT_EQ(fullTraverser.getResult(), std::string("<0:P-0<0:P-0<0:P-0P-0[P-0P-1P-2][<0:P-0P-0><1:P-1P-1>]>>>")); } @@ -208,14 +208,14 @@ TEST(DocumentTest, testVariables) iiiaV.add(iiaV); } - Document doc(type, DocumentId("id:ns:test::1")); - doc.setValue(iiiarrF, iiiaV); + auto doc = Document::make_without_repo(type, DocumentId("id:ns:test::1")); + doc->setValue(iiiarrF, iiiaV); { VariableIteratorHandler handler; FieldPath path; type.buildFieldPath(path, "iiiarray[$x][$y][$z]"); - doc.iterateNested(path.getFullRange(), handler); + doc->iterateNested(path.getFullRange(), handler); std::string fasit = "x: 0,y: 0,z: 0, - 1\n" @@ -315,7 +315,7 @@ TEST(DocumentTest, testModifyDocument) type.addField(primitive1); type.addField(structl1s1); - Document::UP doc(new Document(type, DocumentId("id:ns:test::1"))); + auto doc = Document::make_without_repo(type, DocumentId("id:ns:test::1")); doc->setValue(primitive1, IntFieldValue(1)); StructFieldValue l1s1(struct3); @@ -389,7 +389,7 @@ TEST(DocumentTest, testSimpleUsage) type->addField(strF); DocumentTypeRepo repo(*type); - Document value(*repo.getDocumentType("test"), DocumentId("id:ns:test::1")); + Document value(repo, *repo.getDocumentType("test"), DocumentId("id:ns:test::1")); // Initially empty EXPECT_EQ(size_t(0), value.getSetFieldCount()); @@ -412,7 +412,7 @@ TEST(DocumentTest, testSimpleUsage) // Serialize & equality nbostream buffer; value.serialize(buffer); - Document value2(*repo.getDocumentType("test"), + Document value2(repo, *repo.getDocumentType("test"), DocumentId("id::test:n=3:foo")); EXPECT_TRUE(value != value2); value2.deserialize(repo, buffer); @@ -508,7 +508,7 @@ TEST(DocumentTest, testSimpleUsage) // Refuse to accept non-document types try{ StructDataType otherType("foo", 4); - Document value6(otherType, DocumentId("id:ns:foo::1")); + auto doc = Document::make_without_repo(otherType, DocumentId("id:ns:foo::1")); FAIL() << "Didn't complain about non-document type"; } catch (std::exception& e) { EXPECT_THAT(e.what(), HasSubstr("Cannot generate a document with non-document type")); @@ -706,7 +706,7 @@ TEST(DocumentTest,testReadSerializedAllVersions) // Create a memory instance of document { - Document doc(*docType, DocumentId("id:ns:serializetest::http://test.doc.id/")); + Document doc(repo, *docType, DocumentId("id:ns:serializetest::http://test.doc.id/")); doc.setValue("intfield", IntFieldValue::make(5)); doc.setValue("floatfield", FloatFieldValue::make(-9.23)); doc.setValue("stringfield", StringFieldValue::make("This is a string.")); @@ -714,7 +714,7 @@ TEST(DocumentTest,testReadSerializedAllVersions) doc.setValue("doublefield", DoubleFieldValue::make(98374532.398820)); doc.setValue("bytefield", ByteFieldValue::make(-2)); doc.setValue("rawfield", std::make_unique<RawFieldValue>("RAW DATA", 8)); - Document docInDoc(*docInDocType, DocumentId("id:ns:docindoc::http://doc.in.doc/")); + Document docInDoc(repo, *docInDocType, DocumentId("id:ns:docindoc::http://doc.in.doc/")); docInDoc.setValue("stringindocfield", StringFieldValue::make("Elvis is dead")); doc.setValue("docfield", docInDoc); ArrayFieldValue floatArray(*arrayOfFloatDataType); @@ -828,7 +828,7 @@ TEST(DocumentTest, testGenerateSerializedFile) { const std::string file_name = TEST_PATH("data/crossplatform-java-cpp-doctypes.cfg"); DocumentTypeRepo repo(readDocumenttypesConfig(file_name)); - Document doc(*repo.getDocumentType("serializetest"), DocumentId("id:ns:serializetest::http://test.doc.id/")); + Document doc(repo, *repo.getDocumentType("serializetest"), DocumentId("id:ns:serializetest::http://test.doc.id/")); doc.setValue("intfield", IntFieldValue::make(5)); doc.setValue("floatfield", FloatFieldValue::make(-9.23)); @@ -841,7 +841,7 @@ TEST(DocumentTest, testGenerateSerializedFile) const DocumentType *docindoc_type = repo.getDocumentType("docindoc"); EXPECT_TRUE(docindoc_type); - Document embedDoc(*docindoc_type, DocumentId("id:ns:docindoc::http://embedded")); + Document embedDoc(repo, *docindoc_type, DocumentId("id:ns:docindoc::http://embedded")); doc.setValue("docfield", embedDoc); @@ -949,7 +949,7 @@ TEST(DocumentTest, testUnknownEntries) DocumentTypeRepo repo(type2); - Document doc1(type1, DocumentId("id:ns:test::1")); + Document doc1(repo, type1, DocumentId("id:ns:test::1")); doc1.setValue(field1, IntFieldValue(1)); doc1.setValue(field2, IntFieldValue(2)); doc1.setValue(field3, IntFieldValue(3)); diff --git a/document/src/tests/documenttypetestcase.cpp b/document/src/tests/documenttypetestcase.cpp index 95ee3f4deed..df6d8aa900f 100644 --- a/document/src/tests/documenttypetestcase.cpp +++ b/document/src/tests/documenttypetestcase.cpp @@ -108,7 +108,7 @@ TEST(DocumentTypeTest, testMultipleInheritance) EXPECT_TRUE(docType3->hasField("tmp")); EXPECT_TRUE(docType3->hasField("tall")); - Document doc(*docType3, DocumentId("id:ns:test3::1")); + Document doc(repo, *docType3, DocumentId("id:ns:test3::1")); IntFieldValue intVal(3); doc.setValue(doc.getField("nalle"), intVal); diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp index 7a5d88d1013..3fbccaa155f 100644 --- a/document/src/tests/documentupdatetestcase.cpp +++ b/document/src/tests/documentupdatetestcase.cpp @@ -141,7 +141,7 @@ TEST(DocumentUpdateTest, testSimpleUsage) auto docUpdateCopy(DocumentUpdate::createHEAD(repo, docBuf)); // Create a test document - Document doc(*docType, DocumentId("id:ns:test::1")); + Document doc(repo, *docType, DocumentId("id:ns:test::1")); doc.setValue("bytef", ByteFieldValue::make(0)); doc.setValue("intf", IntFieldValue::make(5)); ArrayFieldValue array(*arrayType); @@ -417,7 +417,7 @@ WeightedSetAutoCreateFixture::~WeightedSetAutoCreateFixture() = default; WeightedSetAutoCreateFixture::WeightedSetAutoCreateFixture() : repo(makeConfig()), docType(repo.getDocumentType("test")), - doc(*docType, DocumentId("id:ns:test::1")), + doc(repo, *docType, DocumentId("id:ns:test::1")), field(docType->getField("strwset")), update(repo, *docType, DocumentId("id:ns:test::1")) { @@ -1355,7 +1355,7 @@ struct UpdateToEmptyDocumentFixture { Document::UP make_empty_doc() { vespalib::nbostream stream; { - Document doc(doc_type, DocumentId("id:test:test::0")); + Document doc(*repo, doc_type, DocumentId("id:test:test::0")); VespaDocumentSerializer serializer(stream); serializer.write(doc); } diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp index a32face5e55..e9f984c9586 100644 --- a/document/src/tests/fieldpathupdatetestcase.cpp +++ b/document/src/tests/fieldpathupdatetestcase.cpp @@ -133,8 +133,7 @@ FieldPathUpdateTestCase::TearDown() TEST_F(FieldPathUpdateTestCase, testRemoveField) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:thangs")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::things:thangs")); EXPECT_TRUE(doc->hasValue("strfoo") == false); doc->setValue("strfoo", StringFieldValue("cocacola")); EXPECT_EQ(vespalib::string("cocacola"), doc->getValue("strfoo")->getAsString()); @@ -146,8 +145,7 @@ TEST_F(FieldPathUpdateTestCase, testRemoveField) TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:thangs")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::things:thangs")); EXPECT_TRUE(doc->hasValue("strarray") == false); { ArrayFieldValue strArray(doc->getType().getField("strarray").getDataType()); @@ -171,8 +169,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList) TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList2) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:thangs")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::things:thangs")); EXPECT_TRUE(doc->hasValue("strarray") == false); { ArrayFieldValue strArray(doc->getType().getField("strarray").getDataType()); @@ -195,8 +192,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiList2) TEST_F(FieldPathUpdateTestCase, testApplyRemoveEntireListField) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:thangs")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::things:thangs")); EXPECT_TRUE(doc->hasValue("strarray") == false); { ArrayFieldValue strArray(doc->getType().getField("strarray").getDataType()); @@ -214,8 +210,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveEntireListField) TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiWset) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::helan:halvan")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::helan:halvan")); EXPECT_TRUE(doc->hasValue("strwset") == false); { WeightedSetFieldValue strWset(doc->getType().getField("strwset").getDataType()); @@ -237,8 +232,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyRemoveMultiWset) TEST_F(FieldPathUpdateTestCase, testApplyAssignSingle) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::drekka:karsk")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::drekka:karsk")); EXPECT_TRUE(doc->hasValue("strfoo") == false); // Test assignment of non-existing DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); @@ -255,8 +249,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignSingle) TEST_F(FieldPathUpdateTestCase, testApplyAssignMath) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bat:man")); doc->setValue("num", IntFieldValue(34)); DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); @@ -267,8 +260,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMath) TEST_F(FieldPathUpdateTestCase, testApplyAssignMathByteToZero) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bat:man")); doc->setValue("byteval", ByteFieldValue(3)); DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); @@ -280,8 +272,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathByteToZero) TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnUnderflow) { int low_value = -126; - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bat:man")); doc->setValue("byteval", ByteFieldValue(low_value)); DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); @@ -293,8 +284,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnUnderflow) TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnOverflow) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bat:man")); doc->setValue("byteval", ByteFieldValue(127)); DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); @@ -306,8 +296,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathNotModifiedOnOverflow) TEST_F(FieldPathUpdateTestCase, testApplyAssignMathDivZero) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bat:man")); EXPECT_TRUE(doc->hasValue("num") == false); doc->setValue("num", IntFieldValue(10)); @@ -319,8 +308,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathDivZero) TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInExpression) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bat:man")); EXPECT_TRUE(doc->hasValue("num") == false); doc->setValue("num", IntFieldValue(10)); @@ -332,8 +320,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInExpression) TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInPath) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bat:man")); DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); try { @@ -346,8 +333,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignFieldNotExistingInPath) TEST_F(FieldPathUpdateTestCase, testApplyAssignTargetNotExisting) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bat:man")); EXPECT_TRUE(doc->hasValue("num") == false); DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); @@ -358,8 +344,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignTargetNotExisting) TEST_F(FieldPathUpdateTestCase, testAssignSimpleMapValueWithVariable) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bug:hunter")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bug:hunter")); MapFieldValue mfv(doc->getType().getField("strmap").getDataType()); mfv.put(StringFieldValue("foo"), StringFieldValue("bar")); @@ -385,8 +370,7 @@ TEST_F(FieldPathUpdateTestCase, testAssignSimpleMapValueWithVariable) TEST_F(FieldPathUpdateTestCase, testApplyAssignMathRemoveIfZero) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bat:man")); EXPECT_TRUE(doc->hasValue("num") == false); doc->setValue("num", IntFieldValue(34)); EXPECT_TRUE(doc->hasValue("num") == true); @@ -402,8 +386,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMathRemoveIfZero) TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiList) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::fest:skinnvest")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::fest:skinnvest")); EXPECT_TRUE(doc->hasValue("strarray") == false); { @@ -432,8 +415,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiList) TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiWset) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::fest:skinnvest")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::fest:skinnvest")); EXPECT_TRUE(doc->hasValue("strarray") == false); { @@ -463,8 +445,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAssignMultiWset) TEST_F(FieldPathUpdateTestCase, testAssignWsetRemoveIfZero) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::tronder:bataljon")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::tronder:bataljon")); EXPECT_TRUE(doc->hasValue("strarray") == false); { @@ -493,8 +474,7 @@ TEST_F(FieldPathUpdateTestCase, testAssignWsetRemoveIfZero) TEST_F(FieldPathUpdateTestCase, testApplyAddMultiList) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::george:costanza")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::george:costanza")); EXPECT_TRUE(doc->hasValue("strarray") == false); auto adds = std::make_unique<ArrayFieldValue>(doc->getType().getField("strarray").getDataType()); @@ -512,8 +492,7 @@ TEST_F(FieldPathUpdateTestCase, testApplyAddMultiList) TEST_F(FieldPathUpdateTestCase, testAddAndAssignList) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::fancy:pants")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::fancy:pants")); EXPECT_TRUE(doc->hasValue("strarray") == false); { @@ -580,14 +559,12 @@ struct Fixture { Fixture::~Fixture() = default; Fixture::Fixture(const DocumentTypeRepo &repo, const DocumentType &doc_type, const Keys &k) : _doc_type(&doc_type), - doc(new Document(doc_type, DocumentId("id:ns:" + doc_type.getName() + "::planet:express"))), + doc(new Document(repo, doc_type, DocumentId("id:ns:" + doc_type.getName() + "::planet:express"))), mfv(getMapType(doc_type)), fv1(getMapType(doc_type).getValueType()), fv2(getMapType(doc_type).getValueType()), fv3(getMapType(doc_type).getValueType()) { - doc->setRepo(repo); - fv1.setValue("title", StringFieldValue("fry")); fv1.setValue("rating", IntFieldValue(30)); mfv.put(StringFieldValue(k.key1), fv1); @@ -646,7 +623,6 @@ TEST_F(FieldPathUpdateTestCase, testAssignMapStructVariable) DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); docUp.addFieldPathUpdate(std::make_unique<AssignFieldPathUpdate>(*f.doc->getDataType(), "structmap{$x}.rating", "foobar.structmap{$x}.title == \"farnsworth\"", IntFieldValue::make(48))); - f.doc->setRepo(*_repo); docUp.applyTo(*f.doc); std::unique_ptr<MapFieldValue> valueNow = f.doc->getAs<MapFieldValue>(f.doc->getField("structmap")); @@ -665,8 +641,7 @@ createFry(const DataType & type) { } TEST_F(FieldPathUpdateTestCase, testAssignMapNoExist) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::planet:express")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::planet:express")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); @@ -683,8 +658,7 @@ TEST_F(FieldPathUpdateTestCase, testAssignMapNoExist) TEST_F(FieldPathUpdateTestCase, testAssignMapNoExistNoCreate) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::planet:express")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::planet:express")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); @@ -730,8 +704,7 @@ createTastyCake(const DataType &type) { } TEST_F(FieldPathUpdateTestCase, testEqualityComparison) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::foo:zoo")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::foo:zoo")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); { @@ -772,8 +745,7 @@ TEST_F(FieldPathUpdateTestCase, testEqualityComparison) TEST_F(FieldPathUpdateTestCase, testAffectsDocumentBody) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:stuff")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::things:stuff")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); auto fv4 = std::make_unique<StructFieldValue>(dynamic_cast<const MapDataType&>(*mfv.getDataType()).getValueType()); @@ -801,8 +773,7 @@ TEST_F(FieldPathUpdateTestCase, testAffectsDocumentBody) TEST_F(FieldPathUpdateTestCase, testIncompatibleDataTypeFails) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::things:stuff")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::things:stuff")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); @@ -817,8 +788,7 @@ TEST_F(FieldPathUpdateTestCase, testIncompatibleDataTypeFails) TEST_F(FieldPathUpdateTestCase, testSerializeAssign) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::weloveto:serializestuff")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::weloveto:serializestuff")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); auto val = std::make_unique<StructFieldValue>(dynamic_cast<const MapDataType&>(*mfv.getDataType()).getValueType()); @@ -836,8 +806,7 @@ TEST_F(FieldPathUpdateTestCase, testSerializeAssign) TEST_F(FieldPathUpdateTestCase, testSerializeAdd) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::george:costanza")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::george:costanza")); EXPECT_TRUE(doc->hasValue("strarray") == false); auto adds = std::make_unique<ArrayFieldValue>(doc->getType().getField("strarray").getDataType()); @@ -854,8 +823,7 @@ TEST_F(FieldPathUpdateTestCase, testSerializeAdd) TEST_F(FieldPathUpdateTestCase, testSerializeRemove) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::weloveto:serializestuff")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::weloveto:serializestuff")); MapFieldValue mfv(doc->getType().getField("structmap").getDataType()); DocumentUpdate docUp(*_repo, *_foobar_type, DocumentId("id:ns:foobar::barbar:foofoo")); @@ -867,8 +835,7 @@ TEST_F(FieldPathUpdateTestCase, testSerializeRemove) TEST_F(FieldPathUpdateTestCase, testSerializeAssignMath) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id:ns:foobar::bat:man")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id:ns:foobar::bat:man")); EXPECT_TRUE(doc->hasValue("num") == false); doc->setValue("num", IntFieldValue(34)); @@ -940,8 +907,7 @@ TEST_F(FieldPathUpdateTestCase, testGenerateSerializedFile) TEST_F(FieldPathUpdateTestCase, array_element_update_for_invalid_index_is_ignored) { - auto doc = std::make_unique<Document>(*_foobar_type, DocumentId("id::foobar::1")); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, DocumentId("id::foobar::1")); auto& field = doc->getType().getField("strarray"); ArrayFieldValue str_array(field.getDataType()); @@ -959,8 +925,7 @@ TEST_F(FieldPathUpdateTestCase, array_element_update_for_invalid_index_is_ignore TEST_F(FieldPathUpdateTestCase, update_can_have_removes_for_both_existent_and_nonexistent_keys) { DocumentId doc_id("id:ns:foobar::george:costanza"); - auto doc = std::make_unique<Document>(*_foobar_type, doc_id); - doc->setRepo(*_repo); + auto doc = std::make_unique<Document>(*_repo, *_foobar_type, doc_id); auto& map_type = dynamic_cast<const MapDataType&>(doc->getType().getField("structmap").getDataType()); auto& struct_type = map_type.getValueType(); MapFieldValue mfv(map_type); diff --git a/document/src/tests/fieldsettest.cpp b/document/src/tests/fieldsettest.cpp index 4ce8e53ae3c..1664ad8e0ff 100644 --- a/document/src/tests/fieldsettest.cpp +++ b/document/src/tests/fieldsettest.cpp @@ -144,7 +144,7 @@ FieldSetTest::doCopyFields(const Document& src, const std::string& fieldSetStr, Document* dest) { - Document destDoc(src.getType(), DocumentId("id:ns:" + src.getType().getName() + "::fieldset")); + Document destDoc(docRepo, src.getType(), DocumentId("id:ns:" + src.getType().getName() + "::fieldset")); if (!dest) { dest = &destDoc; } @@ -196,7 +196,7 @@ TEST_F(FieldSetTest, testCopyDocumentFields) doCopyFields(*src, repo, "testdoctype1:hstringval,content")); // Test that we overwrite already set fields in destination document { - Document dest(src->getType(), DocumentId("id:ns:" + src->getType().getName() + "::bar")); + Document dest(repo, src->getType(), DocumentId("id:ns:" + src->getType().getName() + "::bar")); dest.setValue(dest.getField("content"), StringFieldValue("overwriteme")); EXPECT_EQ(std::string("content: megafoo megabar\n"), doCopyFields(*src, repo, src->getType().getName() + ":content", &dest)); @@ -209,7 +209,7 @@ FieldSetTest::doCopyDocument(const Document& src, const std::string& fieldSetStr) { auto fset = FieldSetRepo::parse(docRepo, fieldSetStr); - Document::UP doc(FieldSet::createDocumentSubsetCopy(src, *fset)); + Document::UP doc(FieldSet::createDocumentSubsetCopy(docRepo, src, *fset)); return stringifyFields(*doc); } @@ -221,7 +221,7 @@ TEST_F(FieldSetTest, testDocumentSubsetCopy) Document::UP src(createTestDocument(testDocMan)); { - Document::UP doc(FieldSet::createDocumentSubsetCopy(*src, AllFields())); + Document::UP doc(FieldSet::createDocumentSubsetCopy(repo, *src, AllFields())); // Test that document id and type are copied correctly. EXPECT_TRUE(doc.get()); EXPECT_EQ(src->getId(), doc->getId()); @@ -230,7 +230,7 @@ TEST_F(FieldSetTest, testDocumentSubsetCopy) stringifyFields(*doc)); } { - Document::UP doc(FieldSet::createDocumentSubsetCopy(*src, DocumentOnly())); + Document::UP doc(FieldSet::createDocumentSubsetCopy(repo, *src, DocumentOnly())); // Test that document id and type are copied correctly. EXPECT_TRUE(doc.get()); EXPECT_EQ(src->getId(), doc->getId()); diff --git a/document/src/tests/fieldvalue/document_test.cpp b/document/src/tests/fieldvalue/document_test.cpp index fd277bc2eb4..3efaabb1c2e 100644 --- a/document/src/tests/fieldvalue/document_test.cpp +++ b/document/src/tests/fieldvalue/document_test.cpp @@ -16,9 +16,9 @@ TEST("require that document with id schema 'id' checks type") { const DataType *type = repo.getDocumentType("testdoctype1"); ASSERT_TRUE(type); - Document(*type, DocumentId("id:ns:testdoctype1::")); // Should not throw + Document(repo.getTypeRepo(), *type, DocumentId("id:ns:testdoctype1::")); // Should not throw - EXPECT_EXCEPTION(Document(*type, DocumentId("id:ns:type::")), + EXPECT_EXCEPTION(Document(repo.getTypeRepo(), *type, DocumentId("id:ns:type::")), vespalib::IllegalArgumentException, "testdoctype1 that don't match the id (type type)"); } diff --git a/document/src/tests/select/select_test.cpp b/document/src/tests/select/select_test.cpp index 03bd17d47b5..30128fbea0a 100644 --- a/document/src/tests/select/select_test.cpp +++ b/document/src/tests/select/select_test.cpp @@ -85,7 +85,7 @@ DocumentSelectTest::check_select(const Document& doc, const vespalib::string& ex TEST_F(DocumentSelectTest, check_existing_reference_field) { - auto document = std::make_unique<Document>(*_child_document_type, DocumentId("id::child::0")); + auto document = std::make_unique<Document>(*_repo, *_child_document_type, DocumentId("id::child::0")); document->setFieldValue(_child_ref_field, std::make_unique<ReferenceFieldValue>(_child_ref_field_type, DocumentId("id::parent::1"))); EXPECT_TRUE(document->hasValue(_child_ref_field)); check_select(*document, "child.ref == null", Result::False); @@ -102,7 +102,7 @@ TEST_F(DocumentSelectTest, check_existing_reference_field) TEST_F(DocumentSelectTest, check_missing_reference_field) { - auto document = std::make_unique<Document>(*_child_document_type, DocumentId("id::child::0")); + auto document = std::make_unique<Document>(*_repo, *_child_document_type, DocumentId("id::child::0")); EXPECT_FALSE(document->hasValue(_child_ref_field)); check_select(*document, "child.ref == null", Result::True); check_select(*document, "child.ref != null", Result::False); diff --git a/document/src/tests/serialization/vespadocumentserializer_test.cpp b/document/src/tests/serialization/vespadocumentserializer_test.cpp index 7528878bfb5..e91e38e0fe4 100644 --- a/document/src/tests/serialization/vespadocumentserializer_test.cpp +++ b/document/src/tests/serialization/vespadocumentserializer_test.cpp @@ -515,7 +515,7 @@ TEST("requireThatDocumentCanBeSerialized") { const DocumentType &type = repo.getDocumentType(); DocumentId doc_id("id:ns:" + type.getName() + "::"); - Document value(type, doc_id); + Document value(repo.getDocumentTypeRepo(), type, doc_id); value.setValue(type.getField("header field"), IntFieldValue(42)); value.setValue(type.getField("body field"), StringFieldValue("foobar")); @@ -580,7 +580,7 @@ TEST("requireThatUnmodifiedDocumentRetainsUnknownFieldOnSerialization") { DocumentTypeRepo repo2Fields(builder2.config()); DocumentId doc_id("id:ns:my_doctype::"); - Document value(*repo2Fields.getDocumentType(doc_type_id), doc_id); + Document value(repo2Fields, *repo2Fields.getDocumentType(doc_type_id), doc_id); value.setValue("field1", IntFieldValue(42)); value.setValue("field2", StringFieldValue("megafoo")); @@ -632,12 +632,12 @@ TEST("requireThatDocumentWithDocumentCanBeSerialized") { setSpanTree(str, *tree); const Field str_field("str", *DataType::STRING); - Document inner(*inner_type, DocumentId("id:ns:" + inner_type->getName() + "::")); + Document inner(my_repo, *inner_type, DocumentId("id:ns:" + inner_type->getName() + "::")); inner.setValue(str_field, str); const DocumentType *type = my_repo.getDocumentType(outer_type_id); ASSERT_TRUE(type); DocumentId doc_id("id:ns:" + type->getName() + "::"); - Document value(*type, doc_id); + Document value(my_repo, *type, doc_id); const Field doc_field(inner_name, *inner_type); value.setValue(doc_field, inner); @@ -659,9 +659,10 @@ TEST("requireThatReadDocumentTypeThrowsIfUnknownType") { template <typename FieldValueT> void serializeToFile(FieldValueT &value, const string &file_name, + const DocumentTypeRepo& my_repo, const DocumentType *type, const string &field_name) { DocumentId doc_id("id:test:" + type->getName() + "::foo"); - Document doc(*type, doc_id); + Document doc(my_repo, *type, doc_id); doc.setValue(type->getField(field_name), value); nbostream stream; @@ -675,7 +676,7 @@ void serializeToFile(FieldValueT &value, const string &file_name, void serializeToFile(PredicateFieldValue &value, const string &file_name) { const DocumentType *type = doc_repo.getDocumentType(predicate_doc_type_id); - serializeToFile(value, file_name, type, predicate_field_name); + serializeToFile(value, file_name, doc_repo, type, predicate_field_name); } template <typename FieldValueT> @@ -819,7 +820,7 @@ const DocumentTypeRepo tensor_doc_repo1(getTensorDocTypesConfig("tensor(dimX{})" void serializeToFile(TensorFieldValue &value, const string &file_name) { const DocumentType *type = tensor_doc_repo.getDocumentType(tensor_doc_type_id); - serializeToFile(value, file_name, type, tensor_field_name); + serializeToFile(value, file_name, tensor_doc_repo, type, tensor_field_name); } void deserializeAndCheck(const string &file_name, TensorFieldValue &value) { @@ -870,7 +871,7 @@ TensorDocFixture::TensorDocFixture(const DocumentTypeRepo &docTypeRepo, : _docTypeRepo(docTypeRepo), _docType(_docTypeRepo.getDocumentType(tensor_doc_type_id)), _tensor(std::move(tensor)), - _doc(*_docType, DocumentId("id:test:my_type::foo")), + _doc(_docTypeRepo, *_docType, DocumentId("id:test:my_type::foo")), _blob() { auto fv = _doc.getField(tensor_field_name).createValue(); @@ -963,7 +964,7 @@ struct RefFixture { const string data_dir = TEST_PATH("../../test/resources/reference/"); const string field_name = "ref_field"; serializeToFile(value, data_dir + file_base_name + "__cpp.new", - ref_doc_type, field_name); + fixed_repo.getDocumentTypeRepo(), ref_doc_type, field_name); vespalib::rename(data_dir + file_base_name + "__cpp.new", data_dir + file_base_name + "__cpp"); @@ -999,7 +1000,7 @@ TEST_F("ReferenceFieldValue with ID serialization matches Java", RefFixture) { struct AssociatedDocumentRepoFixture { const DocumentType& doc_type{repo.getDocumentType()}; DocumentId doc_id{"id:ns:" + doc_type.getName() + "::"}; - Document source_doc{doc_type, doc_id}; + Document source_doc{doc_repo, doc_type, doc_id}; std::unique_ptr<Document> roundtrip_serialize_source_document() { nbostream stream; diff --git a/document/src/tests/testxml.cpp b/document/src/tests/testxml.cpp index 5f194661fe5..13024ddb005 100644 --- a/document/src/tests/testxml.cpp +++ b/document/src/tests/testxml.cpp @@ -22,8 +22,7 @@ namespace { Document::UP createTestDocument(const DocumentTypeRepo& repo) { const DocumentType* type(repo.getDocumentType("testdoc")); - auto doc = std::make_unique<Document>(*type,DocumentId("id:ns:testdoc::crawler/http://www.ntnu.no/")); - doc->setRepo(repo); + auto doc = std::make_unique<Document>(repo, *type, DocumentId("id:ns:testdoc::crawler/http://www.ntnu.no/")); std::string s("humlepungens buffer"); ByteBuffer bb(s.c_str(), s.size()); @@ -45,7 +44,7 @@ Document::UP createTestDocument(const DocumentTypeRepo& repo) val.add(rawVal3); doc->setValue(doc->getField("rawarrayattr"), val); - auto doc2 = std::make_unique<Document>(*type, DocumentId("id:ns:testdoc::crawler/http://www.ntnu.no/2")); + auto doc2 = std::make_unique<Document>(repo, *type, DocumentId("id:ns:testdoc::crawler/http://www.ntnu.no/2")); doc2->setValue(doc2->getField("stringattr"), StringFieldValue("tjo hei paa du")); doc->setValue(doc->getField("docfield"), *doc2); diff --git a/document/src/vespa/document/base/forcelink.cpp b/document/src/vespa/document/base/forcelink.cpp index cfa3354f5f2..975fca5aa2c 100644 --- a/document/src/vespa/document/base/forcelink.cpp +++ b/document/src/vespa/document/base/forcelink.cpp @@ -1,9 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "forcelink.h" -#include <vespa/document/update/updates.h> -#include <vespa/document/fieldvalue/fieldvalues.h> #include <vespa/document/datatype/documenttype.h> +#include <vespa/document/fieldvalue/fieldvalues.h> +#include <vespa/document/repo/documenttyperepo.h> +#include <vespa/document/update/updates.h> namespace document { @@ -12,7 +13,8 @@ ForceLink::ForceLink(void) { if (time(NULL) == 0) { DocumentType type("foo", 1); - Document document(type, DocumentId("doc:ns:bar")); + DocumentTypeRepo repo(type); + Document document(repo, *repo.getDocumentType("foo"), DocumentId("doc:ns:bar")); DocumentUpdate documentUpdate; MapValueUpdate mapValueUpdate(std::make_unique<IntFieldValue>(3), std::make_unique<ClearValueUpdate>()); AddValueUpdate addValueUpdate(std::make_unique<IntFieldValue>(3)); diff --git a/document/src/vespa/document/base/testdocman.cpp b/document/src/vespa/document/base/testdocman.cpp index 59e4d4d8386..471a2f8c196 100644 --- a/document/src/vespa/document/base/testdocman.cpp +++ b/document/src/vespa/document/base/testdocman.cpp @@ -79,7 +79,7 @@ TestDocMan::createDocument( { const DocumentType *type_ptr = _repo->getDocumentType(type); assert(type_ptr); - Document::UP doc(new Document(*type_ptr, DocumentId(id))); + Document::UP doc(new Document(*_repo, *type_ptr, DocumentId(id))); doc->setValue(doc->getField("content"), StringFieldValue(content.c_str())); return doc; } diff --git a/document/src/vespa/document/datatype/documenttype.cpp b/document/src/vespa/document/datatype/documenttype.cpp index 0d38ce1f623..80181a7ad35 100644 --- a/document/src/vespa/document/datatype/documenttype.cpp +++ b/document/src/vespa/document/datatype/documenttype.cpp @@ -175,7 +175,7 @@ DocumentType::isA(const DataType& other) const FieldValue::UP DocumentType::createFieldValue() const { - return std::make_unique<Document>(*this, DocumentId("id::" + getName() + "::")); + return Document::make_without_repo(*this, DocumentId("id::" + getName() + "::")); } void diff --git a/document/src/vespa/document/fieldset/fieldset.h b/document/src/vespa/document/fieldset/fieldset.h index 1f53f7a3456..5b67701e395 100644 --- a/document/src/vespa/document/fieldset/fieldset.h +++ b/document/src/vespa/document/fieldset/fieldset.h @@ -6,6 +6,7 @@ namespace document { class Document; +class DocumentTypeRepo; /** * FieldSet class. Represents a subset of fields in a document type. @@ -57,7 +58,7 @@ public: * See comment for copyFields() for performance notes. * @return The new, (partially) copied document instance. */ - static std::unique_ptr<Document> createDocumentSubsetCopy(const Document& src, const FieldSet& fields); + static std::unique_ptr<Document> createDocumentSubsetCopy(const DocumentTypeRepo& type_repo, const Document& src, const FieldSet& fields); /** * Strip all fields _except_ the ones that are contained within the diff --git a/document/src/vespa/document/fieldset/fieldsets.cpp b/document/src/vespa/document/fieldset/fieldsets.cpp index 0ed9ace7467..0ab959d6815 100644 --- a/document/src/vespa/document/fieldset/fieldsets.cpp +++ b/document/src/vespa/document/fieldset/fieldsets.cpp @@ -80,9 +80,9 @@ FieldSet::copyFields(Document& dest, const Document& src, const FieldSet& fields } Document::UP -FieldSet::createDocumentSubsetCopy(const Document& src, const FieldSet& fields) +FieldSet::createDocumentSubsetCopy(const DocumentTypeRepo& type_repo, const Document& src, const FieldSet& fields) { - auto ret = std::make_unique<Document>(src.getType(), src.getId()); + auto ret = std::make_unique<Document>(type_repo, src.getType(), src.getId()); copyFields(*ret, src, fields); return ret; } diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp index 33b1bbe8d2c..2fb1611f6ff 100644 --- a/document/src/vespa/document/fieldvalue/document.cpp +++ b/document/src/vespa/document/fieldvalue/document.cpp @@ -95,6 +95,26 @@ Document::Document(const DataType &type, DocumentId documentId) } } +Document::UP +Document::make_without_repo(const DataType& type, DocumentId id) +{ + // Must use new as the constructor is private. + return Document::UP(new Document(type, id)); +} + +Document::Document(const DocumentTypeRepo& repo, const DataType &type, DocumentId documentId) + : StructuredFieldValue(Type::DOCUMENT, verifyDocumentType(&type)), + _id(std::move(documentId)), + _fields(repo, getType().getFieldsType()), + _backingBuffer(), + _lastModified(0) +{ + _fields.setDocumentType(getType()); + if (_id.hasDocType() && (_id.getDocType() != type.getName())) { + throwTypeMismatch(type.getName(), _id.getDocType()); + } +} + void Document::setRepo(const DocumentTypeRepo& repo) { _fields.setRepo(repo); diff --git a/document/src/vespa/document/fieldvalue/document.h b/document/src/vespa/document/fieldvalue/document.h index c871e324f05..ac3963a4cc0 100644 --- a/document/src/vespa/document/fieldvalue/document.h +++ b/document/src/vespa/document/fieldvalue/document.h @@ -50,7 +50,13 @@ public: Document(Document &&) noexcept; Document & operator =(const Document &); Document & operator =(Document &&) noexcept; +private: Document(const DataType &, DocumentId id); +public: + // Should preferably only be used by unit tests. + // TODO: Remove all usage of this outside of unit tests. + static Document::UP make_without_repo(const DataType& type, DocumentId id); + Document(const DocumentTypeRepo& repo, const DataType&, DocumentId id); Document(const DocumentTypeRepo& repo, vespalib::nbostream& stream); Document(const DocumentTypeRepo& repo, vespalib::DataBuffer && buffer); ~Document() noexcept override; diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp index 444e763c52b..083012a213c 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp @@ -36,6 +36,16 @@ StructFieldValue::StructFieldValue(const DataType &type) { } +StructFieldValue::StructFieldValue(const DocumentTypeRepo& repo, const DataType& type) + : StructuredFieldValue(Type::STRUCT, type), + _fields(), + _repo(&repo), + _doc_type(nullptr), + _version(Document::getNewestSerializationVersion()), + _hasChanged(true) +{ +} + StructFieldValue::StructFieldValue(const StructFieldValue & rhs) = default; StructFieldValue & StructFieldValue::operator = (const StructFieldValue & rhs) = default; diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.h b/document/src/vespa/document/fieldvalue/structfieldvalue.h index 360aa6dca63..e888847fdfe 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.h @@ -36,6 +36,7 @@ public: using UP = std::unique_ptr<StructFieldValue>; explicit StructFieldValue(const DataType &type); + explicit StructFieldValue(const DocumentTypeRepo& repo, const DataType& type); StructFieldValue(const StructFieldValue & rhs); StructFieldValue & operator = (const StructFieldValue & rhs); StructFieldValue(StructFieldValue && rhs) noexcept = default; |