summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Sun <tony.sun427@gmail.com>2019-01-08 22:41:22 -0800
committerTony Sun <tony.sun427@gmail.com>2019-01-08 22:41:22 -0800
commit364328ca58eb4e72ade9e093e16a798455439eb0 (patch)
treeacbea32d328f3f2bdcde0926f962a13f18e59b59
parent31a4a531780ae39a3f9ccf58067ee87bfcfa5e8b (diff)
downloadcouchdb-add-mango-text-partition-tests.tar.gz
this adds mango text elixir testsadd-mango-text-partition-tests
-rw-r--r--test/elixir/test/partition_mango_test.exs994
1 files changed, 583 insertions, 411 deletions
diff --git a/test/elixir/test/partition_mango_test.exs b/test/elixir/test/partition_mango_test.exs
index 1471ddb0a..5cdcb2aea 100644
--- a/test/elixir/test/partition_mango_test.exs
+++ b/test/elixir/test/partition_mango_test.exs
@@ -28,11 +28,573 @@ defmodule PartitionMangoTest do
end)
end
+ # @tag :with_partitioned_db
+ # test "query using _id and partition works", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+ # create_index(db_name)
+
+ # url = "/#{db_name}/_partition/foo/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # _id: %{
+ # "$gt": "foo:"
+ # }
+ # },
+ # limit: 20
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 20
+ # assert_correct_partition(partitions, "foo")
+
+ # url = "/#{db_name}/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # _id: %{
+ # "$lt": "foo:"
+ # }
+ # },
+ # limit: 20
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 20
+ # assert_correct_partition(partitions, "bar")
+ # end
+
+ # @tag :with_partitioned_db
+ # test "query using _id works for global and local query", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+ # create_index(db_name)
+
+ # url = "/#{db_name}/_partition/foo/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # _id: %{
+ # "$gt": 0
+ # }
+ # },
+ # limit: 20
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 20
+ # assert_correct_partition(partitions, "foo")
+
+ # url = "/#{db_name}/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # _id: %{
+ # "$gt": 0
+ # }
+ # },
+ # limit: 20
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 20
+ # assert_correct_partition(partitions, "bar")
+ # end
+
+ # @tag :with_partitioned_db
+ # test "query with partitioned:true using index and $eq", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+ # create_index(db_name)
+
+ # url = "/#{db_name}/_partition/foo/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # some: "field"
+ # },
+ # limit: 20
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 20
+ # assert_correct_partition(partitions, "foo")
+
+ # url = "/#{db_name}/_partition/bar/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # some: "field"
+ # },
+ # limit: 20
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 20
+ # assert_correct_partition(partitions, "bar")
+ # end
+
+ # @tag :with_partitioned_db
+ # test "partitioned query using _all_docs with $eq", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+
+ # url = "/#{db_name}/_partition/foo/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # some: "field"
+ # },
+ # limit: 20
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 20
+ # assert_correct_partition(partitions, "foo")
+
+ # url = "/#{db_name}/_partition/bar/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # some: "field"
+ # },
+ # limit: 20
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 20
+ # assert_correct_partition(partitions, "bar")
+ # end
+
+ # @tag :with_db
+ # test "non-partitioned query using _all_docs and $eq", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+
+ # url = "/#{db_name}/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # some: "field"
+ # },
+ # skip: 40,
+ # limit: 5
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 5
+ # assert partitions == ["bar", "bar", "bar", "bar", "bar"]
+
+ # url = "/#{db_name}/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # some: "field"
+ # },
+ # skip: 50,
+ # limit: 5
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 5
+ # assert partitions == ["foo", "foo", "foo", "foo", "foo"]
+ # end
+
+ # @tag :with_partitioned_db
+ # test "partitioned query using index and range scan", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name, "foo", "bar42")
+ # create_index(db_name, ["value"])
+
+ # url = "/#{db_name}/_partition/foo/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # value: %{
+ # "$gte": 6,
+ # "$lt": 16
+ # }
+ # }
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 5
+ # assert_correct_partition(partitions, "foo")
+
+ # url = "/#{db_name}/_partition/bar42/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # value: %{
+ # "$gte": 6,
+ # "$lt": 16
+ # }
+ # }
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 5
+ # assert_correct_partition(partitions, "bar42")
+ # end
+
+ # @tag :with_partitioned_db
+ # test "partitioned query using _all_docs and range scan", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+
+ # url = "/#{db_name}/_partition/foo/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # value: %{
+ # "$gte": 6,
+ # "$lt": 16
+ # }
+ # }
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 5
+ # assert_correct_partition(partitions, "foo")
+
+ # url = "/#{db_name}/_partition/bar/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # value: %{
+ # "$gte": 6,
+ # "$lt": 16
+ # }
+ # }
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 5
+ # assert_correct_partition(partitions, "bar")
+ # end
+
+ # @tag :with_partitioned_db
+ # test "partitioned query using _all_docs", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name, "foo", "bar42")
+
+ # url = "/#{db_name}/_partition/foo/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # value: %{
+ # "$gte": 6,
+ # "$lt": 16
+ # }
+ # }
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 5
+ # assert_correct_partition(partitions, "foo")
+
+ # url = "/#{db_name}/_partition/bar42/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # value: %{
+ # "$gte": 6,
+ # "$lt": 16
+ # }
+ # }
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 5
+ # assert_correct_partition(partitions, "bar42")
+ # end
+
+ # @tag :with_partitioned_db
+ # test "explain works with partitions", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+ # create_index(db_name, ["some"])
+
+ # url = "/#{db_name}/_partition/foo/_explain"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # value: %{
+ # "$gte": 6,
+ # "$lt": 16
+ # }
+ # }
+ # }
+ # )
+
+ # %{:body => body} = resp
+
+ # assert body["index"]["name"] == "_all_docs"
+ # assert body["mrargs"]["partition"] == "foo"
+
+ # url = "/#{db_name}/_partition/bar/_explain"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # some: "field"
+ # }
+ # }
+ # )
+
+ # %{:body => body} = resp
+
+ # assert body["index"]["def"] == %{"fields" => [%{"some" => "asc"}]}
+ # assert body["mrargs"]["partition"] == "bar"
+ # end
+
+ # @tag :with_db
+ # test "explain works with non partitioned db", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+ # create_index(db_name, ["some"])
+
+ # url = "/#{db_name}/_explain"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # value: %{
+ # "$gte": 6,
+ # "$lt": 16
+ # }
+ # }
+ # }
+ # )
+
+ # %{:body => body} = resp
+
+ # assert body["index"]["name"] == "_all_docs"
+ # assert body["mrargs"]["partition"] == :null
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # some: "field"
+ # }
+ # }
+ # )
+
+ # %{:body => body} = resp
+
+ # assert body["index"]["def"] == %{"fields" => [%{"some" => "asc"}]}
+ # assert body["mrargs"]["partition"] == :null
+ # end
+
+ # @tag :with_partitioned_db
+ # test "partitioned query using bookmarks", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+ # create_index(db_name, ["value"])
+
+ # url = "/#{db_name}/_partition/foo/_find"
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # value: %{
+ # "$gte": 6,
+ # "$lt": 16
+ # }
+ # },
+ # limit: 3
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 3
+ # assert_correct_partition(partitions, "foo")
+
+ # %{:body => %{"bookmark" => bookmark}} = resp
+
+ # resp =
+ # Couch.post(url,
+ # body: %{
+ # selector: %{
+ # value: %{
+ # "$gte": 6,
+ # "$lt": 16
+ # }
+ # },
+ # limit: 3,
+ # bookmark: bookmark
+ # }
+ # )
+
+ # assert resp.status_code == 200
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 2
+ # assert_correct_partition(partitions, "foo")
+ # end
+
+ # @tag :with_partitioned_db
+ # test "global query uses global index", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+ # create_index(db_name, ["some"], %{partitioned: false})
+
+ # url = "/#{db_name}/_explain"
+
+ # selector = %{
+ # selector: %{
+ # some: "field"
+ # },
+ # limit: 100
+ # }
+
+ # resp = Couch.post(url, body: selector)
+ # assert resp.status_code == 200
+ # %{:body => body} = resp
+ # assert body["index"]["def"] == %{"fields" => [%{"some" => "asc"}]}
+
+ # url = "/#{db_name}/_find"
+ # resp = Couch.post(url, body: selector)
+ # assert resp.status_code == 200
+
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 100
+ # end
+
+ # @tag :with_partitioned_db
+ # test "global query does not use partition index", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+ # create_index(db_name, ["some"])
+
+ # url = "/#{db_name}/_explain"
+
+ # selector = %{
+ # selector: %{
+ # some: "field"
+ # },
+ # limit: 100
+ # }
+
+ # resp = Couch.post(url, body: selector)
+ # %{:body => body} = resp
+ # assert body["index"]["name"] == "_all_docs"
+
+ # url = "/#{db_name}/_find"
+ # resp = Couch.post(url, body: selector)
+
+ # assert resp.status_code == 200
+
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 100
+ # end
+
+ # @tag :with_partitioned_db
+ # test "partitioned query does not use global index", context do
+ # db_name = context[:db_name]
+ # create_partition_docs(db_name)
+ # create_index(db_name, ["some"], %{partitioned: false})
+
+ # url = "/#{db_name}/_partition/foo/_explain"
+
+ # selector = %{
+ # selector: %{
+ # some: "field"
+ # },
+ # limit: 50
+ # }
+
+ # resp = Couch.post(url, body: selector)
+ # assert resp.status_code == 200
+ # %{:body => body} = resp
+ # assert body["index"]["name"] == "_all_docs"
+
+ # url = "/#{db_name}/_partition/foo/_find"
+ # resp = Couch.post(url, body: selector)
+ # assert resp.status_code == 200
+
+ # partitions = get_partitions(resp)
+ # assert length(partitions) == 50
+ # assert_correct_partition(partitions, "foo")
+ # end
+
@tag :with_partitioned_db
- test "query using _id and partition works", context do
+ test "query using text index", context do
db_name = context[:db_name]
create_partition_docs(db_name)
- create_index(db_name)
+ create_index(db_name, [%{name: "some", type: "string"}],
+ %{type: "text"})
url = "/#{db_name}/_partition/foo/_find"
@@ -53,7 +615,7 @@ defmodule PartitionMangoTest do
assert length(partitions) == 20
assert_correct_partition(partitions, "foo")
- url = "/#{db_name}/_find"
+ url = "/#{db_name}/_find"
resp =
Couch.post(url,
@@ -74,266 +636,42 @@ defmodule PartitionMangoTest do
end
@tag :with_partitioned_db
- test "query using _id works for global and local query", context do
+ test "query using partitioned false index", context do
db_name = context[:db_name]
create_partition_docs(db_name)
- create_index(db_name)
+ create_index(db_name, [%{name: "some", type: "string"}],
+ %{
+ type: "text",
+ ddoc: "partitioned-false-index",
+ partitioned: false
+ })
- url = "/#{db_name}/_partition/foo/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- _id: %{
- "$gt": 0
- }
- },
- limit: 20
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 20
- assert_correct_partition(partitions, "foo")
-
- url = "/#{db_name}/_find"
+ url = "/#{db_name}/_partition/foo/_explain"
resp =
Couch.post(url,
body: %{
selector: %{
_id: %{
- "$gt": 0
+ "$gt": "foo:"
}
},
- limit: 20
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 20
- assert_correct_partition(partitions, "bar")
- end
-
- @tag :with_partitioned_db
- test "query with partitioned:true using index and $eq", context do
- db_name = context[:db_name]
- create_partition_docs(db_name)
- create_index(db_name)
-
- url = "/#{db_name}/_partition/foo/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- some: "field"
- },
- limit: 20
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 20
- assert_correct_partition(partitions, "foo")
-
- url = "/#{db_name}/_partition/bar/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- some: "field"
- },
- limit: 20
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 20
- assert_correct_partition(partitions, "bar")
- end
-
- @tag :with_partitioned_db
- test "partitioned query using _all_docs with $eq", context do
- db_name = context[:db_name]
- create_partition_docs(db_name)
-
- url = "/#{db_name}/_partition/foo/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- some: "field"
- },
- limit: 20
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 20
- assert_correct_partition(partitions, "foo")
-
- url = "/#{db_name}/_partition/bar/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- some: "field"
- },
- limit: 20
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 20
- assert_correct_partition(partitions, "bar")
- end
-
- @tag :with_db
- test "non-partitioned query using _all_docs and $eq", context do
- db_name = context[:db_name]
- create_partition_docs(db_name)
-
- url = "/#{db_name}/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- some: "field"
- },
- skip: 40,
- limit: 5
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 5
- assert partitions == ["bar", "bar", "bar", "bar", "bar"]
-
- url = "/#{db_name}/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- some: "field"
- },
- skip: 50,
- limit: 5
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 5
- assert partitions == ["foo", "foo", "foo", "foo", "foo"]
- end
-
- @tag :with_partitioned_db
- test "partitioned query using index and range scan", context do
- db_name = context[:db_name]
- create_partition_docs(db_name, "foo", "bar42")
- create_index(db_name, ["value"])
-
- url = "/#{db_name}/_partition/foo/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- value: %{
- "$gte": 6,
- "$lt": 16
- }
- }
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 5
- assert_correct_partition(partitions, "foo")
-
- url = "/#{db_name}/_partition/bar42/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- value: %{
- "$gte": 6,
- "$lt": 16
- }
- }
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 5
- assert_correct_partition(partitions, "bar42")
- end
-
- @tag :with_partitioned_db
- test "partitioned query using _all_docs and range scan", context do
- db_name = context[:db_name]
- create_partition_docs(db_name)
-
- url = "/#{db_name}/_partition/foo/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- value: %{
- "$gte": 6,
- "$lt": 16
- }
- }
+ limit: 20,
+ use_index: "partitioned-false-index"
}
)
assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 5
- assert_correct_partition(partitions, "foo")
-
- url = "/#{db_name}/_partition/bar/_find"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- value: %{
- "$gte": 6,
- "$lt": 16
- }
- }
- }
- )
-
- assert resp.status_code == 200
- partitions = get_partitions(resp)
- assert length(partitions) == 5
- assert_correct_partition(partitions, "bar")
+ %{:body => body} = resp
+ assert body["index"]["name"] == "_all_docs"
end
@tag :with_partitioned_db
- test "partitioned query using _all_docs", context do
+ test "partitioned query using text index and range scan", context do
db_name = context[:db_name]
create_partition_docs(db_name, "foo", "bar42")
+ create_index(db_name, [%{name: "value", type: "number"}],
+ %{type: "text"})
url = "/#{db_name}/_partition/foo/_find"
@@ -375,92 +713,11 @@ defmodule PartitionMangoTest do
end
@tag :with_partitioned_db
- test "explain works with partitions", context do
- db_name = context[:db_name]
- create_partition_docs(db_name)
- create_index(db_name, ["some"])
-
- url = "/#{db_name}/_partition/foo/_explain"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- value: %{
- "$gte": 6,
- "$lt": 16
- }
- }
- }
- )
-
- %{:body => body} = resp
-
- assert body["index"]["name"] == "_all_docs"
- assert body["mrargs"]["partition"] == "foo"
-
- url = "/#{db_name}/_partition/bar/_explain"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- some: "field"
- }
- }
- )
-
- %{:body => body} = resp
-
- assert body["index"]["def"] == %{"fields" => [%{"some" => "asc"}]}
- assert body["mrargs"]["partition"] == "bar"
- end
-
- @tag :with_db
- test "explain works with non partitioned db", context do
- db_name = context[:db_name]
- create_partition_docs(db_name)
- create_index(db_name, ["some"])
-
- url = "/#{db_name}/_explain"
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- value: %{
- "$gte": 6,
- "$lt": 16
- }
- }
- }
- )
-
- %{:body => body} = resp
-
- assert body["index"]["name"] == "_all_docs"
- assert body["mrargs"]["partition"] == :null
-
- resp =
- Couch.post(url,
- body: %{
- selector: %{
- some: "field"
- }
- }
- )
-
- %{:body => body} = resp
-
- assert body["index"]["def"] == %{"fields" => [%{"some" => "asc"}]}
- assert body["mrargs"]["partition"] == :null
- end
-
- @tag :with_partitioned_db
test "partitioned query using bookmarks", context do
db_name = context[:db_name]
create_partition_docs(db_name)
- create_index(db_name, ["value"])
+ create_index(db_name, [%{name: "value", type: "number"}],
+ %{type: "text"})
url = "/#{db_name}/_partition/foo/_find"
@@ -503,89 +760,4 @@ defmodule PartitionMangoTest do
assert length(partitions) == 2
assert_correct_partition(partitions, "foo")
end
-
- @tag :with_partitioned_db
- test "global query uses global index", context do
- db_name = context[:db_name]
- create_partition_docs(db_name)
- create_index(db_name, ["some"], %{partitioned: false})
-
- url = "/#{db_name}/_explain"
-
- selector = %{
- selector: %{
- some: "field"
- },
- limit: 100
- }
-
- resp = Couch.post(url, body: selector)
- assert resp.status_code == 200
- %{:body => body} = resp
- assert body["index"]["def"] == %{"fields" => [%{"some" => "asc"}]}
-
- url = "/#{db_name}/_find"
- resp = Couch.post(url, body: selector)
- assert resp.status_code == 200
-
- partitions = get_partitions(resp)
- assert length(partitions) == 100
- end
-
- @tag :with_partitioned_db
- test "global query does not use partition index", context do
- db_name = context[:db_name]
- create_partition_docs(db_name)
- create_index(db_name, ["some"])
-
- url = "/#{db_name}/_explain"
-
- selector = %{
- selector: %{
- some: "field"
- },
- limit: 100
- }
-
- resp = Couch.post(url, body: selector)
- %{:body => body} = resp
- assert body["index"]["name"] == "_all_docs"
-
- url = "/#{db_name}/_find"
- resp = Couch.post(url, body: selector)
-
- assert resp.status_code == 200
-
- partitions = get_partitions(resp)
- assert length(partitions) == 100
- end
-
- @tag :with_partitioned_db
- test "partitioned query does not use global index", context do
- db_name = context[:db_name]
- create_partition_docs(db_name)
- create_index(db_name, ["some"], %{partitioned: false})
-
- url = "/#{db_name}/_partition/foo/_explain"
-
- selector = %{
- selector: %{
- some: "field"
- },
- limit: 50
- }
-
- resp = Couch.post(url, body: selector)
- assert resp.status_code == 200
- %{:body => body} = resp
- assert body["index"]["name"] == "_all_docs"
-
- url = "/#{db_name}/_partition/foo/_find"
- resp = Couch.post(url, body: selector)
- assert resp.status_code == 200
-
- partitions = get_partitions(resp)
- assert length(partitions) == 50
- assert_correct_partition(partitions, "foo")
- end
end