Author: davisp
Date: Sun Sep 18 21:53:05 2011
New Revision: 1172380
URL: http://svn.apache.org/viewvc?rev=1172380&view=rev
Log:
Test that view reads can span compaction swaping.
Make sure that compaction doesn't remove a file out from under the
current view readers.
Added:
couchdb/trunk/src/couch_mrview/test/07-compact-swap.t
Modified:
couchdb/trunk/src/couch_mrview/Makefile.am
couchdb/trunk/src/couch_mrview/src/couch_mrview_test_util.erl
Modified: couchdb/trunk/src/couch_mrview/Makefile.am
URL:
http://svn.apache.org/viewvc/couchdb/trunk/src/couch_mrview/Makefile.am?rev=1172380&r1=1172379&r2=1172380&view=diff
==============================================================================
--- couchdb/trunk/src/couch_mrview/Makefile.am (original)
+++ couchdb/trunk/src/couch_mrview/Makefile.am Sun Sep 18 21:53:05 2011
@@ -38,7 +38,8 @@ test_files = \
test/03-red-views.t \
test/04-index-info.t \
test/05-collation.t \
- test/06-all-docs.t
+ test/06-all-docs.t \
+ test/07-compact-swap.t
compiled_files = \
ebin/couch_mrview.app \
Modified: couchdb/trunk/src/couch_mrview/src/couch_mrview_test_util.erl
URL:
http://svn.apache.org/viewvc/couchdb/trunk/src/couch_mrview/src/couch_mrview_test_util.erl?rev=1172380&r1=1172379&r2=1172380&view=diff
==============================================================================
--- couchdb/trunk/src/couch_mrview/src/couch_mrview_test_util.erl (original)
+++ couchdb/trunk/src/couch_mrview/src/couch_mrview_test_util.erl Sun Sep 18
21:53:05 2011
@@ -19,8 +19,12 @@
init_db(Name, Type) ->
+ init_db(Name, Type, 10).
+
+
+init_db(Name, Type, Count) ->
{ok, Db} = new_db(Name, Type),
- Docs = make_docs(10),
+ Docs = make_docs(Count),
save_docs(Db, Docs).
Added: couchdb/trunk/src/couch_mrview/test/07-compact-swap.t
URL:
http://svn.apache.org/viewvc/couchdb/trunk/src/couch_mrview/test/07-compact-swap.t?rev=1172380&view=auto
==============================================================================
--- couchdb/trunk/src/couch_mrview/test/07-compact-swap.t (added)
+++ couchdb/trunk/src/couch_mrview/test/07-compact-swap.t Sun Sep 18 21:53:05
2011
@@ -0,0 +1,57 @@
+#!/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:run(1, fun() -> test() end).
+
+
+test() ->
+ couch_server_sup:start_link(test_util:config_files()),
+ {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map, 1000),
+ couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
+ test_swap(Db),
+ ok.
+
+
+test_swap(Db) ->
+ {ok, QPid} = start_query(Db),
+ {ok, MonRef} = couch_mrview:compact(Db, <<"_design/bar">>, [monitor]),
+ receive
+ {'DOWN', MonRef, process, _, _} -> ok
+ after 1000 ->
+ throw(compaction_failed)
+ end,
+ QPid ! {self(), continue},
+ receive
+ {QPid, Count} ->
+ etap:is(Count, 1000, "View finished successfully.")
+ after 1000 ->
+ throw("query failed")
+ end.
+
+
+start_query(Db) ->
+ Self = self(),
+ Pid = spawn(fun() ->
+ CB = fun
+ (_, wait) -> receive {Self, continue} -> {ok, 0} end;
+ ({row, _}, Count) -> {ok, Count+1};
+ (_, Count) -> {ok, Count}
+ end,
+ {ok, Result} =
+ couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, [], CB,
wait),
+ Self ! {self(), Result}
+ end),
+ {ok, Pid}.