diff options
-rw-r--r-- | Makefile.am | 7 | ||||
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/couchdb/Makefile.am | 2 | ||||
-rw-r--r-- | src/couchdb/couch_btree.erl | 215 | ||||
-rw-r--r-- | src/ibrowse/Makefile.am | 2 | ||||
-rw-r--r-- | src/mochiweb/Makefile.am | 2 | ||||
-rw-r--r-- | test/etap/030-doc-from-json.t | 4 |
8 files changed, 14 insertions, 220 deletions
diff --git a/Makefile.am b/Makefile.am index 2e4790d0..5ee69f0f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,6 +39,13 @@ THANKS.gz: $(top_srcdir)/THANKS check: all prove test/etap/*.t +cover: all + rm -f cover/*.coverdata + COVER=1 COVER_BIN=./src/couchdb/ prove test/etap/*.t + SRC=./src/couchdb/ \ + $(ERL) -noshell -eval 'etap_report:create()' \ + -s init stop -noshell > /dev/null 2>&1 + dev: all @echo "This command is intended for developers to use;" @echo "it creates development ini files as well as a" @@ -28,5 +28,6 @@ suggesting improvements or submitting changes. Some of these people are: * Volker Mische <volker.mische@gmail.com> * Brian Candler <B.Candler@pobox.com> * Brad Anderson <brad@sankatygroup.com> + * Nick Gerakines <nick@gerakines.net> For a list of authors see the `AUTHORS` file. diff --git a/configure.ac b/configure.ac index 803968f8..fb65ca60 100644 --- a/configure.ac +++ b/configure.ac @@ -74,6 +74,7 @@ AC_ARG_WITH([js-lib], [AC_HELP_STRING([--with-js-lib=PATH], [set PATH to the SpiderMonkey library directory])], [JS_LIB_FLAGS="-L$withval"], []) +AC_ARG_VAR([ERLC_FLAGS], [general flags to prepend to ERLC_FLAGS]) AC_ARG_VAR([FLAGS], [general flags to prepend to LDFLAGS and CPPFLAGS]) LIB_FLAGS="$JS_LIB_FLAGS -L/usr/local/lib -L/opt/local/lib" diff --git a/src/couchdb/Makefile.am b/src/couchdb/Makefile.am index e19a7539..b34155c7 100644 --- a/src/couchdb/Makefile.am +++ b/src/couchdb/Makefile.am @@ -169,7 +169,7 @@ couch.app: couch.app.tpl # $(ERL) -noshell -run edoc_run files [\"$<\"] %.beam: %.erl couch_db.hrl - $(ERLC) ${TEST} $<; + $(ERLC) $(ERLC_FLAGS) ${TEST} $<; install-data-hook: if test -f "$(DESTDIR)/$(couchprivlibdir)/couch_erl_driver"; then \ diff --git a/src/couchdb/couch_btree.erl b/src/couchdb/couch_btree.erl index 4c94a68c..0231d83c 100644 --- a/src/couchdb/couch_btree.erl +++ b/src/couchdb/couch_btree.erl @@ -15,7 +15,6 @@ -export([open/2, open/3, query_modify/4, add/2, add_remove/3, foldl/3, foldl/4]). -export([foldr/3, foldr/4, fold/4, fold/5, full_reduce/1, final_reduce/2]). -export([fold_reduce/6, fold_reduce/7, lookup/2, get_state/1, set_options/2]). --export([test/1, test/0, test_remove/2, test_add/2]). -define(CHUNK_THRESHOLD, 16#4ff). @@ -652,217 +651,3 @@ stream_kv_node2(Bt, Reds, PrevKVs, [{K,V} | RestKVs], Dir, Fun, Acc) -> {stop, Acc2} -> {stop, Acc2} end. - -shuffle(List) -> -%% Determine the log n portion then randomize the list. - randomize(round(math:log(length(List)) + 0.5), List). - -randomize(1, List) -> - randomize(List); -randomize(T, List) -> - lists:foldl(fun(_E, Acc) -> - randomize(Acc) - end, randomize(List), lists:seq(1, (T - 1))). - -randomize(List) -> - D = lists:map(fun(A) -> - {random:uniform(), A} - end, List), - {_, D1} = lists:unzip(lists:keysort(1, D)), - D1. - - - -test()-> - test(1000). - -test(N) -> - Sorted = [{Seq, random:uniform()} || Seq <- lists:seq(1, N)], - test_btree(Sorted), % sorted regular - test_btree(lists:reverse(Sorted)), % sorted reverse - test_btree(shuffle(Sorted)). % randomly distributed - - -test_btree(KeyValues) -> - {ok, Fd} = couch_file:open("foo", [create,overwrite]), - {ok, Btree} = open(nil, Fd), - ReduceFun = - fun(reduce, KVs) -> - length(KVs); - (rereduce, Reds) -> - lists:sum(Reds) - end, - Btree1 = set_options(Btree, [{reduce, ReduceFun}]), - - % first dump in all the values in one go - {ok, Btree10} = add_remove(Btree1, KeyValues, []), - - - Len = length(KeyValues), - - % get the leading reduction as we foldl/r - % and count of all from start to Val1 - Val1 = Len div 3, - {ok, _} = foldl(Btree10, Val1, - fun(_X, LeadingReds, Acc) -> - CountToStart = Val1 + Acc - 1, - CountToStart = final_reduce(Btree10, LeadingReds), - {ok, Acc + 1} - end, - 0), - - {ok, true} = foldr(Btree10, Val1, fun(_X, LeadingReds, _Acc) -> - CountToEnd = Len - Val1, - CountToEnd = final_reduce(Btree10, LeadingReds), - {stop, true} % change Acc to 'true' - end, - false), - - ok = test_keys(Btree10, KeyValues), - - % remove everything - {ok, Btree20} = test_remove(Btree10, KeyValues), - - % make sure its empty - {ok, false} = foldl(Btree20, fun(_X, _Acc) -> - {ok, true} % change Acc to 'true' - end, - false), - - % add everything back one at a time. - {ok, Btree30} = test_add(Btree20, KeyValues), - - ok = test_keys(Btree30, KeyValues), - - KeyValuesRev = lists:reverse(KeyValues), - - % remove everything, in reverse order - {ok, Btree40} = test_remove(Btree30, KeyValuesRev), - - % make sure its empty - {ok, false} = foldl(Btree40, fun(_X, _Acc) -> - {ok, true} % change Acc to 'true' - end, - false), - - - {A, B} = every_other(KeyValues), - - % add everything back - {ok, Btree50} = test_add(Btree40,KeyValues), - - ok = test_keys(Btree50, KeyValues), - - % remove half the values - {ok, Btree60} = test_remove(Btree50, A), - - % verify the remaining - ok = test_keys(Btree60, B), - - % add A back - {ok, Btree70} = test_add(Btree60, A), - - % verify - ok = test_keys(Btree70, KeyValues), - - % remove B - {ok, Btree80} = test_remove(Btree70, B), - - % verify the remaining - ok = test_keys(Btree80, A), - - {ok, Btree90} = test_remove(Btree80, A), - - EvenOdd = fun(V) when V rem 2 == 1 -> "odd"; (_) -> "even" end, - - EvenOddKVs = [{{EvenOdd(Key),Key}, 1} || {Key, _} <- KeyValues], - - {ok, Btree100} = test_add(Btree90, EvenOddKVs), - GroupingFun = fun({K1, _},{K2,_}) -> K1 == K2 end, - FoldFun = fun(GroupedKey, Unreduced, Acc) -> - {ok, [{GroupedKey, final_reduce(Btree100, Unreduced)} | Acc]} - end, - - Half = Len div 2, - - {ok, [{{"odd", _}, Half}, {{"even",_}, Half}]} = - fold_reduce(Btree100, nil, nil, GroupingFun, FoldFun, []), - - {ok, [{{"even",_}, Half}, {{"odd", _}, Half}]} = - fold_reduce(Btree100, rev, nil, nil, GroupingFun, FoldFun, []), - - {ok, [{{"even",_}, Half}]} = - fold_reduce(Btree100, fwd, {"even", -1}, {"even", foo}, GroupingFun, FoldFun, []), - - {ok, [{{"even",_}, Half}]} = - fold_reduce(Btree100, rev, {"even", foo}, {"even", -1}, GroupingFun, FoldFun, []), - - {ok, [{{"odd",_}, Half}]} = - fold_reduce(Btree100, fwd, {"odd", -1}, {"odd", foo}, GroupingFun, FoldFun, []), - - {ok, [{{"odd",_}, Half}]} = - fold_reduce(Btree100, rev, {"odd", foo}, {"odd", -1}, GroupingFun, FoldFun, []), - - {ok, [{{"odd", _}, Half}, {{"even",_}, Half}]} = - fold_reduce(Btree100, {"even", -1}, {"odd", foo}, GroupingFun, FoldFun, []), - - ok = couch_file:close(Fd). - - - - - -every_other(List) -> - every_other(List, [], [], 1). - -every_other([], AccA, AccB, _Flag) -> - {lists:reverse(AccA), lists:reverse(AccB)}; -every_other([H|T], AccA, AccB, 1) -> - every_other(T, [H|AccA], AccB, 0); -every_other([H|T], AccA, AccB, 0) -> - every_other(T, AccA, [H|AccB], 1). - -test_keys(Btree, List) -> - FoldFun = - fun(Element, [HAcc|TAcc]) -> - Element = HAcc, % must match - {ok, TAcc} - end, - Sorted = lists:sort(List), - {ok, []} = foldl(Btree, FoldFun, Sorted), - {ok, []} = foldr(Btree, FoldFun, lists:reverse(Sorted)), - - test_lookup(Btree, List). - -% Makes sure each key value pair is found in the btree -test_lookup(_Btree, []) -> - ok; -test_lookup(Btree, [{Key, Value} | Rest]) -> - [{ok,{Key, Value}}] = lookup(Btree, [Key]), - {ok, []} = foldl(Btree, Key, fun({KeyIn, ValueIn}, []) -> - KeyIn = Key, - ValueIn = Value, - {stop, []} - end, - []), - {ok, []} = foldr(Btree, Key, fun({KeyIn, ValueIn}, []) -> - KeyIn = Key, - ValueIn = Value, - {stop, []} - end, - []), - test_lookup(Btree, Rest). - -% removes each key one at a time from the btree -test_remove(Btree, []) -> - {ok, Btree}; -test_remove(Btree, [{Key, _Value} | Rest]) -> - {ok, Btree2} = add_remove(Btree,[], [Key]), - test_remove(Btree2, Rest). - -% adds each key one at a time from the btree -test_add(Btree, []) -> - {ok, Btree}; -test_add(Btree, [KeyValue | Rest]) -> - {ok, Btree2} = add_remove(Btree, [KeyValue], []), - test_add(Btree2, Rest). diff --git a/src/ibrowse/Makefile.am b/src/ibrowse/Makefile.am index 614bdc39..2ba7b31c 100644 --- a/src/ibrowse/Makefile.am +++ b/src/ibrowse/Makefile.am @@ -45,4 +45,4 @@ CLEANFILES = \ $(ibrowseebin_make_generated_file_list) %.beam: %.erl - $(ERLC) $< + $(ERLC) $(ERLC_FLAGS) $< diff --git a/src/mochiweb/Makefile.am b/src/mochiweb/Makefile.am index 7654cd16..a3ae0068 100644 --- a/src/mochiweb/Makefile.am +++ b/src/mochiweb/Makefile.am @@ -76,4 +76,4 @@ CLEANFILES = \ $(mochiwebebin_make_generated_file_list) %.beam: %.erl - $(ERLC) $< + $(ERLC) $(ERLC_FLAGS) $< diff --git a/test/etap/030-doc-from-json.t b/test/etap/030-doc-from-json.t index bf685c24..2d5eb8f7 100644 --- a/test/etap/030-doc-from-json.t +++ b/test/etap/030-doc-from-json.t @@ -87,11 +87,11 @@ test_from_json_success() -> }, { {[ - {<<"_rev">>, <<"6-something">>}, {<<"_revisions">>, {[ {<<"start">>, 4}, {<<"ids">>, [<<"foo1">>, <<"phi3">>, <<"omega">>]} - ]}} + ]}}, + {<<"_rev">>, <<"6-something">>} ]}, #doc{revs={4, [<<"foo1">>, <<"phi3">>, <<"omega">>]}}, "_revisions attribute are preferred to _rev." |