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

[couchdb] branch test-database-partitions-size created (now c5af1e3)

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

jiangphcn pushed a change to branch test-database-partitions-size
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at c5af1e3  Add Elixir tests for database partitions size

This branch includes the following new commits:

     new c5af1e3  Add Elixir tests for database partitions size

The 1 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.



[couchdb] 01/01: Add Elixir tests for database partitions size

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

jiangphcn pushed a commit to branch test-database-partitions-size
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit c5af1e3240fcb587ec3a2aa0ea8f5fd7e3529179
Author: jiangph <ji...@cn.ibm.com>
AuthorDate: Mon Jan 14 15:14:26 2019 +0800

    Add Elixir tests for database partitions size
---
 test/elixir/test/partition_helpers.exs   | 88 ++++++++++++++++++++++++++++++++
 test/elixir/test/partition_size_test.exs | 12 +++++
 2 files changed, 100 insertions(+)

diff --git a/test/elixir/test/partition_helpers.exs b/test/elixir/test/partition_helpers.exs
index 6eac2b1..4920c11 100644
--- a/test/elixir/test/partition_helpers.exs
+++ b/test/elixir/test/partition_helpers.exs
@@ -1,5 +1,6 @@
 defmodule PartitionHelpers do
   use ExUnit.Case
+  use CouchTestCase
 
   def create_partition_docs(db_name, pk1 \\ "foo", pk2 \\ "bar") do
     docs =
@@ -54,6 +55,81 @@ defmodule PartitionHelpers do
     assert Map.has_key?(resp.body, "ok") == true
   end
 
+  def crud_partition_doc(db_name, pk \\ "foo") do
+    resp = Couch.post("/#{db_name}", body: %{:_id => "#{pk}:id1", :a => 1, :b => 1}).body
+    assert resp["ok"]
+
+    url = "/#{db_name}/_partition/#{pk}"
+    resp = Couch.get(url)
+
+    assert resp.status_code == 200
+    %{:body => body} = resp
+    assert body["doc_count"] == 1
+    assert body["doc_del_count"] == 0
+    assert body["partition"] == "#{pk}"
+    exernal_size1 = body["sizes"]["external"]
+    assert exernal_size1 > 0
+
+    resp = Couch.post("/#{db_name}", body: %{:_id => "#{pk}:id2", :a => 2, :b => 22}).body
+    rev = resp["rev"]
+    assert resp["ok"]
+
+    url = "/#{db_name}/_partition/#{pk}"
+    resp = Couch.get(url)
+
+    assert resp.status_code == 200
+    %{:body => body} = resp
+    assert body["doc_count"] == 2
+    assert body["doc_del_count"] == 0
+    assert body["partition"] == "#{pk}"
+    exernal_size2 = body["sizes"]["external"]
+    assert exernal_size2 > exernal_size1
+
+    resp = Couch.delete("/#{db_name}/#{pk}:id2?rev=#{rev}").body
+    assert resp["ok"]
+    :timer.sleep(300)
+
+    url = "/#{db_name}/_partition/#{pk}"
+    resp = Couch.get(url)
+
+    assert resp.status_code == 200
+    %{:body => body} = resp
+    assert body["doc_count"] == 1
+    assert body["doc_del_count"] == 1
+    assert body["partition"] == "#{pk}"
+    exernal_size3 = body["sizes"]["external"]
+    assert exernal_size3 <= exernal_size2
+
+    compact(db_name)
+
+    url = "/#{db_name}/_partition/#{pk}"
+    resp = Couch.get(url)
+    %{:body => body} = resp
+    exernal_size4 = body["sizes"]["external"]
+    assert exernal_size4 < exernal_size3
+
+    map = ~s"""
+    function (doc) {
+      emit(doc.integer, doc.integer);
+      emit(doc.integer, doc.integer);
+    };
+    """
+    red_doc = %{:views => %{:bar => %{:map => map}}}
+
+    assert Couch.put("/#{db_name}/_design/#{pk}_foo", body: red_doc).body["ok"]
+
+    url = "/#{db_name}/_partition/#{pk}"
+    resp = Couch.get(url)
+
+    assert resp.status_code == 200
+    %{:body => body} = resp
+    assert body["doc_count"] == 1
+    assert body["doc_del_count"] == 1
+    assert body["partition"] == "#{pk}"
+    exernal_size5 = body["sizes"]["external"]
+    assert exernal_size5 == exernal_size4
+  end
+
   def get_ids(resp) do
     %{:body => %{"rows" => rows}} = resp
     Enum.map(rows, fn row -> row["id"] end)
@@ -73,4 +149,16 @@ defmodule PartitionHelpers do
              partition == correct_partition
            end)
   end
+
+  def compact(db) do
+    assert Couch.post("/#{db}/_compact").status_code == 202
+
+    retry_until(
+      fn ->
+        Couch.get("/#{db}").body["compact_running"] == false
+      end,
+      200,
+      20_000
+    )
+  end
 end
diff --git a/test/elixir/test/partition_size_test.exs b/test/elixir/test/partition_size_test.exs
index 289d1e1..3cd30e8 100644
--- a/test/elixir/test/partition_size_test.exs
+++ b/test/elixir/test/partition_size_test.exs
@@ -1,5 +1,6 @@
 defmodule PartitionSizeTest do
   use CouchTestCase
+  import PartitionHelpers
 
   @moduledoc """
   Test Partition size functionality
@@ -85,6 +86,17 @@ defmodule PartitionSizeTest do
     assert info["sizes"]["active"] > 0
   end
 
+  test "get partition size for curd", context do
+    db_name = context[:db_name]
+    crud_partition_doc(db_name, "pk1")
+  end
+
+  test "get partition size for multipe curd", context do
+    db_name = context[:db_name]
+    crud_partition_doc(db_name, "pk1")
+    crud_partition_doc(db_name, "pk2")
+  end
+
   test "adding docs increases partition sizes", context do
     db_name = context[:db_name]
     save_doc(db_name, %{_id: "foo:bar", val: 42})