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 BF16F11734 for ; Thu, 28 Aug 2014 17:34:59 +0000 (UTC) Received: (qmail 37903 invoked by uid 500); 28 Aug 2014 17:34:57 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 37763 invoked by uid 500); 28 Aug 2014 17:34:57 -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 36784 invoked by uid 99); 28 Aug 2014 17:34:57 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Aug 2014 17:34:57 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 1C56AA04B8A; Thu, 28 Aug 2014 17:34:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chewbranca@apache.org To: commits@couchdb.apache.org Date: Thu, 28 Aug 2014 17:35:24 -0000 Message-Id: <808d0f424bd649bb94807787c1b47a6c@git.apache.org> In-Reply-To: <3b2f70a7334d4c93af17616b11bbac06@git.apache.org> References: <3b2f70a7334d4c93af17616b11bbac06@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [29/50] [abbrv] couch commit: updated refs/heads/1963-eunit-bigcouch to 3ecd0a0 Port 250-upgrade-legacy-view-files.t etap test suite to eunit Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/ff2dc10c Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/ff2dc10c Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/ff2dc10c Branch: refs/heads/1963-eunit-bigcouch Commit: ff2dc10c76bae22760849017129f98b4c8c5626a Parents: 6f7a600 Author: Alexander Shorin Authored: Tue Jun 10 23:55:32 2014 +0400 Committer: Russell Branca Committed: Thu Aug 28 10:34:07 2014 -0700 ---------------------------------------------------------------------- test/couchdb/couchdb_views_tests.erl | 69 +++++++++++++++++++ .../3b835456c235b1827e012e25666152f3.view | Bin 0 -> 4192 bytes test/couchdb/fixtures/test.couch | Bin 0 -> 16482 bytes 3 files changed, 69 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ff2dc10c/test/couchdb/couchdb_views_tests.erl ---------------------------------------------------------------------- diff --git a/test/couchdb/couchdb_views_tests.erl b/test/couchdb/couchdb_views_tests.erl index 57d5a14..6d81f32 100644 --- a/test/couchdb/couchdb_views_tests.erl +++ b/test/couchdb/couchdb_views_tests.erl @@ -14,6 +14,7 @@ -include("couch_eunit.hrl"). -include_lib("couchdb/couch_db.hrl"). +-include_lib("couch_mrview/include/couch_mrview.hrl"). -define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}). -define(DELAY, 100). @@ -131,6 +132,68 @@ should_not_remember_docs_in_index_after_backup_restore_test() -> stop(whereis(couch_server_sup)). +should_upgrade_legacy_view_files_test() -> + start(), + + ok = couch_config:set("query_server_config", "commit_freq", "0", false), + + DbName = <<"test">>, + DbFileName = "test.couch", + DbFilePath = filename:join([?FIXTURESDIR, DbFileName]), + OldViewName = "3b835456c235b1827e012e25666152f3.view", + FixtureViewFilePath = filename:join([?FIXTURESDIR, OldViewName]), + NewViewName = "a1c5929f912aca32f13446122cc6ce50.view", + + DbDir = couch_config:get("couchdb", "database_dir"), + ViewDir = couch_config:get("couchdb", "view_index_dir"), + OldViewFilePath = filename:join([ViewDir, ".test_design", OldViewName]), + NewViewFilePath = filename:join([ViewDir, ".test_design", "mrview", + NewViewName]), + + % cleanup + Files = [ + filename:join([DbDir, DbFileName]), + OldViewFilePath, + NewViewFilePath + ], + lists:foreach(fun(File) -> file:delete(File) end, Files), + + % copy old db file into db dir + {ok, _} = file:copy(DbFilePath, filename:join([DbDir, DbFileName])), + + % copy old view file into view dir + ok = filelib:ensure_dir(filename:join([ViewDir, ".test_design"])), + {ok, _} = file:copy(FixtureViewFilePath, OldViewFilePath), + + % ensure old header + OldHeader = read_header(OldViewFilePath), + ?assertMatch(#index_header{}, OldHeader), + + % query view for expected results + Rows0 = query_view(DbName, "test", "test"), + ?assertEqual(2, length(Rows0)), + + % ensure old file gone + ?assertNot(filelib:is_regular(OldViewFilePath)), + + % add doc to trigger update + DocUrl = db_url(DbName) ++ "/boo", + {ok, _, _, _} = test_request:put( + DocUrl, [{"Content-Type", "application/json"}], <<"{\"a\":3}">>), + + % query view for expected results + Rows1 = query_view(DbName, "test", "test"), + ?assertEqual(3, length(Rows1)), + + % ensure new header + timer:sleep(2000), % have to wait for awhile to upgrade the index + NewHeader = read_header(NewViewFilePath), + ?assertMatch(#mrheader{}, NewHeader), + + teardown(DbName), + stop(whereis(couch_server_sup)). + + should_have_two_indexes_alive_before_deletion({DbName, _}) -> view_cleanup(DbName), ?_assertEqual(2, count_index_files(DbName)). @@ -598,3 +661,9 @@ writer_loop_2(DbName, Parent, Error) -> Parent ! {ok, Ref}, writer_loop(DbName, Parent) end. + +read_header(File) -> + {ok, Fd} = couch_file:open(File), + {ok, {_Sig, Header}} = couch_file:read_header(Fd), + couch_file:close(Fd), + Header. http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ff2dc10c/test/couchdb/fixtures/3b835456c235b1827e012e25666152f3.view ---------------------------------------------------------------------- diff --git a/test/couchdb/fixtures/3b835456c235b1827e012e25666152f3.view b/test/couchdb/fixtures/3b835456c235b1827e012e25666152f3.view new file mode 100644 index 0000000..9c67648 Binary files /dev/null and b/test/couchdb/fixtures/3b835456c235b1827e012e25666152f3.view differ http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ff2dc10c/test/couchdb/fixtures/test.couch ---------------------------------------------------------------------- diff --git a/test/couchdb/fixtures/test.couch b/test/couchdb/fixtures/test.couch new file mode 100644 index 0000000..32c79af Binary files /dev/null and b/test/couchdb/fixtures/test.couch differ