couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [08/50] couchdb commit: updated refs/heads/1963-eunit to bfb7eb9
Date Mon, 16 Jun 2014 22:52:49 GMT
Port 076-file-compression.t etap test suite to eunit

The original test suite was decoupled into compaction and comparison
cases.


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/e656e8d7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/e656e8d7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/e656e8d7

Branch: refs/heads/1963-eunit
Commit: e656e8d710e565fc0c7aa0420dee2b407dadd3f8
Parents: 085e0ed
Author: Alexander Shorin <kxepal@apache.org>
Authored: Thu May 22 20:17:47 2014 +0400
Committer: Alexander Shorin <kxepal@apache.org>
Committed: Mon Jun 16 00:51:18 2014 +0400

----------------------------------------------------------------------
 test/couchdb/Makefile.am                        |   1 +
 test/couchdb/couchdb_file_compression_tests.erl | 239 +++++++++++++++++++
 test/etap/076-file-compression.t                | 186 ---------------
 test/etap/Makefile.am                           |   1 -
 4 files changed, 240 insertions(+), 187 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/e656e8d7/test/couchdb/Makefile.am
----------------------------------------------------------------------
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am
index 16b6295..fda7560 100644
--- a/test/couchdb/Makefile.am
+++ b/test/couchdb/Makefile.am
@@ -30,6 +30,7 @@ eunit_files = \
     couch_util_tests.erl \
     couch_uuids_tests.erl \
     couch_work_queue_tests.erl \
