You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ju...@apache.org on 2020/07/07 15:01:09 UTC

[couchdb] branch 3.x updated (ace7e68 -> 8c572bf)

This is an automated email from the ASF dual-hosted git repository.

juanjo pushed a change to branch 3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


    from ace7e68  fix: set gen_server:call() timeout to infinity on ioq bypass
     new 9cd4df9  Port view_collation_raw.js to elixir
     new 8c572bf  Port view_compaction test to elixir

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 test/elixir/README.md                              |   6 +-
 test/elixir/lib/couch/db_test.ex                   |   1 +
 ...lation_test.exs => view_collation_raw_test.exs} |  81 +++++++++-------
 test/elixir/test/view_compaction_test.exs          | 105 +++++++++++++++++++++
 test/javascript/tests/view_collation_raw.js        |   1 +
 test/javascript/tests/view_compaction.js           |   1 +
 6 files changed, 159 insertions(+), 36 deletions(-)
 copy test/elixir/test/{view_collation_test.exs => view_collation_raw_test.exs} (77%)
 create mode 100644 test/elixir/test/view_compaction_test.exs


[couchdb] 01/02: Port view_collation_raw.js to elixir

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanjo pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 9cd4df9c5d1dcdf7a7b8bc80c9e08a9e301de31b
Author: Juanjo Rodriguez <ju...@apache.org>
AuthorDate: Wed Jul 1 08:36:25 2020 +0200

    Port view_collation_raw.js to elixir
---
 test/elixir/README.md                        |   2 +-
 test/elixir/test/view_collation_raw_test.exs | 159 +++++++++++++++++++++++++++
 test/javascript/tests/view_collation_raw.js  |   1 +
 3 files changed, 161 insertions(+), 1 deletion(-)

diff --git a/test/elixir/README.md b/test/elixir/README.md
index 0043fcf..de5cb20 100644
--- a/test/elixir/README.md
+++ b/test/elixir/README.md
@@ -99,7 +99,7 @@ X means done, - means partially
   - [X] Port utf8.js
   - [X] Port uuids.js
   - [X] Port view_collation.js
-  - [ ] Port view_collation_raw.js
+  - [X] Port view_collation_raw.js
   - [ ] Port view_compaction.js
   - [ ] Port view_conflicts.js
   - [ ] Port view_errors.js
