summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuanjo Rodriguez <juanjo@apache.org>2020-07-07 09:04:15 +0200
committerJuanjo Rodriguez <jjrodrig@gmail.com>2020-07-07 13:07:59 +0200
commitce22cbcc2c92de456f0a1d98c30d2ea17a3010c6 (patch)
treed23e93c1ece43ee49d5937789e827b83124352eb
parent23b4aa78e09cceb9424ab1b0b9891755ecb46ba7 (diff)
downloadcouchdb-ce22cbcc2c92de456f0a1d98c30d2ea17a3010c6.tar.gz
Port view_compaction test to elixir
-rw-r--r--test/elixir/README.md4
-rw-r--r--test/elixir/lib/couch/db_test.ex1
-rw-r--r--test/elixir/test/view_compaction_test.exs105
-rw-r--r--test/javascript/tests/view_compaction.js1
4 files changed, 109 insertions, 2 deletions
diff --git a/test/elixir/README.md b/test/elixir/README.md
index 44cca52d9..cf529438d 100644
--- a/test/elixir/README.md
+++ b/test/elixir/README.md
@@ -100,7 +100,7 @@ X means done, - means partially
- [X] Port uuids.js
- [X] Port view_collation.js
- [X] Port view_collation_raw.js
- - [ ] Port view_compaction.js
+ - [X] Port view_compaction.js
- [ ] Port view_conflicts.js
- [ ] Port view_errors.js
- [ ] Port view_include_docs.js
@@ -110,7 +110,7 @@ X means done, - means partially
- [X] Port view_offsets.js
- [X] Port view_pagination.js
- [ ] Port view_sandboxing.js
- - [ ] Port view_update_seq.js
+ - [X] Port view_update_seq.js
# Using ExUnit to write unit tests
diff --git a/test/elixir/lib/couch/db_test.ex b/test/elixir/lib/couch/db_test.ex
index 23f10937d..652fa6bb6 100644
--- a/test/elixir/lib/couch/db_test.ex
+++ b/test/elixir/lib/couch/db_test.ex
@@ -209,6 +209,7 @@ defmodule Couch.DBTest do
)
assert resp.status_code in [201, 202]
+ resp
end
def query(
diff --git a/test/elixir/test/view_compaction_test.exs b/test/elixir/test/view_compaction_test.exs
new file mode 100644
index 000000000..d2bf060ba
--- /dev/null
+++ b/test/elixir/test/view_compaction_test.exs
@@ -0,0 +1,105 @@
+defmodule ViewCompactionTest do
+ use CouchTestCase
+
+ @moduledoc """
+ Test CouchDB View Compaction Behavior
+ This is a port of the view_compaction.js suite
+ """
+ @num_docs 1000
+
+ @ddoc %{
+ _id: "_design/foo",
+ language: "javascript",
+ views: %{
+ view1: %{
+ map: "function(doc) { emit(doc._id, doc.value) }"
+ },
+ view2: %{
+ map:
+ "function(doc) { if (typeof(doc.integer) === 'number') {emit(doc._id, doc.integer);} }",
+ reduce: "function(keys, values, rereduce) { return sum(values); }"
+ }
+ }
+ }
+
+ defp bulk_save_for_update(db_name, docs) do
+ resp = bulk_save(db_name, docs)
+ revs = resp.body
+
+ Enum.map(docs, fn m ->
+ rev = Enum.at(revs, String.to_integer(m["_id"]))["rev"]
+
+ m
+ |> Map.put("_rev", rev)
+ |> Map.update!("integer", &(&1 + 1))
+ end)
+ end
+
+ @tag :with_db
+ test "view compaction", context do
+ db_name = context[:db_name]
+ create_doc(db_name, @ddoc)
+
+ docs = make_docs(0..(@num_docs - 1))
+ docs = bulk_save_for_update(db_name, docs)
+
+ resp = view(db_name, "foo/view1")
+ assert length(resp.body["rows"]) == @num_docs
+
+ resp = view(db_name, "foo/view2")
+ assert length(resp.body["rows"]) == 1
+
+ resp = Couch.get("/#{db_name}/_design/foo/_info")
+ assert resp.body["view_index"]["update_seq"] == @num_docs + 1
+
+ docs = bulk_save_for_update(db_name, docs)
+
+ resp = view(db_name, "foo/view1")
+ assert length(resp.body["rows"]) == @num_docs
+
+ resp = view(db_name, "foo/view2")
+ assert length(resp.body["rows"]) == 1
+
+ resp = Couch.get("/#{db_name}/_design/foo/_info")
+ assert resp.body["view_index"]["update_seq"] == 2 * @num_docs + 1
+
+ bulk_save(db_name, docs)
+ resp = view(db_name, "foo/view1")
+ assert length(resp.body["rows"]) == @num_docs
+
+ resp = view(db_name, "foo/view2")
+ assert length(resp.body["rows"]) == 1
+
+ resp = Couch.get("/#{db_name}/_design/foo/_info")
+ assert resp.body["view_index"]["update_seq"] == 3 * @num_docs + 1
+
+ disk_size_before_compact = resp.body["view_index"]["sizes"]["file"]
+ data_size_before_compact = resp.body["view_index"]["sizes"]["active"]
+
+ assert is_integer(disk_size_before_compact)
+ assert data_size_before_compact < disk_size_before_compact
+
+ resp = Couch.post("/#{db_name}/_compact/foo")
+ assert resp.body["ok"] == true
+
+ retry_until(fn ->
+ resp = Couch.get("/#{db_name}/_design/foo/_info")
+ resp.body["view_index"]["compact_running"] == false
+ end)
+
+ resp = view(db_name, "foo/view1")
+ assert length(resp.body["rows"]) == @num_docs
+
+ resp = view(db_name, "foo/view2")
+ assert length(resp.body["rows"]) == 1
+
+ resp = Couch.get("/#{db_name}/_design/foo/_info")
+ assert resp.body["view_index"]["update_seq"] == 3 * @num_docs + 1
+
+ disk_size_after_compact = resp.body["view_index"]["sizes"]["file"]
+ data_size_after_compact = resp.body["view_index"]["sizes"]["active"]
+ assert disk_size_after_compact < disk_size_before_compact
+ assert is_integer(data_size_after_compact)
+ assert data_size_after_compact < disk_size_after_compact
+ end
+end
diff --git a/test/javascript/tests/view_compaction.js b/test/javascript/tests/view_compaction.js
index d1a1e8790..f2af39058 100644
--- a/test/javascript/tests/view_compaction.js
+++ b/test/javascript/tests/view_compaction.js
@@ -10,6 +10,7 @@
// License for the specific language governing permissions and limitations under
// the License.
+couchTests.elixir = true;
couchTests.view_compaction = function(debug) {
if (debug) debugger;