+    couchdb_file_compression_tests.erl \
     couchdb_modules_load_tests.erl \
     couchdb_update_conflicts_tests.erl \
     couchdb_views_tests.erl \

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e656e8d7/test/couchdb/couchdb_file_compression_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couchdb_file_compression_tests.erl b/test/couchdb/couchdb_file_compression_tests.erl
new file mode 100644
index 0000000..fd3f513
--- /dev/null
+++ b/test/couchdb/couchdb_file_compression_tests.erl
@@ -0,0 +1,239 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couchdb_file_compression_tests).
+
+-include("couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+-define(DDOC_ID, <<"_design/test">>).
+-define(DOCS_COUNT, 5000).
+-define(TIMEOUT, 30000).
+
+
+start() ->
+    {ok, Pid} = couch_server_sup:start_link(?CONFIG_CHAIN),
+    Pid.
+
+stop(Pid) ->
+    erlang:monitor(process, Pid),
+    couch_server_sup:stop(),
+    receive
+        {'DOWN', _, _, Pid, _} ->
+            ok
+    after ?TIMEOUT ->
+        throw({timeout, server_stop})
+    end.
+
+setup() ->
+    couch_config:set("couchdb", "file_compression", "none", false),
+    DbName = ?tempdb(),
+    {ok, Db} = couch_db:create(DbName, [?ADMIN_USER]),
+    ok = populate_db(Db, ?DOCS_COUNT),
+    DDoc = couch_doc:from_json_obj({[
+        {<<"_id">>, ?DDOC_ID},
+        {<<"language">>, <<"javascript">>},
+        {<<"views">>, {[
+                {<<"by_id">>, {[
+                    {<<"map">>, <<"function(doc){emit(doc._id, doc.string);}">>}
+                ]}}
+            ]}
+        }
+    ]}),
+    {ok, _} = couch_db:update_doc(Db, DDoc, []),
+    refresh_index(DbName),
+    ok = couch_db:close(Db),
+    DbName.
+
+teardown(DbName) ->
+    ok = couch_server:delete(DbName, [?ADMIN_USER]),
+    ok.
+
+
+couch_auth_cache_test_() ->
+    {
+        "CouchDB file compression tests",
+        {
+            setup,
+            fun start/0, fun stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_use_none/1,
+                    fun should_use_deflate_1/1,
+                    fun should_use_deflate_9/1,
+                    fun should_use_snappy/1,
+                    fun should_compare_compression_methods/1
+                ]
+            }
+        }
+    }.
+
+
+should_use_none(DbName) ->
+    couch_config:set("couchdb", "file_compression", "none", false),
+    {
+        "Use no compression",
+        [
+            {"compact database", ?_test(compact_db(DbName))},
+            {"compact view", ?_test(compact_view(DbName))}
+        ]
+    }.
+
+should_use_deflate_1(DbName) ->
+    couch_config:set("couchdb", "file_compression", "deflate_1", false),
+    {
+        "Use deflate compression at level 1",
+        [
+            {"compact database", ?_test(compact_db(DbName))},
+            {"compact view", ?_test(compact_view(DbName))}
+        ]
+    }.
+
+should_use_deflate_9(DbName) ->
+    couch_config:set("couchdb", "file_compression", "deflate_9", false),
+    {
+        "Use deflate compression at level 9",
+        [
+            {"compact database", ?_test(compact_db(DbName))},
+            {"compact view", ?_test(compact_view(DbName))}
+        ]
+    }.
+
+should_use_snappy(DbName) ->
+    couch_config:set("couchdb", "file_compression", "snappy", false),
+    {
+        "Use snappy compression",
+        [
+            {"compact database", ?_test(compact_db(DbName))},
+            {"compact view", ?_test(compact_view(DbName))}
+        ]
+    }.
+
+should_compare_compression_methods(DbName) ->
+    {"none > snappy > deflate_1 > deflate_9",
+     {timeout, ?TIMEOUT div 1000, ?_test(compare_compression_methods(DbName))}}.
+
+compare_compression_methods(DbName) ->
+    couch_config:set("couchdb", "file_compression", "none", false),
+    compact_db(DbName),
+    compact_view(DbName),
+    DbSizeNone = db_disk_size(DbName),
+    ViewSizeNone = view_disk_size(DbName),
+
+    couch_config:set("couchdb", "file_compression", "snappy", false),
+    compact_db(DbName),
+    compact_view(DbName),
+    DbSizeSnappy = db_disk_size(DbName),
+    ViewSizeSnappy = view_disk_size(DbName),
+
+    ?assert(DbSizeNone > DbSizeSnappy),
+    ?assert(ViewSizeNone > ViewSizeSnappy),
+
+    couch_config:set("couchdb", "file_compression", "deflate_1", false),
+    compact_db(DbName),
+    compact_view(DbName),
+    DbSizeDeflate1 = db_disk_size(DbName),
+    ViewSizeDeflate1 = view_disk_size(DbName),
+
+    ?assert(DbSizeSnappy > DbSizeDeflate1),
+    ?assert(ViewSizeSnappy > ViewSizeDeflate1),
+
+    couch_config:set("couchdb", "file_compression", "deflate_9", false),
+    compact_db(DbName),
+    compact_view(DbName),
+    DbSizeDeflate9 = db_disk_size(DbName),
+    ViewSizeDeflate9 = view_disk_size(DbName),
+
+    ?assert(DbSizeDeflate1 > DbSizeDeflate9),
+    ?assert(ViewSizeDeflate1 > ViewSizeDeflate9).
+
+
+populate_db(_Db, NumDocs) when NumDocs =< 0 ->
+    ok;
+populate_db(Db, NumDocs) ->
+    Docs = lists:map(
+        fun(_) ->
+            couch_doc:from_json_obj({[
+                {<<"_id">>, couch_uuids:random()},
+                {<<"string">>, ?l2b(lists:duplicate(1000, $X))}
+            ]})
+        end,
+        lists:seq(1, 500)),
+    {ok, _} = couch_db:update_docs(Db, Docs, []),
+    populate_db(Db, NumDocs - 500).
+
+refresh_index(DbName) ->
+    {ok, Db} = couch_db:open_int(DbName, []),
+    {ok, DDoc} = couch_db:open_doc(Db, ?DDOC_ID, [ejson_body]),
+    couch_mrview:query_view(Db, DDoc, <<"by_id">>, [{stale, false}]),
+    ok = couch_db:close(Db).
+
+compact_db(DbName) ->
+    DiskSizeBefore = db_disk_size(DbName),
+    {ok, Db} = couch_db:open_int(DbName, []),
+    {ok, CompactPid} = couch_db:start_compact(Db),
+    MonRef = erlang:monitor(process, CompactPid),
+    receive
+        {'DOWN', MonRef, process, CompactPid, normal} ->
+            ok;
+        {'DOWN', MonRef, process, CompactPid, Reason} ->
+            erlang:error({assertion_failed,
+                          [{module, ?MODULE},
+                           {line, ?LINE},
+                           {reason, "Error compacting database: "
+                                    ++ couch_util:to_list(Reason)}]})
+    after ?TIMEOUT ->
+        erlang:error({assertion_failed,
+                      [{module, ?MODULE},
+                       {line, ?LINE},
+                       {reason, "Timeout waiting for database compaction"}]})
+    end,
+    ok = couch_db:close(Db),
+    DiskSizeAfter = db_disk_size(DbName),
+    ?assert(DiskSizeBefore > DiskSizeAfter).
+
+compact_view(DbName) ->
+    DiskSizeBefore = view_disk_size(DbName),
+    {ok, MonRef} = couch_mrview:compact(DbName, ?DDOC_ID, [monitor]),
+    receive
+        {'DOWN', MonRef, process, _CompactPid, normal} ->
+            ok;
+        {'DOWN', MonRef, process, _CompactPid, Reason} ->
+            erlang:error({assertion_failed,
+                          [{module, ?MODULE},
+                           {line, ?LINE},
+                           {reason, "Error compacting view group: "
+                                    ++ couch_util:to_list(Reason)}]})
+    after ?TIMEOUT ->
+        erlang:error({assertion_failed,
+                      [{module, ?MODULE},
+                       {line, ?LINE},
+                       {reason, "Timeout waiting for view group compaction"}]})
+    end,
+    DiskSizeAfter = view_disk_size(DbName),
+    ?assert(DiskSizeBefore > DiskSizeAfter).
+
+db_disk_size(DbName) ->
+    {ok, Db} = couch_db:open_int(DbName, []),
+    {ok, Info} = couch_db:get_db_info(Db),
+    ok = couch_db:close(Db),
+    couch_util:get_value(disk_size, Info).
+
+view_disk_size(DbName) ->
+    {ok, Db} = couch_db:open_int(DbName, []),
+    {ok, DDoc} = couch_db:open_doc(Db, ?DDOC_ID, [ejson_body]),
+    {ok, Info} = couch_mrview:get_info(Db, DDoc),
+    ok = couch_db:close(Db),
+    couch_util:get_value(disk_size, Info).

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e656e8d7/test/etap/076-file-compression.t
----------------------------------------------------------------------
diff --git a/test/etap/076-file-compression.t b/test/etap/076-file-compression.t
deleted file mode 100755
index 2929230..0000000
--- a/test/etap/076-file-compression.t
+++ /dev/null
@@ -1,186 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-%   http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--record(user_ctx, {
-    name = null,
-    roles = [],
-    handler
-}).
-
-test_db_name() -> <<"couch_test_file_compression">>.
-ddoc_id() -> <<"_design/test">>.
-num_docs() -> 5000.
-
-
-main(_) ->
-    test_util:init_code_path(),
-
-    etap:plan(10),
-    case (catch test()) of
-        ok ->
-            etap:end_tests();
-        Other ->
-            etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
-            etap:bail(Other)
-    end,
-    ok.
-
-
-test() ->
-    couch_server_sup:start_link(test_util:config_files()),
-    couch_config:set("couchdb", "file_compression", "none", false),
-
-    create_database(),
-    compact_db(),
-    compact_view(),
-    DbDiskSize1 = db_disk_size(),
-    ViewDiskSize1 = view_disk_size(),
-
-    couch_config:set("couchdb", "file_compression", "snappy", false),
-    compact_db(),
-    compact_view(),
-    DbDiskSize2 = db_disk_size(),
-    ViewDiskSize2 = view_disk_size(),
-
-    etap:is(DbDiskSize2 < DbDiskSize1, true, "Database disk size decreased"),
-    etap:is(ViewDiskSize2 < ViewDiskSize1, true, "Index disk size decreased"),
-
-    couch_config:set("couchdb", "file_compression", "deflate_9", false),
-    compact_db(),
-    compact_view(),
-    DbDiskSize3 = db_disk_size(),
-    ViewDiskSize3 = view_disk_size(),
-
-    etap:is(DbDiskSize3 < DbDiskSize2, true, "Database disk size decreased again"),
-    etap:is(ViewDiskSize3 < ViewDiskSize2, true, "Index disk size decreased again"),
-
-    couch_config:set("couchdb", "file_compression", "deflate_1", false),
-    compact_db(),
-    compact_view(),
-    DbDiskSize4 = db_disk_size(),
-    ViewDiskSize4 = view_disk_size(),
-
-    etap:is(DbDiskSize4 > DbDiskSize3, true, "Database disk size increased"),
-    etap:is(ViewDiskSize4 > ViewDiskSize3, true, "Index disk size increased"),
-
-    couch_config:set("couchdb", "file_compression", "snappy", false),
-    compact_db(),
-    compact_view(),
-    DbDiskSize5 = db_disk_size(),
-    ViewDiskSize5 = view_disk_size(),
-
-    etap:is(DbDiskSize5 > DbDiskSize4, true, "Database disk size increased again"),
-    etap:is(ViewDiskSize5 > ViewDiskSize4, true, "Index disk size increased again"),
-
-    couch_config:set("couchdb", "file_compression", "none", false),
-    compact_db(),
-    compact_view(),
-    DbDiskSize6 = db_disk_size(),
-    ViewDiskSize6 = view_disk_size(),
-
-    etap:is(DbDiskSize6 > DbDiskSize5, true, "Database disk size increased again"),
-    etap:is(ViewDiskSize6 > ViewDiskSize5, true, "Index disk size increased again"),
-
-    delete_db(),
-    couch_server_sup:stop(),
-    ok.
-
-
-create_database() ->
-    {ok, Db} = couch_db:create(
-        test_db_name(),
-        [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}, overwrite]),
-    ok = populate_db(Db, num_docs()),
-    DDoc = couch_doc:from_json_obj({[
-        {<<"_id">>, ddoc_id()},
-        {<<"language">>, <<"javascript">>},
-        {<<"views">>, {[
-                {<<"view1">>, {[
-                    {<<"map">>, <<"function(doc) { emit(doc._id, doc.string);
}">>}
-                ]}}
-            ]}
-        }
-    ]}),
-    {ok, _} = couch_db:update_doc(Db, DDoc, []),
-    refresh_index(),
-    ok = couch_db:close(Db).
-
-
-populate_db(_Db, NumDocs) when NumDocs =< 0 ->
-    ok;
-populate_db(Db, NumDocs) ->
-    Docs = lists:map(
-        fun(_) ->
-            couch_doc:from_json_obj({[
-                {<<"_id">>, couch_uuids:random()},
-                {<<"string">>, list_to_binary(lists:duplicate(1000, $X))}
-            ]})
-        end,
-        lists:seq(1, 500)),
-    {ok, _} = couch_db:update_docs(Db, Docs, []),
-    populate_db(Db, NumDocs - 500).
-
-
-refresh_index() ->
-    {ok, Db} = couch_db:open_int(test_db_name(), []),
-    {ok, DDoc} = couch_db:open_doc(Db, ddoc_id(), [ejson_body]),
-    couch_mrview:query_view(Db, DDoc, <<"view1">>, [{stale, false}]),
-    ok = couch_db:close(Db).
-
-
-compact_db() ->
-    {ok, Db} = couch_db:open_int(test_db_name(), []),
-    {ok, CompactPid} = couch_db:start_compact(Db),
-    MonRef = erlang:monitor(process, CompactPid),
-    receive
-    {'DOWN', MonRef, process, CompactPid, normal} ->
-        ok;
-    {'DOWN', MonRef, process, CompactPid, Reason} ->
-        etap:bail("Error compacting database: " ++ couch_util:to_list(Reason))
-    after 120000 ->
-        etap:bail("Timeout waiting for database compaction")
-    end,
-    ok = couch_db:close(Db).
-
-
-compact_view() ->
-    {ok, MonRef} = couch_mrview:compact(test_db_name(), ddoc_id(), [monitor]),
-    receive
-    {'DOWN', MonRef, process, _CompactPid, normal} ->
-        ok;
-    {'DOWN', MonRef, process, _CompactPid, Reason} ->
-        etap:bail("Error compacting view group: " ++ couch_util:to_list(Reason))
-    after 120000 ->
-        etap:bail("Timeout waiting for view group compaction")
-    end.
-
-
-db_disk_size() ->
-    {ok, Db} = couch_db:open_int(test_db_name(), []),
-    {ok, Info} = couch_db:get_db_info(Db),
-    ok = couch_db:close(Db),
-    couch_util:get_value(disk_size, Info).
-
-
-view_disk_size() ->
-    {ok, Db} = couch_db:open_int(test_db_name(), []),
-    {ok, DDoc} = couch_db:open_doc(Db, ddoc_id(), [ejson_body]),
-    {ok, Info} = couch_mrview:get_info(Db, DDoc),
-    ok = couch_db:close(Db),
-    couch_util:get_value(disk_size, Info).
-
-
-delete_db() ->
-    ok = couch_server:delete(
-        test_db_name(), [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}]).

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e656e8d7/test/etap/Makefile.am
----------------------------------------------------------------------
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index 3673ef9..d950e46 100644
--- a/test/etap/Makefile.am
+++ b/test/etap/Makefile.am
@@ -36,7 +36,6 @@ fixture_files = \
     fixtures/test.couch
 
 tap_files = \
-    076-file-compression.t \
     077-couch-db-fast-db-delete-create.t \
     080-config-get-set.t \
     081-config-override.1.ini \


Mime
View raw message