aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/attribute
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahoo-inc.com>2016-08-16 09:44:57 +0000
committerTor Egge <Tor.Egge@yahoo-inc.com>2016-08-16 09:44:57 +0000
commit62785f5eea51ad0b64319acb979e5543d7cdc985 (patch)
tree0733ff35124e4a76783a1afaf15996d29e684dfe /searchcore/src/tests/proton/attribute
parent988b518e050a455d1d22ca7cc0cfc19f97e8c1d9 (diff)
Enable tensor field assign updates in backend.
Diffstat (limited to 'searchcore/src/tests/proton/attribute')
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_test.cpp74
1 files changed, 62 insertions, 12 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_test.cpp b/searchcore/src/tests/proton/attribute/attribute_test.cpp
index d5084273c6c..53dffaf9765 100644
--- a/searchcore/src/tests/proton/attribute/attribute_test.cpp
+++ b/searchcore/src/tests/proton/attribute/attribute_test.cpp
@@ -569,27 +569,41 @@ createTensor(const TensorCells &cells, const TensorDimensions &dimensions) {
return vespalib::tensor::TensorFactory::create(cells, dimensions, builder);
}
+
+AttributeVector::SP
+createTensorAttribute(Fixture &f) {
+ AVConfig cfg(AVBasicType::TENSOR);
+ cfg.setTensorType(TensorType::fromSpec("tensor(x{},y{})"));
+ return f._m->addAttribute("a1", cfg, createSerialNum);
+}
+
+Schema
+createTensorSchema() {
+ Schema schema;
+ schema.addAttributeField(Schema::AttributeField("a1", Schema::TENSOR,
+ Schema::SINGLE));
+ return schema;
+}
+
+Document::UP
+createTensorPutDoc(DocBuilder &builder, const Tensor &tensor) {
+ return builder.startDocument("doc::1").
+ startAttributeField("a1").
+ addTensor(tensor.clone()).endField().endDocument();
+}
+
}
TEST_F("Test that we can use attribute writer to write to tensor attribute",
Fixture)
{
- proton::AttributeManager & am = *f._m;
- AVConfig cfg(AVBasicType::TENSOR);
- cfg.setTensorType(TensorType::fromSpec("tensor(x{},y{})"));
- AttributeVector::SP a1 = am.addAttribute("a1",
- cfg,
- createSerialNum);
- Schema s;
- s.addAttributeField(Schema::AttributeField("a1", Schema::TENSOR,
- Schema::SINGLE));
+ AttributeVector::SP a1 = createTensorAttribute(f);
+ Schema s = createTensorSchema();
DocBuilder builder(s);
auto tensor = createTensor({ {{{"x", "4"}, {"y", "5"}}, 7} },
{"x", "y"});
- Document::UP doc = builder.startDocument("doc::1").
- startAttributeField("a1").
- addTensor(tensor->clone()).endField().endDocument();
+ Document::UP doc = createTensorPutDoc(builder, *tensor);
f.put(1, *doc, 1);
EXPECT_EQUAL(2u, a1->getNumDocs());
TensorAttribute *tensorAttribute =
@@ -600,6 +614,42 @@ TEST_F("Test that we can use attribute writer to write to tensor attribute",
EXPECT_TRUE(tensor->equals(*tensor2));
}
+TEST_F("require that attribute writer handles tensor assign update", Fixture)
+{
+ AttributeVector::SP a1 = createTensorAttribute(f);
+ Schema s = createTensorSchema();
+ DocBuilder builder(s);
+ auto tensor = createTensor({ {{{"x", "6"}, {"y", "7"}}, 9} },
+ {"x", "y"});
+ Document::UP doc = createTensorPutDoc(builder, *tensor);
+ f.put(1, *doc, 1);
+ EXPECT_EQUAL(2u, a1->getNumDocs());
+ TensorAttribute *tensorAttribute =
+ dynamic_cast<TensorAttribute *>(a1.get());
+ EXPECT_TRUE(tensorAttribute != nullptr);
+ auto tensor2 = tensorAttribute->getTensor(1);
+ EXPECT_TRUE(static_cast<bool>(tensor2));
+ EXPECT_TRUE(tensor->equals(*tensor2));
+
+ const document::DocumentType &dt(builder.getDocumentType());
+ DocumentUpdate upd(dt, DocumentId("doc::1"));
+ auto new_tensor = createTensor({ {{{"x", "8"}, {"y", "9"}}, 11} },
+ {"x", "y"});
+ TensorFieldValue new_value;
+ new_value = new_tensor->clone();
+ upd.addUpdate(FieldUpdate(upd.getType().getField("a1"))
+ .addUpdate(AssignValueUpdate(new_value)));
+ bool immediateCommit = true;
+ f.update(2, upd, 1, immediateCommit);
+ EXPECT_EQUAL(2u, a1->getNumDocs());
+ EXPECT_TRUE(tensorAttribute != nullptr);
+ tensor2 = tensorAttribute->getTensor(1);
+ EXPECT_TRUE(static_cast<bool>(tensor2));
+ EXPECT_TRUE(!tensor->equals(*tensor2));
+ EXPECT_TRUE(new_tensor->equals(*tensor2));
+
+}
+
TEST_MAIN()
{
vespalib::rmdir(test_dir, true);