summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-02-26 11:58:58 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-02-26 11:58:58 +0000
commitb57bbc0bf415d969a603f9ef8ce112666b0c2b19 (patch)
treeb3fe64daf4e92ca6c1f383979aa76536d6805664 /document
parent75ae8d06f3c0af1fa787305ec3a794cd14a2b9e0 (diff)
More edge case testing of tensor updates.
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/documentupdatetestcase.cpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp
index 017d83893f0..743babdf5e1 100644
--- a/document/src/tests/documentupdatetestcase.cpp
+++ b/document/src/tests/documentupdatetestcase.cpp
@@ -24,6 +24,7 @@
#include <vespa/eval/tensor/tensor.h>
#include <vespa/vespalib/objects/nbostream.h>
#include <vespa/vespalib/util/exception.h>
+#include <vespa/vespalib/util/exceptions.h>
#include <fcntl.h>
#include <gtest/gtest.h>
@@ -808,6 +809,10 @@ struct TensorUpdateFixture {
return dynamic_cast<const TensorDataType &>(dataType);
}
+ const Field &getNonTensorField() {
+ return emptyDoc->getField("title");
+ }
+
TensorUpdateFixture(const vespalib::string &fieldName_ = "sparse_tensor")
: docMan(),
emptyDoc(docMan.createDocument()),
@@ -874,9 +879,9 @@ struct TensorUpdateFixture {
assertTensor(*expTensor);
}
- void assertApplyUpdate(const TensorSpec& initialTensor,
- const ValueUpdate& update,
- const TensorSpec& expTensor) {
+ void assertApplyUpdate(const TensorSpec &initialTensor,
+ const ValueUpdate &update,
+ const TensorSpec &expTensor) {
setTensor(initialTensor);
applyUpdate(update);
assertDocumentUpdated();
@@ -888,6 +893,14 @@ struct TensorUpdateFixture {
testRoundtripSerialize(valueUpdate, tensorDataType);
}
+ void assertThrowOnNonTensorField(const ValueUpdate &update) {
+ ASSERT_THROW(update.checkCompatibility(getNonTensorField()),
+ vespalib::IllegalArgumentException);
+ StringFieldValue value("my value");
+ ASSERT_THROW(update.applyTo(value),
+ vespalib::IllegalStateException);
+ }
+
};
TEST(DocumentUpdateTest, tensor_assign_update_can_be_applied)
@@ -985,6 +998,24 @@ TEST(DocumentUpdateTest, tensor_modify_update_can_be_roundtrip_serialized)
f.assertRoundtripSerialize(TensorModifyUpdate(TensorModifyUpdate::Operation::MULTIPLY, f.makeBaselineTensor()));
}
+TEST(DocumentUpdateTest, tensor_add_update_throws_on_non_tensor_field)
+{
+ TensorUpdateFixture f;
+ f.assertThrowOnNonTensorField(TensorAddUpdate(f.makeBaselineTensor()));
+}
+
+TEST(DocumentUpdateTest, tensor_remove_update_throws_on_non_tensor_field)
+{
+ TensorUpdateFixture f;
+ f.assertThrowOnNonTensorField(TensorRemoveUpdate(f.makeBaselineTensor()));
+}
+
+TEST(DocumentUpdateTest, tensor_modify_update_throws_on_non_tensor_field)
+{
+ TensorUpdateFixture f;
+ f.assertThrowOnNonTensorField(TensorModifyUpdate(TensorModifyUpdate::Operation::REPLACE, f.makeBaselineTensor()));
+}
+
void
assertDocumentUpdateFlag(bool createIfNonExistent, int value)