You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2015/12/03 00:02:28 UTC

[28/50] couchdb commit: updated refs/heads/1.x.x to 921006f

Port 250-upgrade-legacy-view-files.t etap test suite to eunit


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/641c3654
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/641c3654
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/641c3654

Branch: refs/heads/1.x.x
Commit: 641c3654fbd39125cd24ad75f89504803deecf31
Parents: 63e5e68
Author: Alexander Shorin <kx...@apache.org>
Authored: Tue Jun 10 23:55:32 2014 +0400
Committer: Alexander Shorin <kx...@apache.org>
Committed: Thu Dec 3 00:52:02 2015 +0300

----------------------------------------------------------------------
 license.skip                                    |   2 +
 test/couchdb/Makefile.am                        |   4 +-
 test/couchdb/couchdb_views_tests.erl            |  69 ++++++++
 .../3b835456c235b1827e012e25666152f3.view       | Bin 0 -> 4192 bytes
 test/couchdb/fixtures/test.couch                | Bin 0 -> 16482 bytes
 test/etap/250-upgrade-legacy-view-files.t       | 168 -------------------
 test/etap/Makefile.am                           |  11 +-
 .../3b835456c235b1827e012e25666152f3.view       | Bin 4192 -> 0 bytes
 test/etap/fixtures/test.couch                   | Bin 16482 -> 0 bytes
 9 files changed, 75 insertions(+), 179 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/641c3654/license.skip
----------------------------------------------------------------------
diff --git a/license.skip b/license.skip
index fe807b2..2d46c85 100644
--- a/license.skip
+++ b/license.skip
@@ -167,8 +167,10 @@
 ^test/couchdb/Makefile
 ^test/couchdb/Makefile.in
 ^test/couchdb/fixtures/logo.png
+^test/couchdb/fixtures/3b835456c235b1827e012e25666152f3.view
 ^test/couchdb/fixtures/Makefile
 ^test/couchdb/fixtures/Makefile.in
+^test/couchdb/fixtures/test.couch
 ^test/couchdb/fixtures/.deps/test_cfg_register-test_cfg_register.Po
 ^test/couchdb/fixtures/test_cfg_register
 ^test/couchdb/fixtures/test_cfg_register.o

http://git-wip-us.apache.org/repos/asf/couchdb/blob/641c3654/test/couchdb/Makefile.am
----------------------------------------------------------------------
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am
index 6859236..eaac42f 100644
--- a/test/couchdb/Makefile.am
+++ b/test/couchdb/Makefile.am
@@ -68,7 +68,9 @@ fixture_files = \
     fixtures/os_daemon_can_reboot.sh \
     fixtures/os_daemon_die_on_boot.sh \
     fixtures/os_daemon_die_quickly.sh \
-    fixtures/logo.png
+    fixtures/logo.png \
+    fixtures/3b835456c235b1827e012e25666152f3.view \
+    fixtures/test.couch
 
 EXTRA_DIST = \
     run.in \

http://git-wip-us.apache.org/repos/asf/couchdb/blob/641c3654/test/couchdb/couchdb_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couchdb_views_tests.erl b/test/couchdb/couchdb_views_tests.erl
index dc61576..6904f00 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)).
@@ -606,3 +669,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/blob/641c3654/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/blob/641c3654/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

