Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F042D110DC for ; Fri, 5 Sep 2014 21:10:28 +0000 (UTC) Received: (qmail 97959 invoked by uid 500); 5 Sep 2014 21:10:28 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 97773 invoked by uid 500); 5 Sep 2014 21:10:28 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 97683 invoked by uid 99); 5 Sep 2014 21:10:28 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Sep 2014 21:10:28 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 84FC1A0B2E5; Fri, 5 Sep 2014 21:10:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rnewson@apache.org To: commits@couchdb.apache.org Date: Fri, 05 Sep 2014 21:10:29 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [02/50] [abbrv] couch commit: updated refs/heads/master to 55e98c4 Port 150-invalid-view-seq.t etap test suite to eunit Merged into couchdb_views_tests suite. Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/b06bee7f Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/b06bee7f Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/b06bee7f Branch: refs/heads/master Commit: b06bee7f2d0c3d017f30d11158ba916901dfab2c Parents: b42477a Author: Alexander Shorin Authored: Tue Jun 3 08:49:32 2014 +0400 Committer: Russell Branca Committed: Thu Sep 4 14:37:31 2014 -0700 ---------------------------------------------------------------------- test/couchdb/couchdb_views_tests.erl | 102 ++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b06bee7f/test/couchdb/couchdb_views_tests.erl ---------------------------------------------------------------------- diff --git a/test/couchdb/couchdb_views_tests.erl b/test/couchdb/couchdb_views_tests.erl index e44cef6..d10b567 100644 --- a/test/couchdb/couchdb_views_tests.erl +++ b/test/couchdb/couchdb_views_tests.erl @@ -36,13 +36,22 @@ setup() -> DbName = ?tempdb(), {ok, _} = couch_db:create(DbName, [?ADMIN_USER]), FooRev = create_design_doc(DbName, <<"_design/foo">>, <<"bar">>), - ok = query_view(DbName, "foo", "bar"), + query_view(DbName, "foo", "bar"), BooRev = create_design_doc(DbName, <<"_design/boo">>, <<"baz">>), - ok = query_view(DbName, "boo", "baz"), + query_view(DbName, "boo", "baz"), {DbName, {FooRev, BooRev}}. +setup_with_docs() -> + DbName = ?tempdb(), + {ok, _} = couch_db:create(DbName, [?ADMIN_USER]), + create_docs(DbName), + create_design_doc(DbName, <<"_design/foo">>, <<"bar">>), + DbName. + teardown({DbName, _}) -> - ok = couch_server:delete(DbName, []), + teardown(DbName); +teardown(DbName) when is_binary(DbName) -> + ok = couch_server:delete(DbName, [?ADMIN_USER]), ok. @@ -64,6 +73,36 @@ view_indexes_cleanup_test_() -> } }. +should_not_remember_docs_in_index_after_backup_restore_test() -> + %% COUCHDB-640 + start(), + DbName = setup_with_docs(), + + ok = backup_db_file(DbName), + create_doc(DbName), + + Body0 = query_view(DbName, "foo", "bar"), + ViewJson0 = ejson:decode(Body0), + Rows0 = couch_util:get_nested_json_value(ViewJson0, [<<"rows">>]), + ?assert(has_doc("doc1", Rows0)), + ?assert(has_doc("doc2", Rows0)), + ?assert(has_doc("doc3", Rows0)), + ?assert(has_doc("doc666", Rows0)), + + restore_backup_db_file(DbName), + + Body1 = query_view(DbName, "foo", "bar"), + ViewJson1 = ejson:decode(Body1), + Rows1 = couch_util:get_nested_json_value(ViewJson1, [<<"rows">>]), + ?assert(has_doc("doc1", Rows1)), + ?assert(has_doc("doc2", Rows1)), + ?assert(has_doc("doc3", Rows1)), + ?assertNot(has_doc("doc666", Rows1)), + + teardown(DbName), + stop(whereis(couch_server_sup)). + + should_have_two_indexes_alive_before_deletion({DbName, _}) -> view_cleanup(DbName), ?_assertEqual(2, count_index_files(DbName)). @@ -80,6 +119,38 @@ should_cleanup_all_index_files({DbName, {FooRev, BooRev}})-> ?_assertEqual(0, count_index_files(DbName)). +create_doc(DbName) -> + {ok, Db} = couch_db:open(DbName, [?ADMIN_USER]), + Doc666 = couch_doc:from_json_obj({[ + {<<"_id">>, <<"doc666">>}, + {<<"value">>, 999} + + ]}), + {ok, _} = couch_db:update_docs(Db, [Doc666]), + couch_db:ensure_full_commit(Db), + couch_db:close(Db). + +create_docs(DbName) -> + {ok, Db} = couch_db:open(DbName, [?ADMIN_USER]), + Doc1 = couch_doc:from_json_obj({[ + {<<"_id">>, <<"doc1">>}, + {<<"value">>, 1} + + ]}), + Doc2 = couch_doc:from_json_obj({[ + {<<"_id">>, <<"doc2">>}, + {<<"value">>, 2} + + ]}), + Doc3 = couch_doc:from_json_obj({[ + {<<"_id">>, <<"doc3">>}, + {<<"value">>, 3} + + ]}), + {ok, _} = couch_db:update_docs(Db, [Doc1, Doc2, Doc3]), + couch_db:ensure_full_commit(Db), + couch_db:close(Db). + create_design_doc(DbName, DDName, ViewName) -> {ok, Db} = couch_db:open(DbName, [?ADMIN_USER]), DDoc = couch_doc:from_json_obj({[ @@ -109,13 +180,13 @@ delete_design_doc(DbName, DDName, Rev) -> db_url(DbName) -> 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(DbName). + "http://" ++ Addr ++ ":" ++ Port ++ "/" ++ ?b2l(DbName). query_view(DbName, DDoc, View) -> - {ok, Code, _Headers, _Body} = test_request:get( + {ok, Code, _Headers, Body} = test_request:get( db_url(DbName) ++ "/_design/" ++ DDoc ++ "/_view/" ++ View), ?assertEqual(200, Code), - ok. + Body. view_cleanup(DbName) -> {ok, Db} = couch_db:open(DbName, [?ADMIN_USER]), @@ -127,3 +198,22 @@ count_index_files(DbName) -> RootDir = couch_config:get("couchdb", "view_index_dir"), length(filelib:wildcard(RootDir ++ "/." ++ binary_to_list(DbName) ++ "_design"++"/mrview/*")). + +has_doc(DocId1, Rows) -> + DocId = iolist_to_binary(DocId1), + lists:any(fun({R}) -> lists:member({<<"id">>, DocId}, R) end, Rows). + +backup_db_file(DbName) -> + DbDir = couch_config:get("couchdb", "database_dir"), + DbFile = filename:join([DbDir, ?b2l(DbName) ++ ".couch"]), + {ok, _} = file:copy(DbFile, DbFile ++ ".backup"), + ok. + +restore_backup_db_file(DbName) -> + DbDir = couch_config:get("couchdb", "database_dir"), + stop(whereis(couch_server_sup)), + DbFile = filename:join([DbDir, ?b2l(DbName) ++ ".couch"]), + ok = file:delete(DbFile), + ok = file:rename(DbFile ++ ".backup", DbFile), + start(), + ok.