AT_BANNER([OVSDB -- replication])

m4_divert_push([PREPARE_TESTS])
[
replication_schema () {
    cat <<'EOF'
    {"name": "mydb",
     "tables": {
       "a": {
         "columns": {
           "number": {"type": "integer"},
           "name": {"type": "string"}},
         "indexes": [["number"]]},
       "b": {
         "columns": {
           "number": {"type": "integer"},
           "name": {"type": "string"}},
         "indexes": [["number"]]}}
    }
EOF
}
replication_schema_v2 () {
    cat <<'EOF'
    {"name": "mydb",
     "tables": {
       "a": {
         "columns": {
           "number": {"type": "integer"},
           "name": {"type": "string"}},
         "indexes": [["number"]]},
       "b": {
         "columns": {
           "number": {"type": "integer"},
           "name": {"type": "string"},
           "foo" : {"type": "string"}},
         "indexes": [["number"]]},
       "c": {
         "columns": {
           "number": {"type": "integer"},
           "name": {"type": "string"}},
         "indexes": [["number"]]}}
    }
EOF
}
]
m4_divert_pop([PREPARE_TESTS])

m4_define([REPLICATION_EXAMPLES], [

OVSDB_CHECK_REPLICATION([insert monitored table, insert excluded table],
  [replication_schema],
  [[[["mydb",
      {"op": "insert",
       "table": "a",
       "row": {"number": 0, "name": "zero"}}]]],
  [[["mydb",
      {"op": "insert",
       "table": "b",
       "row": {"number": 1, "name": "one"}}]]],
  [[["mydb",
      {"op": "insert",
       "table": "a",
       "row": {"number": 1, "name": "one"}}]]]],
  [[8,10c8,9
< _uuid                                name number
< ------------------------------------ ---- ------
< <0> one  1
---
> _uuid name number
> ----- ---- ------]]
)

OVSDB_CHECK_REPLICATION([insert monitored table, update excluded table],
  [replication_schema],
  [[[["mydb",
      {"op": "insert",
       "table": "a",
       "row": {"number": 0, "name": "zero"}}]]],
  [[["mydb",
      {"op": "insert",
       "table": "b",
       "row": {"number": 1, "name": "one"}}]]],
  [[["mydb",
      {"op": "update",
       "table": "b",
       "where":[["name","==","one"]],
       "row": {"number": 2, "name": "two"}}]]],
  [[["mydb",
      {"op": "insert",
       "table": "a",
       "row": {"number": 1, "name": "one"}}]]]],
  [[8,10c8,9
< _uuid                                name number
< ------------------------------------ ---- ------
< <0> two  2
---
> _uuid name number
> ----- ---- ------]]
)

OVSDB_CHECK_REPLICATION([update monitored table, insert excluded table],
  [replication_schema],
  [[[["mydb",
      {"op": "insert",
       "table": "a",
       "row": {"number": 0, "name": "zero"}}]]],
  [[["mydb",
      {"op": "update",
       "table": "a",
       "where":[["name","==","zero"]],
       "row": {"number": 1, "name": "one"}}]]],
  [[["mydb",
      {"op": "insert",
       "table": "b",
       "row": {"number": 2, "name": "two"}}]]]],
  [[7,9c7,8
< _uuid                                name number
< ------------------------------------ ---- ------
< <0> two  2
---
> _uuid name number
> ----- ---- ------]]
)

OVSDB_CHECK_REPLICATION([update monitored table, update excluded table],
  [replication_schema],
  [[[["mydb",
      {"op": "insert",
       "table": "a",
       "row": {"number": 0, "name": "zero"}}]]],
  [[["mydb",
      {"op": "update",
       "table": "a",
       "where":[["name","==","zero"]],
       "row": {"number": 1, "name": "one"}}]]],
  [[["mydb",
      {"op": "insert",
       "table": "b",
       "row": {"number": 2, "name": "two"}}]]],
  [[["mydb",
      {"op": "update",
       "table": "b",
       "where":[["name","==","two"]],
       "row": {"number": 3, "name": "three"}}]]]],
  [[7,9c7,8
< _uuid                                name  number
< ------------------------------------ ----- ------
< <0> three 3
---
> _uuid name number
> ----- ---- ------]]
)

OVSDB_CHECK_REPLICATION([delete monitored table, insert excluded table],
  [replication_schema],
  [[[["mydb",
      {"op": "insert",
       "table": "a",
       "row": {"number": 0, "name": "zero"}}]]],
  [[["mydb",
      {"op": "delete",
       "table": "a",
       "where":[["name","==","zero"]]}]]],
  [[["mydb",
      {"op": "insert",
       "table": "b",
       "row": {"number": 1, "name": "one"}}]]],
  [[["mydb",
      {"op": "insert",
       "table": "a",
       "row": {"number": 1, "name": "one"}}]]]],
  [[7,9c7,8
< _uuid                                name number
< ------------------------------------ ---- ------
< <0> one  1
---
> _uuid name number
> ----- ---- ------]]
)

OVSDB_CHECK_REPLICATION([delete monitored table, update excluded table],
  [replication_schema],
  [[[["mydb",
      {"op": "insert",
       "table": "a",
       "row": {"number": 0, "name": "zero"}}]]],
  [[["mydb",
      {"op": "delete",
       "table": "a",
       "where":[["name","==","zero"]]}]]],
  [[["mydb",
      {"op": "insert",
       "table": "b",
       "row": {"number": 1, "name": "one"}}]]],
  [[["mydb",
      {"op": "update",
       "table": "b",
       "where":[["name","==","one"]],
       "row": {"number": 2, "name": "two"}}]]],
  [[["mydb",
      {"op": "insert",
       "table": "a",
       "row": {"number": 1, "name": "one"}}]]]],
  [[7,9c7,8
< _uuid                                name number
< ------------------------------------ ---- ------
< <0> two  2
---
> _uuid name number
> ----- ---- ------]]
)

])