diff --git a/test/elixir/test/view_collation_raw_test.exs b/test/elixir/test/view_collation_raw_test.exs
new file mode 100644
index 0000000..ee272d7
--- /dev/null
+++ b/test/elixir/test/view_collation_raw_test.exs
@@ -0,0 +1,159 @@
+defmodule ViewCollationRawTest do
+  use CouchTestCase
+
+  @moduledoc """
+  Test CouchDB View Raw Collation Behavior
+  This is a port of the view_collation_raw.js suite
+  """
+
+  @values [
+    # Then numbers
+    1,
+    2,
+    3,
+    4,
+    false,
+    :null,
+    true,
+
+    # Then objects, compared each key value in the list until different.
+    # Larger objects sort after their subset objects
+    {[a: 1]},
+    {[a: 2]},
+    {[b: 1]},
+    {[b: 2]},
+    # Member order does matter for collation
+    {[b: 2, a: 1]},
+    {[b: 2, c: 2]},
+
+    # Then arrays, compared element by element until different.
+    # Longer arrays sort after their prefixes
+    ["a"],
+    ["b"],
+    ["b", "c"],
+    ["b", "c", "a"],
+    ["b", "d"],
+    ["b", "d", "e"],
+
+    # Then text, case sensitive
+    "A",
+    "B",
+    "a",
+    "aa",
+    "b",
+    "ba",
+    "bb"
+  ]
+
+  setup_all do
+    db_name = random_db_name()
+    {:ok, _} = create_db(db_name)
+    on_exit(fn -> delete_db(db_name) end)
+
+    {docs, _} =
+      Enum.flat_map_reduce(@values, 1, fn value, idx ->
+        doc = %{:_id => Integer.to_string(idx), :foo => value}
+        {[doc], idx + 1}
+      end)
+
+    resp = Couch.post("/#{db_name}/_bulk_docs", body: %{:docs => docs})
+    Enum.each(resp.body, &assert(&1["ok"]))
+
+    map_fun = "function(doc) { emit(doc.foo, null); }"
+
+    map_doc = %{
+      :language => "javascript",
+      :views => %{:test => %{:map => map_fun, :options => %{:collation => "raw"}}}
+    }
+
+    resp = Couch.put("/#{db_name}/_design/test", body: map_doc)
+    assert resp.body["ok"]
+
+    {:ok, [db_name: db_name]}
+  end
+
+  test "ascending collation order", context do
+    retry_until(fn ->
+      resp = Couch.get(url(context))
+      pairs = Enum.zip(resp.body["rows"], @values)
+
+      Enum.each(pairs, fn {row, value} ->
+        assert row["key"] == convert(value)
+      end)
+    end)
+  end
+
+  test "raw semantics in key ranges", context do
+    retry_until(fn ->
+      resp =
+        Couch.get(url(context),
+          query: %{"startkey" => :jiffy.encode("Z"), "endkey" => :jiffy.encode("a")}
+        )
+
+      assert length(resp.body["rows"]) == 1
+      assert Enum.at(resp.body["rows"], 0)["key"] == "a"
+    end)
+  end
+
+  test "descending collation order", context do
+    retry_until(fn ->
+      resp = Couch.get(url(context), query: %{"descending" => "true"})
+      pairs = Enum.zip(resp.body["rows"], Enum.reverse(@values))
+
+      Enum.each(pairs, fn {row, value} ->
+        assert row["key"] == convert(value)
+      end)
+    end)
+  end
+
+  test "key query option", context do
+    Enum.each(@values, fn value ->
+      retry_until(fn ->
+        resp = Couch.get(url(context), query: %{:key => :jiffy.encode(value)})
+        assert length(resp.body["rows"]) == 1
+        assert Enum.at(resp.body["rows"], 0)["key"] == convert(value)
+      end)
+    end)
+  end
+
+  test "inclusive_end=true", context do
+    query = %{:endkey => :jiffy.encode("b"), :inclusive_end => true}
+    resp = Couch.get(url(context), query: query)
+    assert Enum.at(resp.body["rows"], -1)["key"] == "b"
+
+    query = Map.put(query, :descending, true)
+    resp = Couch.get(url(context), query: query)
+    assert Enum.at(resp.body["rows"], -1)["key"] == "b"
+  end
+
+  test "inclusive_end=false", context do
+    query = %{:endkey => :jiffy.encode("b"), :inclusive_end => false}
+    resp = Couch.get(url(context), query: query)
+    assert Enum.at(resp.body["rows"], -1)["key"] == "aa"
+
+    query = Map.put(query, :descending, true)
+    resp = Couch.get(url(context), query: query)
+    assert Enum.at(resp.body["rows"], -1)["key"] == "ba"
+
+    query = %{
+      :endkey => :jiffy.encode("b"),
+      :endkey_docid => 10,
+      :inclusive_end => false
+    }
+
+    resp = Couch.get(url(context), query: query)
+    assert Enum.at(resp.body["rows"], -1)["key"] == "aa"
+
+    query = Map.put(query, :endkey_docid, 11)
+    resp = Couch.get(url(context), query: query)
+    assert Enum.at(resp.body["rows"], -1)["key"] == "aa"
+  end
+
+  def url(context) do
+    "/#{context[:db_name]}/_design/test/_view/test"
+  end
+
+  def convert(value) do
+    :jiffy.decode(:jiffy.encode(value), [:return_maps])
+  end
+end
diff --git a/test/javascript/tests/view_collation_raw.js b/test/javascript/tests/view_collation_raw.js
index 9b02ff4..ee990bc 100644
--- a/test/javascript/tests/view_collation_raw.js
+++ b/test/javascript/tests/view_collation_raw.js
@@ -10,6 +10,7 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
+couchTests.elixir = true;
 couchTests.view_collation_raw = function(debug) {
   var db_name = get_random_db_name();
   var db = new CouchDB(db_name, {"X-Couch-Full-Commit":"false"});


[couchdb] 02/02: Port view_compaction test to elixir

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanjo pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 8c572bf45744e83c095fe56ffaf7a3c465bf16b9
Author: Juanjo Rodriguez <ju...@apache.org>
AuthorDate: Tue Jul 7 09:04:15 2020 +0200

    Port view_compaction test to elixir
---
 test/elixir/README.md                     |   4 +-
 test/elixir/lib/couch/db_test.ex          |   1 +
 test/elixir/test/view_compaction_test.exs | 105 ++++++++++++++++++++++++++++++
 test/javascript/tests/view_compaction.js  |   1 +
 4 files changed, 109 insertions(+), 2 deletions(-)

diff --git a/test/elixir/README.md b/test/elixir/README.md
index de5cb20..e48dc29 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 23f1093..652fa6b 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 0000000..d2bf060
--- /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 d1a1e87..f2af390 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;