summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-06-06 09:09:10 -0700
committerBen Pfaff <blp@nicira.com>2011-06-06 09:09:10 -0700
commit6910a6e6f25f7fe7adfd93c8405671e72d4d156b (patch)
tree71fa30e91f096cd368992abbb157a5ee5f65eddc /tests
parent25d4983554f6cf8ce5e169f7c5bb5a08c981d27e (diff)
downloadopenvswitch-6910a6e6f25f7fe7adfd93c8405671e72d4d156b.tar.gz
ovsdb: Implement table uniqueness constraints ("indexes").
Diffstat (limited to 'tests')
-rw-r--r--tests/ovsdb-execution.at85
-rw-r--r--tests/ovsdb-server.at2
-rw-r--r--tests/ovsdb-table.at25
-rw-r--r--tests/ovsdb-tool.at2
4 files changed, 111 insertions, 3 deletions
diff --git a/tests/ovsdb-execution.at b/tests/ovsdb-execution.at
index 54ff0aeb2..90f20ff6c 100644
--- a/tests/ovsdb-execution.at
+++ b/tests/ovsdb-execution.at
@@ -6,7 +6,8 @@ m4_define([ORDINAL_SCHEMA],
"ordinals": {
"columns": {
"number": {"type": "integer"},
- "name": {"type": "string"}}}},
+ "name": {"type": "string"}},
+ "indexes": [["number"]]}},
"version": "5.1.3",
"cksum": "12345678 9"}]])
@@ -553,6 +554,88 @@ OVSDB_CHECK_EXECUTION([insert and update constraints],
[{"uuid":["uuid","<1>"]},{"details":"transaction causes \"constrained\" table to contain 2 rows, greater than the schema-defined limit of 1 row(s)","error":"constraint violation"}]
]])
+OVSDB_CHECK_EXECUTION([index uniqueness checking],
+ [ORDINAL_SCHEMA],
+dnl Insert initial row.
+ [[[["ordinals",
+ {"op": "insert",
+ "table": "ordinals",
+ "row": {"number": 1, "name": "one"}}]]],
+dnl Try to insert row with identical value (fails).
+ [[["ordinals",
+ {"op": "insert",
+ "table": "ordinals",
+ "row": {"number": 1, "name": "another one"}}]]],
+dnl Remove initial row and insert new row with identical value in a single
+dnl transaction (succeeds).
+ [[["ordinals",
+ {"op": "insert",
+ "table": "ordinals",
+ "row": {"number": 1, "name": "another one"}},
+ {"op": "delete",
+ "table": "ordinals",
+ "where": [["name", "==", "one"]]}]]],
+dnl Remove row and insert two new rows with identical value in a single
+dnl transaction (fails).
+ [[["ordinals",
+ {"op": "delete",
+ "table": "ordinals",
+ "where": []},
+ {"op": "insert",
+ "table": "ordinals",
+ "row": {"number": 1, "name": "one"}},
+ {"op": "insert",
+ "table": "ordinals",
+ "row": {"number": 1, "name": "still another one"}}]]],
+dnl Add new row with different value (succeeds).
+ [[["ordinals",
+ {"op": "insert",
+ "table": "ordinals",
+ "row": {"number": 2, "name": "two"}}]]],
+dnl Change rows so values collide (fails).
+ [[["ordinals",
+ {"op": "update",
+ "table": "ordinals",
+ "where": [],
+ "row": {"number": 3}}]]],
+dnl Swap rows' values (succeeds).
+ [[["ordinals",
+ {"op": "update",
+ "table": "ordinals",
+ "where": [["number", "==", 1]],
+ "row": {"number": 2, "name": "old two"}},
+ {"op": "update",
+ "table": "ordinals",
+ "where": [["name", "==", "two"]],
+ "row": {"number": 1, "name": "old one"}}]]],
+dnl Change all rows' values to values not used before and insert values that
+dnl collide (only) with their previous values (succeeds).
+ [[["ordinals",
+ {"op": "mutate",
+ "table": "ordinals",
+ "where": [],
+ "mutations": [["number", "*=", 10]]},
+ {"op": "insert",
+ "table": "ordinals",
+ "row": {"number": 1, "name": "new one"}},
+ {"op": "insert",
+ "table": "ordinals",
+ "row": {"number": 2, "name": "new two"}},
+ {"op": "select",
+ "table": "ordinals",
+ "where": [],
+ "columns": ["number", "name"],
+ "sort": ["number"]}]]]],
+ [[[{"uuid":["uuid","<0>"]}]
+[{"uuid":["uuid","<1>"]},{"details":"Transaction causes multiple rows in \"ordinals\" table to have identical values (1) for index on column \"number\". First row, with UUID <0>, existed in the database before this transaction and was not modified by the transaction. Second row, with UUID <1>, was inserted by this transaction.","error":"constraint violation"}]
+[{"uuid":["uuid","<2>"]},{"count":1}]
+[{"count":1},{"uuid":["uuid","<3>"]},{"uuid":["uuid","<4>"]},{"details":"Transaction causes multiple rows in \"ordinals\" table to have identical values (1) for index on column \"number\". First row, with UUID <4>, was inserted by this transaction. Second row, with UUID <3>, was inserted by this transaction.","error":"constraint violation"}]
+[{"uuid":["uuid","<5>"]}]
+[{"count":2},{"details":"Transaction causes multiple rows in \"ordinals\" table to have identical values (3) for index on column \"number\". First row, with UUID <5>, had the following index values before the transaction: 2. Second row, with UUID <2>, had the following index values before the transaction: 1.","error":"constraint violation"}]
+[{"count":1},{"count":1}]
+[{"count":2},{"uuid":["uuid","<6>"]},{"uuid":["uuid","<7>"]},{"rows":[{"name":"new one","number":1},{"name":"new two","number":2},{"name":"old one","number":10},{"name":"old two","number":20}]}]
+]])
+
OVSDB_CHECK_EXECUTION([referential integrity -- simple],
[CONSTRAINT_SCHEMA],
[[[["constraints",
diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at
index d7c0335ef..a7a2829e2 100644
--- a/tests/ovsdb-server.at
+++ b/tests/ovsdb-server.at
@@ -287,7 +287,7 @@ AT_CHECK(
[0], [stdout], [ignore], [test ! -e pid || kill `cat pid`])
dnl Check that all the crap is in fact in the database log.
AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
- [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}},"version":"5.1.3"}
+ [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
{"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
{"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
{"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}
diff --git a/tests/ovsdb-table.at b/tests/ovsdb-table.at
index cf206c423..26ff90e7a 100644
--- a/tests/ovsdb-table.at
+++ b/tests/ovsdb-table.at
@@ -31,6 +31,31 @@ OVSDB_CHECK_POSITIVE_CPY([table with maxRows of 2],
"maxRows": 2}']],
[[{"columns":{"name":{"type":"string"}},"maxRows":2}]])
+OVSDB_CHECK_POSITIVE_CPY([table with index],
+ [[parse-table mytable '{"columns": {"a": {"type": "integer"},
+ "b": {"type": "string"}},
+ "indexes": [["b", "a"]]}']],
+ [[{"columns":{"a":{"type":"integer"},"b":{"type":"string"}},"indexes":[["b","a"]]}]])
+
+OVSDB_CHECK_NEGATIVE_CPY([table with syntax error in index],
+ [[parse-table mytable '{"columns": {"a": {"type": "integer"},
+ "b": {"type": "string"}},
+ "indexes": [["b", "a"], [0]]}']],
+ [[array of distinct column names expected]])
+
+OVSDB_CHECK_NEGATIVE_CPY([table with empty index],
+ [[parse-table mytable '{"columns": {"a": {"type": "integer"},
+ "b": {"type": "string"}},
+ "indexes": [[]]}']],
+ [[index must have at least one column]])
+
+OVSDB_CHECK_NEGATIVE_CPY([table with index of ephemeral column],
+ [[parse-table mytable '{"columns": {"a": {"type": "integer",
+ "ephemeral": true},
+ "b": {"type": "string"}},
+ "indexes": [["b", "a"]]}']],
+ [[ephemeral columns (such as a) may not be indexed]])
+
OVSDB_CHECK_NEGATIVE_CPY([column names may not begin with _],
[[parse-table mytable \
'{"columns": {"_column": {"type": "integer"}}}']],
diff --git a/tests/ovsdb-tool.at b/tests/ovsdb-tool.at
index 989159dd5..d48a0c1ec 100644
--- a/tests/ovsdb-tool.at
+++ b/tests/ovsdb-tool.at
@@ -83,7 +83,7 @@ AT_CHECK(
[0], [stdout], [ignore])
dnl Check that all the crap is in fact in the database log.
AT_CHECK([[perl $srcdir/uuidfilt.pl db | grep -v ^OVSDB | sed 's/"_date":[0-9]*/"_date":0/' | test-json --multiple -]], [0],
- [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}}}},"version":"5.1.3"}
+ [[{"cksum":"12345678 9","name":"ordinals","tables":{"ordinals":{"columns":{"name":{"type":"string"},"number":{"type":"integer"}},"indexes":[["number"]]}},"version":"5.1.3"}
{"_comment":"add row for zero 0","_date":0,"ordinals":{"<0>":{"name":"zero"}}}
{"_comment":"delete row for 0","_date":0,"ordinals":{"<0>":null}}
{"_comment":"add back row for zero 0","_date":0,"ordinals":{"<1>":{"name":"zero"}}}