http://git-wip-us.apache.org/repos/asf/couchdb/blob/641c3654/test/etap/250-upgrade-legacy-view-files.t
----------------------------------------------------------------------
diff --git a/test/etap/250-upgrade-legacy-view-files.t b/test/etap/250-upgrade-legacy-view-files.t
deleted file mode 100644
index e720b1c..0000000
--- a/test/etap/250-upgrade-legacy-view-files.t
+++ /dev/null
@@ -1,168 +0,0 @@
-#!/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.
-
-main(_) ->
-    test_util:init_code_path(),
-
-    etap:plan(8),
-    case (catch test()) of
-        ok ->
-            etap:end_tests();
-        Other ->
-            etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
-            etap:bail(Other)
-    end,
-    ok.
-
-
-test() ->
-    couch_server_sup:start_link(test_util:config_files()),
-
-    % commit sofort
-    ok = couch_config:set("query_server_config", "commit_freq", "0"),
-
-    test_upgrade(),
-
-    couch_server_sup:stop(),
-    ok.
-
-fixture_path() ->
-    test_util:source_file("test/etap/fixtures").
-
-old_db() ->
-    fixture_path() ++ "/" ++ old_db_name().
-
-old_db_name() ->
-    "test.couch".
-
-old_view() ->
-    fixture_path() ++ "/" ++ old_view_name().
-
-old_view_name() ->
-    "3b835456c235b1827e012e25666152f3.view".
-
-new_view_name() ->
-    "a1c5929f912aca32f13446122cc6ce50.view".
-
-couch_url() ->
-    "http://" ++ addr() ++ ":" ++ port().
-
-addr() ->
-    couch_config:get("httpd", "bind_address", "127.0.0.1").
-
-port() ->
-    integer_to_list(mochiweb_socket_server:get(couch_httpd, port)).
-
-
-% <= 1.2.x
--record(index_header,
-    {seq=0,
-    purge_seq=0,
-    id_btree_state=nil,
-    view_states=nil
-    }).
-
-% >= 1.3.x
--record(mrheader, {
-    seq=0,
-    purge_seq=0,
-    id_btree_state=nil,
-    view_states=nil
-}).
-
-ensure_header(File, MatchFun, Msg) ->
-    {ok, Fd} = couch_file:open(File),
-    {ok, {_Sig, Header}} = couch_file:read_header(Fd),
-    couch_file:close(Fd),
-    etap:fun_is(MatchFun, Header, "ensure " ++ Msg ++ " header for file: " ++ File).
-
-file_exists(File) ->
-    % open without creating
-    case file:open(File, [read, raw]) of
-    {ok, Fd_Read} ->
-        file:close(Fd_Read),
-        true;
-    _Error ->
-        false
-    end.
-
-cleanup() ->
-    DbDir = couch_config:get("couchdb", "database_dir"),
-    Files = [
-        DbDir ++ "/test.couch",
-        DbDir ++ "/.test_design/" ++ old_view_name(),
-        DbDir ++ "/.test_design/mrview/" ++ new_view_name()
-    ],
-    lists:foreach(fun(File) -> file:delete(File) end, Files),
-    etap:ok(true, "cleanup").
-
-test_upgrade() ->
-
-    cleanup(),
-
-    % copy old db file into db dir
-    DbDir = couch_config:get("couchdb", "database_dir"),
-    DbTarget = DbDir ++ "/" ++ old_db_name(),
-    filelib:ensure_dir(DbDir),
-    OldDbName = old_db(),
-    {ok, _} = file:copy(OldDbName, DbTarget),
-
-    % copy old view file into view dir
-    ViewDir = couch_config:get("couchdb", "view_index_dir"),
-    ViewTarget = ViewDir ++ "/.test_design/" ++ old_view_name(),
-    filelib:ensure_dir(ViewTarget),
-    OldViewName = old_view(),
-    {ok, _} = file:copy(OldViewName, ViewTarget),
-
-    % ensure old header
-    ensure_header(ViewTarget, fun(#index_header{}) -> true; (_) -> false end, "old"),
-
-    % query view
-    ViewUrl = couch_url() ++ "/test/_design/test/_view/test",
-    {ok, Code, _Headers, Body}  = test_util:request(ViewUrl, [], get),
-
-    % expect results
-    etap:is(Code, 200, "valid view result http status code"),
-    ExpectBody = <<"{\"total_rows\":2,\"offset\":0,\"rows\":[\r\n{\"id\":\"193f2f9c596ddc7ad326f7da470009ec\",\"key\":1,\"value\":null},\r\n{\"id\":\"193f2f9c596ddc7ad326f7da470012b6\",\"key\":2,\"value\":null}\r\n]}\n">>,
-    etap:is(Body, ExpectBody, "valid view result"),
-
-    % ensure old file gone.
-    etap:is(file_exists(ViewTarget), false, "ensure old file is gone"),
-
-    % ensure new header
-    NewViewFile = ViewDir ++ "/.test_design/mrview/" ++ new_view_name(),
-
-    % add doc(s)
-    test_util:request(
-        couch_url() ++ "/test/boo",
-        [{"Content-Type", "application/json"}],
-        put,
-        <<"{\"a\":3}">>),
-
-    % query again
-    {ok, Code2, _Headers2, Body2} = test_util:request(ViewUrl, [], get),
-
-    % expect results
-    etap:is(Code2, 200, "valid view result http status code"),
-    ExpectBody2 = <<"{\"total_rows\":3,\"offset\":0,\"rows\":[\r\n{\"id\":\"193f2f9c596ddc7ad326f7da470009ec\",\"key\":1,\"value\":null},\r\n{\"id\":\"193f2f9c596ddc7ad326f7da470012b6\",\"key\":2,\"value\":null},\r\n{\"id\":\"boo\",\"key\":3,\"value\":null}\r\n]}\n">>,
-    etap:is(Body2, ExpectBody2, "valid view result after doc add"),
-
-    % ensure no rebuild
-    % TBD no idea how to actually test this.
-
-    % ensure new header.
-    timer:sleep(2000),
-    ensure_header(NewViewFile, fun(#mrheader{}) -> true; (_) -> false end, "new"),
-
-    ok.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/641c3654/test/etap/Makefile.am
----------------------------------------------------------------------
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index 743f90f..4d6e19d 100644
--- a/test/etap/Makefile.am
+++ b/test/etap/Makefile.am
@@ -27,14 +27,5 @@ CLEANFILES = run *.beam
 
 DISTCLEANFILES = temp.*
 
-fixture_files = \
-    fixtures/3b835456c235b1827e012e25666152f3.view \
-    fixtures/test.couch
-
-tap_files = \
-    250-upgrade-legacy-view-files.t
-
 EXTRA_DIST = \
-    run.tpl \
-    $(fixture_files) \
-    $(tap_files)
+    run.tpl

http://git-wip-us.apache.org/repos/asf/couchdb/blob/641c3654/test/etap/fixtures/3b835456c235b1827e012e25666152f3.view
----------------------------------------------------------------------
diff --git a/test/etap/fixtures/3b835456c235b1827e012e25666152f3.view b/test/etap/fixtures/3b835456c235b1827e012e25666152f3.view
deleted file mode 100644
index 9c67648..0000000
Binary files a/test/etap/fixtures/3b835456c235b1827e012e25666152f3.view and /dev/null differ

http://git-wip-us.apache.org/repos/asf/couchdb/blob/641c3654/test/etap/fixtures/test.couch
----------------------------------------------------------------------
diff --git a/test/etap/fixtures/test.couch b/test/etap/fixtures/test.couch
deleted file mode 100644
index 32c79af..0000000
Binary files a/test/etap/fixtures/test.couch and /dev/null differ