You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2014/08/28 19:35:24 UTC

[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 <kx...@apache.org>
Authored: Tue Jun 10 23:55:32 2014 +0400
Committer: Russell Branca <ch...@apache.org>
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