summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiangph <jiangph@cn.ibm.com>2019-01-14 15:14:26 +0800
committerjiangph <jiangph@cn.ibm.com>2019-01-14 15:14:26 +0800
commitc5af1e3240fcb587ec3a2aa0ea8f5fd7e3529179 (patch)
treebb0a5fd254549d19f1771e80887a911138ea65e7
parent2635741ef15d609836b491adc4f35b2bd3fa9348 (diff)
downloadcouchdb-test-database-partitions-size.tar.gz
Add Elixir tests for database partitions sizearchive/test-database-partitions-sizetest-database-partitions-size
-rw-r--r--test/elixir/test/partition_helpers.exs88
-rw-r--r--test/elixir/test/partition_size_test.exs12
2 files changed, 100 insertions, 0 deletions
diff --git a/test/elixir/test/partition_helpers.exs b/test/elixir/test/partition_helpers.exs
index 6eac2b1a4..4920c1198 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 289d1e113..3cd30e8ce 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})