From commits-return-33205-archive-asf-public=cust-asf.ponee.io@couchdb.apache.org Thu May 31 00:07:40 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7F1E418067C for ; Thu, 31 May 2018 00:07:39 +0200 (CEST) Received: (qmail 84266 invoked by uid 500); 30 May 2018 22:07:38 -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 84248 invoked by uid 99); 30 May 2018 22:07:38 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 May 2018 22:07:38 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id CCF3C82A06; Wed, 30 May 2018 22:07:37 +0000 (UTC) Date: Wed, 30 May 2018 22:07:38 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb] 03/08: [05/N] Clustered Purge: Add upgrade tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: davisp@apache.org In-Reply-To: <152771805546.12309.11775599856859235454@gitbox.apache.org> References: <152771805546.12309.11775599856859235454@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb X-Git-Refname: refs/heads/COUCHDB-3326-clustered-purge-pr5-implementation X-Git-Reftype: branch X-Git-Rev: 38d584e39d8cff671aeae24475f443b076b44eb8 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20180530220737.CCF3C82A06@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. davisp pushed a commit to branch COUCHDB-3326-clustered-purge-pr5-implementation in repository https://gitbox.apache.org/repos/asf/couchdb.git commit 38d584e39d8cff671aeae24475f443b076b44eb8 Author: Paul J. Davis AuthorDate: Wed May 30 17:01:01 2018 -0500 [05/N] Clustered Purge: Add upgrade tests These test that we can successfully upgrade old databases that have various configurations of purge requests in the legacy format. COUCHDB-3326 Co-authored-by: Mayya Sharipova Co-authored-by: jiangphcn --- src/couch/test/couch_bt_engine_upgrade_tests.erl | 178 +++++++++++++++++++++ src/couch/test/fixtures/db_with_1_purge_req.couch | Bin 0 -> 12470 bytes src/couch/test/fixtures/db_with_2_purge_req.couch | Bin 0 -> 16566 bytes src/couch/test/fixtures/db_without_purge_req.couch | Bin 0 -> 61644 bytes 4 files changed, 178 insertions(+) diff --git a/src/couch/test/couch_bt_engine_upgrade_tests.erl b/src/couch/test/couch_bt_engine_upgrade_tests.erl new file mode 100644 index 0000000..d3f530f --- /dev/null +++ b/src/couch/test/couch_bt_engine_upgrade_tests.erl @@ -0,0 +1,178 @@ +% 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(couch_bt_engine_upgrade_tests). + +-include_lib("couch/include/couch_eunit.hrl"). +-include_lib("couch/include/couch_db.hrl"). + + +setup() -> + Ctx = test_util:start_couch(), + DbDir = config:get("couchdb", "database_dir"), + DbFileNames = [ + "db_without_purge_req.couch", + "db_with_1_purge_req.couch", + "db_with_2_purge_req.couch" + ], + NewPaths = lists:map(fun(DbFileName) -> + OldDbFilePath = filename:join([?FIXTURESDIR, DbFileName]), + NewDbFilePath = filename:join([DbDir, DbFileName]), + ok = filelib:ensure_dir(NewDbFilePath), + file:delete(NewDbFilePath), + {ok, _} = file:copy(OldDbFilePath, NewDbFilePath), + NewDbFilePath + end, DbFileNames), + {Ctx, NewPaths}. + + +teardown({Ctx, Paths}) -> + lists:foreach(fun(Path) -> + %file:delete(Path) + ok + end, Paths), + test_util:stop_couch(Ctx). + + +upgrade_test_() -> + { + "Couch Bt Engine Upgrade tests", + { + setup, + fun setup/0, + fun teardown/1, + [ + t_upgrade_without_purge_req(), + t_upgrade_with_1_purge_req(), + t_upgrade_with_N_purge_req() + ] + } + }. + + +t_upgrade_without_purge_req() -> + ?_test(begin + % There are three documents in the fixture + % db with zero purge entries + DbName = <<"db_without_purge_req">>, + + {ok, UpgradedPurged} = couch_util:with_db(DbName, fun(Db) -> + ?assertEqual({ok, 0}, couch_db:get_purge_seq(Db)), + couch_db:fold_purge_infos(Db, 0, fun fold_fun/2, []) + end), + ?assertEqual([], UpgradedPurged), + + {ok, Rev} = save_doc(DbName, {[{<<"_id">>, <<"doc4">>}, {<<"v">>, 1}]}), + {ok, _} = save_doc(DbName, {[{<<"_id">>, <<"doc5">>}, {<<"v">>, 2}]}), + + couch_util:with_db(DbName, fun(Db) -> + ?assertEqual({ok, 5}, couch_db:get_doc_count(Db)), + ?assertEqual({ok, 0}, couch_db:get_purge_seq(Db)) + end), + + PurgeReqs = [ + {couch_uuids:random(), <<"doc4">>, [Rev]} + ], + + {ok, [{ok, PRevs}]} = couch_util:with_db(DbName, fun(Db) -> + couch_db:purge_docs(Db, PurgeReqs) + end), + ?assertEqual(PRevs, [Rev]), + + couch_util:with_db(DbName, fun(Db) -> + ?assertEqual({ok, 4}, couch_db:get_doc_count(Db)), + ?assertEqual({ok, 1}, couch_db:get_purge_seq(Db)) + end) + end). + + +t_upgrade_with_1_purge_req() -> + ?_test(begin + % There are two documents in the fixture database + % with a single purge entry + DbName = <<"db_with_1_purge_req">>, + + {ok, UpgradedPurged} = couch_util:with_db(DbName, fun(Db) -> + ?assertEqual({ok, 1}, couch_db:get_purge_seq(Db)), + couch_db:fold_purge_infos(Db, 0, fun fold_fun/2, []) + end), + ?assertEqual([{1, <<"doc1">>}], UpgradedPurged), + + {ok, Rev} = save_doc(DbName, {[{<<"_id">>, <<"doc4">>}, {<<"v">>, 1}]}), + {ok, _} = save_doc(DbName, {[{<<"_id">>, <<"doc5">>}, {<<"v">>, 2}]}), + + couch_util:with_db(DbName, fun(Db) -> + ?assertEqual({ok, 4}, couch_db:get_doc_count(Db)), + ?assertEqual({ok, 1}, couch_db:get_purge_seq(Db)) + end), + + PurgeReqs = [ + {couch_uuids:random(), <<"doc4">>, [Rev]} + ], + + {ok, [{ok, PRevs}]} = couch_util:with_db(DbName, fun(Db) -> + couch_db:purge_docs(Db, PurgeReqs) + end), + ?assertEqual(PRevs, [Rev]), + + couch_util:with_db(DbName, fun(Db) -> + ?assertEqual({ok, 3}, couch_db:get_doc_count(Db)), + ?assertEqual({ok, 2}, couch_db:get_purge_seq(Db)) + end) + end). + + +t_upgrade_with_N_purge_req() -> + ?_test(begin + % There is one document in the fixture database + % with two docs that have been purged + DbName = <<"db_with_2_purge_req">>, + + {ok, UpgradedPurged} = couch_util:with_db(DbName, fun(Db) -> + ?assertEqual({ok, 2}, couch_db:get_purge_seq(Db)), + couch_db:fold_purge_infos(Db, 1, fun fold_fun/2, []) + end), + ?assertEqual([{2, <<"doc2">>}], UpgradedPurged), + + {ok, Rev} = save_doc(DbName, {[{<<"_id">>, <<"doc4">>}, {<<"v">>, 1}]}), + {ok, _} = save_doc(DbName, {[{<<"_id">>, <<"doc5">>}, {<<"v">>, 2}]}), + + couch_util:with_db(DbName, fun(Db) -> + ?assertEqual({ok, 3}, couch_db:get_doc_count(Db)), + ?assertEqual({ok, 2}, couch_db:get_purge_seq(Db)) + end), + + PurgeReqs = [ + {couch_uuids:random(), <<"doc4">>, [Rev]} + ], + + {ok, [{ok, PRevs}]} = couch_util:with_db(DbName, fun(Db) -> + couch_db:purge_docs(Db, PurgeReqs) + end), + ?assertEqual(PRevs, [Rev]), + + couch_util:with_db(DbName, fun(Db) -> + ?assertEqual({ok, 2}, couch_db:get_doc_count(Db)), + ?assertEqual({ok, 3}, couch_db:get_purge_seq(Db)) + end) + end). + + +save_doc(DbName, Json) -> + Doc = couch_doc:from_json_obj(Json), + couch_util:with_db(DbName, fun(Db) -> + couch_db:update_doc(Db, Doc, []) + end). + + +fold_fun({PSeq, _UUID, Id, _Revs}, Acc) -> + {ok, [{PSeq, Id} | Acc]}. diff --git a/src/couch/test/fixtures/db_with_1_purge_req.couch b/src/couch/test/fixtures/db_with_1_purge_req.couch new file mode 100644 index 0000000..b0d39c9 Binary files /dev/null and b/src/couch/test/fixtures/db_with_1_purge_req.couch differ diff --git a/src/couch/test/fixtures/db_with_2_purge_req.couch b/src/couch/test/fixtures/db_with_2_purge_req.couch new file mode 100644 index 0000000..ee4e11b Binary files /dev/null and b/src/couch/test/fixtures/db_with_2_purge_req.couch differ diff --git a/src/couch/test/fixtures/db_without_purge_req.couch b/src/couch/test/fixtures/db_without_purge_req.couch new file mode 100644 index 0000000..814feb8 Binary files /dev/null and b/src/couch/test/fixtures/db_without_purge_req.couch differ -- To stop receiving notification emails like this one, please contact davisp@apache.org.