From 218f61ca2844ef4326157c6db958574c29c1ea40 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Wed, 8 Jun 2011 18:57:43 +0000 Subject: backport r1133312 from trunk _view_cleanup with no _design docs - COUCHDB-1136 git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1133510 13f79535-47bb-0310-9956-ffa450edef68 --- test/etap/072-cleanup.t | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100755 test/etap/072-cleanup.t (limited to 'test') diff --git a/test/etap/072-cleanup.t b/test/etap/072-cleanup.t new file mode 100755 index 00000000..61790bc6 --- /dev/null +++ b/test/etap/072-cleanup.t @@ -0,0 +1,130 @@ +#!/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. + +-define(TEST_DB, <<"etap-test-db">>). + +-record(user_ctx, { + name = null, + roles = [], + handler +}). + +-define(ADMIN_USER, #user_ctx{roles=[<<"_admin">>]}). + +main(_) -> + test_util:init_code_path(), + + etap:plan(7), + try test() of + ok -> + etap:end_tests() + catch + Other -> + etap:diag(io_lib:format("Test died abnormally: ~p", [Other])), + timer:sleep(1000), + etap:bail(Other) + end, + ok. + +test() -> + + {ok, _} = couch_server_sup:start_link(test_util:config_files()), + ok = application:start(inets), + couch_server:delete(?TEST_DB, []), + timer:sleep(1000), + + couch_db:create(?TEST_DB, []), + + {ok, AllDbs} = couch_server:all_databases(), + etap:ok(lists:member(?TEST_DB, AllDbs), "Database was created."), + + FooRev = create_design_doc(<<"_design/foo">>, <<"bar">>), + query_view("foo", "bar"), + + BoozRev = create_design_doc(<<"_design/booz">>, <<"baz">>), + query_view("booz", "baz"), + + {ok, Db} = couch_db:open(?TEST_DB, [{user_ctx, ?ADMIN_USER}]), + view_cleanup(), + etap:is(count_index_files(), 2, + "Two index files before any deletions."), + + delete_design_doc(<<"_design/foo">>, FooRev), + view_cleanup(), + etap:is(count_index_files(), 1, + "One index file after first deletion and cleanup."), + + delete_design_doc(<<"_design/booz">>, BoozRev), + view_cleanup(), + etap:is(count_index_files(), 0, + "No index files after second deletion and cleanup."), + + couch_server:delete(?TEST_DB, []), + {ok, AllDbs2} = couch_server:all_databases(), + etap:ok(not lists:member(?TEST_DB, AllDbs2), + "Database was deleted."), + ok. + +create_design_doc(DDName, ViewName) -> + {ok, Db} = couch_db:open(?TEST_DB, [{user_ctx, ?ADMIN_USER}]), + DDoc = couch_doc:from_json_obj({[ + {<<"_id">>, DDName}, + {<<"language">>, <<"javascript">>}, + {<<"views">>, {[ + {ViewName, {[ + {<<"map">>, <<"function(doc) { emit(doc.value, 1); }">>} + ]}} + ]}} + ]}), + {ok, Rev} = couch_db:update_doc(Db, DDoc, []), + couch_db:ensure_full_commit(Db), + couch_db:close(Db), + Rev. + +delete_design_doc(DDName, Rev) -> + {ok, Db} = couch_db:open(?TEST_DB, [{user_ctx, ?ADMIN_USER}]), + DDoc = couch_doc:from_json_obj({[ + {<<"_id">>, DDName}, + {<<"_rev">>, couch_doc:rev_to_str(Rev)}, + {<<"_deleted">>, true} + ]}), + {ok, _} = couch_db:update_doc(Db, DDoc, [Rev]), + couch_db:close(Db). + +db_url() -> + Addr = couch_config:get("httpd", "bind_address", "127.0.0.1"), + Port = integer_to_list(mochiweb_socket_server:get(couch_httpd, port)), + "http://" ++ Addr ++ ":" ++ Port ++ "/" ++ + binary_to_list(?TEST_DB). + +query_view(DDoc, View) -> + {ok, {{_, Code, _}, _Headers, _Body}} = http:request( + get, + {db_url() ++ "/_design/" ++ DDoc ++ "/_view/" ++ View, []}, + [], + [{sync, true}]), + etap:is(Code, 200, "Built view index for " ++ DDoc ++ "."), + ok. + +view_cleanup() -> + {ok, Db} = couch_db:open(?TEST_DB, [{user_ctx, ?ADMIN_USER}]), + couch_view:cleanup_index_files(Db), + couch_db:close(Db). + +count_index_files() -> + % call server to fetch the index files + RootDir = couch_config:get("couchdb", "view_index_dir"), + length(filelib:wildcard(RootDir ++ "/." ++ + binary_to_list(?TEST_DB) ++ "_design"++"/*")). -- cgit v1.2.3 From a217146276375f6247b027305723b0734ab280f5 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Sat, 11 Jun 2011 19:14:16 +0000 Subject: Backport r113686 from trunk add 072-cleanup.t to etap Makefile.am git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1134729 13f79535-47bb-0310-9956-ffa450edef68 --- test/etap/Makefile.am | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am index ce52d430..ecbc3a93 100644 --- a/test/etap/Makefile.am +++ b/test/etap/Makefile.am @@ -53,6 +53,7 @@ EXTRA_DIST = \ 064-kt-counting.t \ 065-kt-stemming.t \ 070-couch-db.t \ + 072-cleanup.t \ 080-config-get-set.t \ 081-config-override.1.ini \ 081-config-override.2.ini \ -- cgit v1.2.3 From 0827cb483ef4cf74123313e8f2d0d2bd5ce8e46b Mon Sep 17 00:00:00 2001 From: Robert Newson Date: Mon, 20 Jun 2011 21:22:02 +0000 Subject: Fix spurious declarations of new merge conflicts This patch also adds extra tests of the key tree merging logic as well as edoc-formatted documentation for the module and a few of the merge functions. Closes COUCHDB-902. Thanks Paul Davis, Bob Dionne, Klaus Trainer. backported from trunk@1065471 Conflicts: src/couchdb/couch_key_tree.erl git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1137789 13f79535-47bb-0310-9956-ffa450edef68 --- test/etap/060-kt-merging.t | 95 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 17 deletions(-) (limited to 'test') diff --git a/test/etap/060-kt-merging.t b/test/etap/060-kt-merging.t index 0e481a52..efbdbf69 100755 --- a/test/etap/060-kt-merging.t +++ b/test/etap/060-kt-merging.t @@ -15,7 +15,7 @@ main(_) -> test_util:init_code_path(), - etap:plan(12), + etap:plan(16), case (catch test()) of ok -> etap:end_tests(); @@ -26,25 +26,21 @@ main(_) -> ok. test() -> - One = {0, {"1","foo",[]}}, - TwoSibs = [{0, {"1","foo",[]}}, - {0, {"2","foo",[]}}], - OneChild = {0, {"1","foo",[{"1a", "bar", []}]}}, - TwoChild = {0, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}]}}, - TwoChildSibs = {0, {"1","foo", [{"1a", "bar", []}, - {"1b", "bar", []}]}}, - TwoChildSibs2 = {0, {"1","foo", [{"1a", "bar", []}, - {"1b", "bar", [{"1bb", "boo", []}]}]}}, - Stemmed1b = {1, {"1a", "bar", []}}, - Stemmed1a = {1, {"1a", "bar", [{"1aa", "bar", []}]}}, - Stemmed1aa = {2, {"1aa", "bar", []}}, - Stemmed1bb = {2, {"1bb", "boo", []}}, + One = {1, {"1","foo",[]}}, etap:is( {[One], no_conflicts}, couch_key_tree:merge([], One, 10), "The empty tree is the identity for merge." ), + etap:is( + {[One], no_conflicts}, + couch_key_tree:merge([One], One, 10), + "Merging is reflexive." + ), + + TwoSibs = [{1, {"1","foo",[]}}, + {1, {"2","foo",[]}}], etap:is( {TwoSibs, no_conflicts}, @@ -52,41 +48,75 @@ test() -> "Merging a prefix of a tree with the tree yields the tree." ), + Three = {1, {"3","foo",[]}}, + ThreeSibs = [{1, {"1","foo",[]}}, + {1, {"2","foo",[]}}, + {1, {"3","foo",[]}}], + etap:is( - {[One], no_conflicts}, - couch_key_tree:merge([One], One, 10), - "Merging is reflexive." + {ThreeSibs, conflicts}, + couch_key_tree:merge(TwoSibs, Three, 10), + "Merging a third unrelated branch leads to a conflict." ), + + TwoChild = {1, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}]}}, + etap:is( {[TwoChild], no_conflicts}, couch_key_tree:merge([TwoChild], TwoChild, 10), "Merging two children is still reflexive." ), + TwoChildSibs = {1, {"1","foo", [{"1a", "bar", []}, + {"1b", "bar", []}]}}, etap:is( {[TwoChildSibs], no_conflicts}, couch_key_tree:merge([TwoChildSibs], TwoChildSibs, 10), "Merging a tree to itself is itself."), + TwoChildPlusSibs = + {1, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}, + {"1b", "bar", []}]}}, + + etap:is( + {[TwoChildPlusSibs], no_conflicts}, + couch_key_tree:merge([TwoChild], TwoChildSibs, 10), + "Merging tree of uneven length at node 2."), + + Stemmed1b = {2, {"1a", "bar", []}}, etap:is( {[TwoChildSibs], no_conflicts}, couch_key_tree:merge([TwoChildSibs], Stemmed1b, 10), "Merging a tree with a stem." ), + TwoChildSibs2 = {1, {"1","foo", [{"1a", "bar", []}, + {"1b", "bar", [{"1bb", "boo", []}]}]}}, + Stemmed1bb = {3, {"1bb", "boo", []}}, etap:is( {[TwoChildSibs2], no_conflicts}, couch_key_tree:merge([TwoChildSibs2], Stemmed1bb, 10), "Merging a stem at a deeper level." ), + StemmedTwoChildSibs2 = [{2,{"1a", "bar", []}}, + {2,{"1b", "bar", [{"1bb", "boo", []}]}}], + + etap:is( + {StemmedTwoChildSibs2, no_conflicts}, + couch_key_tree:merge(StemmedTwoChildSibs2, Stemmed1bb, 10), + "Merging a stem at a deeper level against paths at deeper levels." + ), + + Stemmed1aa = {3, {"1aa", "bar", []}}, etap:is( {[TwoChild], no_conflicts}, couch_key_tree:merge([TwoChild], Stemmed1aa, 10), "Merging a single tree with a deeper stem." ), + Stemmed1a = {2, {"1a", "bar", [{"1aa", "bar", []}]}}, etap:is( {[TwoChild], no_conflicts}, couch_key_tree:merge([TwoChild], Stemmed1a, 10), @@ -99,6 +129,7 @@ test() -> "More merging." ), + OneChild = {1, {"1","foo",[{"1a", "bar", []}]}}, Expect1 = [OneChild, Stemmed1aa], etap:is( {Expect1, conflicts}, @@ -112,4 +143,34 @@ test() -> "Merge should have no conflicts." ), + %% this test is based on couch-902-test-case2.py + %% foo has conflicts from replication at depth two + %% foo3 is the current value + Foo = {1, {"foo", + "val1", + [{"foo2","val2",[]}, + {"foo3", "val3", []} + ]}}, + %% foo now has an attachment added, which leads to foo4 and val4 + %% off foo3 + Bar = {1, {"foo", + [], + [{"foo3", + [], + [{"foo4","val4",[]} + ]}]}}, + %% this is what the merge returns + %% note that it ignore the conflicting branch as there's no match + FooBar = {1, {"foo", + "val1", + [{"foo2","val2",[]}, + {"foo3", "val3", [{"foo4","val4",[]}]} + ]}}, + + etap:is( + {[FooBar], no_conflicts}, + couch_key_tree:merge([Foo],Bar,10), + "Merging trees with conflicts ought to behave." + ), + ok. -- cgit v1.2.3