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/02/09 21:00:51 UTC
[50/57] [abbrv] couchdb commit: updated
refs/heads/developer-preview-2.0 to 849b334
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/050-stream.t
----------------------------------------------------------------------
diff --git a/test/etap/050-stream.t b/test/etap/050-stream.t
deleted file mode 100755
index 0251f00..0000000
--- a/test/etap/050-stream.t
+++ /dev/null
@@ -1,87 +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(13),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail(Other)
- end,
- ok.
-
-read_all(Fd, PosList) ->
- Data = couch_stream:foldl(Fd, PosList, fun(Bin, Acc) -> [Bin, Acc] end, []),
- iolist_to_binary(Data).
-
-test() ->
- {ok, Fd} = couch_file:open("test/etap/temp.050", [create,overwrite]),
- {ok, Stream} = couch_stream:open(Fd),
-
- etap:is(ok, couch_stream:write(Stream, <<"food">>),
- "Writing to streams works."),
-
- etap:is(ok, couch_stream:write(Stream, <<"foob">>),
- "Consecutive writing to streams works."),
-
- etap:is(ok, couch_stream:write(Stream, <<>>),
- "Writing an empty binary does nothing."),
-
- {Ptrs, Length, _, _, _} = couch_stream:close(Stream),
- etap:is(Ptrs, [{0, 8}], "Close returns the file pointers."),
- etap:is(Length, 8, "Close also returns the number of bytes written."),
- etap:is(<<"foodfoob">>, read_all(Fd, Ptrs), "Returned pointers are valid."),
-
- % Remember where we expect the pointer to be.
- {ok, ExpPtr} = couch_file:bytes(Fd),
- {ok, Stream2} = couch_stream:open(Fd),
- OneBits = <<1:(8*10)>>,
- etap:is(ok, couch_stream:write(Stream2, OneBits),
- "Successfully wrote 79 zero bits and 1 one bit."),
-
- ZeroBits = <<0:(8*10)>>,
- etap:is(ok, couch_stream:write(Stream2, ZeroBits),
- "Successfully wrote 80 0 bits."),
-
- {Ptrs2, Length2, _, _, _} = couch_stream:close(Stream2),
- etap:is(Ptrs2, [{ExpPtr, 20}], "Closing stream returns the file pointers."),
- etap:is(Length2, 20, "Length written is 160 bytes."),
-
- AllBits = iolist_to_binary([OneBits,ZeroBits]),
- etap:is(AllBits, read_all(Fd, Ptrs2), "Returned pointers are valid."),
-
- % Stream more the 4K chunk size.
- {ok, ExpPtr2} = couch_file:bytes(Fd),
- {ok, Stream3} = couch_stream:open(Fd, [{buffer_size, 4096}]),
- lists:foldl(fun(_, Acc) ->
- Data = <<"a1b2c">>,
- couch_stream:write(Stream3, Data),
- [Data | Acc]
- end, [], lists:seq(1, 1024)),
- {Ptrs3, Length3, _, _, _} = couch_stream:close(Stream3),
-
- % 4095 because of 5 * 4096 rem 5 (last write before exceeding threshold)
- % + 5 puts us over the threshold
- % + 4 bytes for the term_to_binary adding a length header
- % + 1 byte every 4K for tail append headers
- SecondPtr = ExpPtr2 + 4095 + 5 + 4 + 1,
- etap:is(Ptrs3, [{ExpPtr2, 4100}, {SecondPtr, 1020}], "Pointers every 4K bytes."),
- etap:is(Length3, 5120, "Wrote the expected 5K bytes."),
-
- couch_file:close(Fd),
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/060-kt-merging.t
----------------------------------------------------------------------
diff --git a/test/etap/060-kt-merging.t b/test/etap/060-kt-merging.t
deleted file mode 100755
index e0b1a9c..0000000
--- a/test/etap/060-kt-merging.t
+++ /dev/null
@@ -1,175 +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(16),
- 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() ->
- One = {1, {"1","foo",[]}},
-
- etap:is(
- {[One], new_leaf},
- couch_key_tree:merge([], One, 10),
- "The empty tree is the identity for merge."
- ),
- etap:is(
- {[One], internal_node},
- couch_key_tree:merge([One], One, 10),
- "Merging is reflexive."
- ),
-
- TwoSibs = [{1, {"1","foo",[]}},
- {1, {"2","foo",[]}}],
-
- etap:is(
- {TwoSibs, internal_node},
- couch_key_tree:merge(TwoSibs, One, 10),
- "Merging a prefix of a tree with the tree yields the tree."
- ),
-
- Three = {1, {"3","foo",[]}},
- ThreeSibs = [{1, {"1","foo",[]}},
- {1, {"2","foo",[]}},
- {1, {"3","foo",[]}}],
-
- etap:is(
- {ThreeSibs, new_branch},
- couch_key_tree:merge(TwoSibs, Three, 10),
- "Merging a third unrelated branch leads to a conflict."
- ),
-
-
- TwoChild = {1, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}]}},
-
- etap:is(
- {[TwoChild], internal_node},
- couch_key_tree:merge([TwoChild], TwoChild, 10),
- "Merging two children is still reflexive."
- ),
-
- TwoChildSibs = {1, {"1","foo", [{"1a", "bar", []},
- {"1b", "bar", []}]}},
-
- Stemmed1b = {2, {"1a", "bar", []}},
- etap:is(
- {[TwoChildSibs], internal_node},
- couch_key_tree:merge([TwoChildSibs], Stemmed1b, 10),
- "Merging a tree with a stem."
- ),
-
- TwoChildSibs2 = {1, {"1","foo", [{"1a", "bar", []},
- {"1b", "bar", [{"1bb", "boo", []}]}]}},
- Stemmed1bb = {3, {"1bb", "boo", []}},
- etap:is(
- {[TwoChildSibs2], internal_node},
- couch_key_tree:merge([TwoChildSibs2], Stemmed1bb, 10),
- "Merging a stem at a deeper level."
- ),
-
- StemmedTwoChildSibs2 = [{2,{"1a", "bar", []}},
- {2,{"1b", "bar", [{"1bb", "boo", []}]}}],
-
- etap:is(
- {StemmedTwoChildSibs2, internal_node},
- couch_key_tree:merge(StemmedTwoChildSibs2, Stemmed1bb, 10),
- "Merging a stem at a deeper level against paths at deeper levels."
- ),
-
- Stemmed1aa = {3, {"1aa", "bar", []}},
- etap:is(
- {[TwoChild], internal_node},
- couch_key_tree:merge([TwoChild], Stemmed1aa, 10),
- "Merging a single tree with a deeper stem."
- ),
-
- Stemmed1a = {2, {"1a", "bar", [{"1aa", "bar", []}]}},
- etap:is(
- {[TwoChild], internal_node},
- couch_key_tree:merge([TwoChild], Stemmed1a, 10),
- "Merging a larger stem."
- ),
-
- etap:is(
- {[Stemmed1a], internal_node},
- couch_key_tree:merge([Stemmed1a], Stemmed1aa, 10),
- "More merging."
- ),
-
- OneChild = {1, {"1","foo",[{"1a", "bar", []}]}},
- Expect1 = [OneChild, Stemmed1aa],
- etap:is(
- {Expect1, new_branch},
- couch_key_tree:merge([OneChild], Stemmed1aa, 10),
- "Merging should create conflicts."
- ),
-
- etap:is(
- {[TwoChild], new_leaf},
- couch_key_tree:merge(Expect1, TwoChild, 10),
- "Merge should have no conflicts."
- ),
-
- %% this test is based on couch-902-test-case2.py
- %% foo has conflicts from replication at depth two
- %% foo3 is the current value
- Foo = {1, {"foo",
- "val1",
- [{"foo2","val2",[]},
- {"foo3", "val3", []}
- ]}},
- %% foo now has an attachment added, which leads to foo4 and val4
- %% off foo3
- Bar = {1, {"foo",
- [],
- [{"foo3",
- [],
- [{"foo4","val4",[]}
- ]}]}},
- %% this is what the merge returns
- %% note that it ignore the conflicting branch as there's no match
- FooBar = {1, {"foo",
- "val1",
- [{"foo2","val2",[]},
- {"foo3", "val3", [{"foo4","val4",[]}]}
- ]}},
-
- etap:is(
- {[FooBar], new_leaf},
- couch_key_tree:merge([Foo],Bar,10),
- "Merging trees with conflicts ought to behave."
- ),
-
- etap:is(
- {[TwoChild], internal_node},
- couch_key_tree:merge([TwoChild],One,10),
- "Merging tree with already-existing path."
- ),
-
- etap:is(
- {[TwoChildSibs], internal_node},
- couch_key_tree:merge([TwoChildSibs],One,10),
- "Merging tree with already-existing path with siblings."
- ),
-
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/061-kt-missing-leaves.t
----------------------------------------------------------------------
diff --git a/test/etap/061-kt-missing-leaves.t b/test/etap/061-kt-missing-leaves.t
deleted file mode 100755
index d60b4db..0000000
--- a/test/etap/061-kt-missing-leaves.t
+++ /dev/null
@@ -1,65 +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(4),
- 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() ->
- TwoChildSibs = [{0, {"1","foo", [{"1a", "bar", []}, {"1b", "bar", []}]}}],
- Stemmed1 = [{1, {"1a", "bar", [{"1aa", "bar", []}]}}],
- Stemmed2 = [{2, {"1aa", "bar", []}}],
-
- etap:is(
- [],
- couch_key_tree:find_missing(TwoChildSibs, [{0,"1"}, {1,"1a"}]),
- "Look for missing keys."
- ),
-
- etap:is(
- [{0, "10"}, {100, "x"}],
- couch_key_tree:find_missing(
- TwoChildSibs,
- [{0,"1"}, {0, "10"}, {1,"1a"}, {100, "x"}]
- ),
- "Look for missing keys."
- ),
-
- etap:is(
- [{0, "1"}, {100, "x"}],
- couch_key_tree:find_missing(
- Stemmed1,
- [{0,"1"}, {1,"1a"}, {100, "x"}]
- ),
- "Look for missing keys."
- ),
- etap:is(
- [{0, "1"}, {1,"1a"}, {100, "x"}],
- couch_key_tree:find_missing(
- Stemmed2,
- [{0,"1"}, {1,"1a"}, {100, "x"}]
- ),
- "Look for missing keys."
- ),
-
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/062-kt-remove-leaves.t
----------------------------------------------------------------------
diff --git a/test/etap/062-kt-remove-leaves.t b/test/etap/062-kt-remove-leaves.t
deleted file mode 100755
index 745a00b..0000000
--- a/test/etap/062-kt-remove-leaves.t
+++ /dev/null
@@ -1,69 +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(6),
- 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() ->
- OneChild = [{0, {"1","foo",[{"1a", "bar", []}]}}],
- TwoChildSibs = [{0, {"1","foo", [{"1a", "bar", []}, {"1b", "bar", []}]}}],
- Stemmed = [{1, {"1a", "bar", [{"1aa", "bar", []}]}}],
-
- etap:is(
- {TwoChildSibs, []},
- couch_key_tree:remove_leafs(TwoChildSibs, []),
- "Removing no leaves has no effect on the tree."
- ),
-
- etap:is(
- {TwoChildSibs, []},
- couch_key_tree:remove_leafs(TwoChildSibs, [{0, "1"}]),
- "Removing a non-existant branch has no effect."
- ),
-
- etap:is(
- {OneChild, [{1, "1b"}]},
- couch_key_tree:remove_leafs(TwoChildSibs, [{1, "1b"}]),
- "Removing a leaf removes the leaf."
- ),
-
- etap:is(
- {[], [{1, "1b"},{1, "1a"}]},
- couch_key_tree:remove_leafs(TwoChildSibs, [{1, "1a"}, {1, "1b"}]),
- "Removing all leaves returns an empty tree."
- ),
-
- etap:is(
- {Stemmed, []},
- couch_key_tree:remove_leafs(Stemmed, [{1, "1a"}]),
- "Removing a non-existant node has no effect."
- ),
-
- etap:is(
- {[], [{2, "1aa"}]},
- couch_key_tree:remove_leafs(Stemmed, [{2, "1aa"}]),
- "Removing the last leaf returns an empty tree."
- ),
-
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/063-kt-get-leaves.t
----------------------------------------------------------------------
diff --git a/test/etap/063-kt-get-leaves.t b/test/etap/063-kt-get-leaves.t
deleted file mode 100755
index 6d4e800..0000000
--- a/test/etap/063-kt-get-leaves.t
+++ /dev/null
@@ -1,98 +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(11),
- 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() ->
- TwoChildSibs = [{0, {"1","foo", [{"1a", "bar", []}, {"1b", "bar", []}]}}],
- Stemmed = [{1, {"1a", "bar", [{"1aa", "bar", []}]}}],
-
- etap:is(
- {[{"foo", {0, ["1"]}}],[]},
- couch_key_tree:get(TwoChildSibs, [{0, "1"}]),
- "extract a subtree."
- ),
-
- etap:is(
- {[{"bar", {1, ["1a", "1"]}}],[]},
- couch_key_tree:get(TwoChildSibs, [{1, "1a"}]),
- "extract a subtree."
- ),
-
- etap:is(
- {[],[{0,"x"}]},
- couch_key_tree:get_key_leafs(TwoChildSibs, [{0, "x"}]),
- "gather up the leaves."
- ),
-
- etap:is(
- {[{"bar", {1, ["1a","1"]}}],[]},
- couch_key_tree:get_key_leafs(TwoChildSibs, [{1, "1a"}]),
- "gather up the leaves."
- ),
-
- etap:is(
- {[{"bar", {1, ["1a","1"]}},{"bar",{1, ["1b","1"]}}],[]},
- couch_key_tree:get_key_leafs(TwoChildSibs, [{0, "1"}]),
- "gather up the leaves."
- ),
-
- etap:is(
- {[{0,[{"1", "foo"}]}],[]},
- couch_key_tree:get_full_key_paths(TwoChildSibs, [{0, "1"}]),
- "retrieve full key paths."
- ),
-
- etap:is(
- {[{1,[{"1a", "bar"},{"1", "foo"}]}],[]},
- couch_key_tree:get_full_key_paths(TwoChildSibs, [{1, "1a"}]),
- "retrieve full key paths."
- ),
-
- etap:is(
- [{2, [{"1aa", "bar"},{"1a", "bar"}]}],
- couch_key_tree:get_all_leafs_full(Stemmed),
- "retrieve all leaves."
- ),
-
- etap:is(
- [{1, [{"1a", "bar"},{"1", "foo"}]}, {1, [{"1b", "bar"},{"1", "foo"}]}],
- couch_key_tree:get_all_leafs_full(TwoChildSibs),
- "retrieve all the leaves."
- ),
-
- etap:is(
- [{"bar", {2, ["1aa","1a"]}}],
- couch_key_tree:get_all_leafs(Stemmed),
- "retrieve all leaves."
- ),
-
- etap:is(
- [{"bar", {1, ["1a", "1"]}}, {"bar", {1, ["1b","1"]}}],
- couch_key_tree:get_all_leafs(TwoChildSibs),
- "retrieve all the leaves."
- ),
-
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/064-kt-counting.t
----------------------------------------------------------------------
diff --git a/test/etap/064-kt-counting.t b/test/etap/064-kt-counting.t
deleted file mode 100755
index f182d28..0000000
--- a/test/etap/064-kt-counting.t
+++ /dev/null
@@ -1,46 +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(4),
- 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() ->
- EmptyTree = [],
- One = [{0, {"1","foo",[]}}],
- TwoChildSibs = [{0, {"1","foo", [{"1a", "bar", []}, {"1b", "bar", []}]}}],
- Stemmed = [{2, {"1bb", "boo", []}}],
-
- etap:is(0, couch_key_tree:count_leafs(EmptyTree),
- "Empty trees have no leaves."),
-
- etap:is(1, couch_key_tree:count_leafs(One),
- "Single node trees have a single leaf."),
-
- etap:is(2, couch_key_tree:count_leafs(TwoChildSibs),
- "Two children siblings counted as two leaves."),
-
- etap:is(1, couch_key_tree:count_leafs(Stemmed),
- "Stemming does not affect leaf counting."),
-
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/065-kt-stemming.t
----------------------------------------------------------------------
diff --git a/test/etap/065-kt-stemming.t b/test/etap/065-kt-stemming.t
deleted file mode 100755
index 6e781c1..0000000
--- a/test/etap/065-kt-stemming.t
+++ /dev/null
@@ -1,42 +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(3),
- 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() ->
- TwoChild = [{0, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}]}}],
- Stemmed1 = [{1, {"1a", "bar", [{"1aa", "bar", []}]}}],
- Stemmed2 = [{2, {"1aa", "bar", []}}],
-
- etap:is(TwoChild, couch_key_tree:stem(TwoChild, 3),
- "Stemming more levels than what exists does nothing."),
-
- etap:is(Stemmed1, couch_key_tree:stem(TwoChild, 2),
- "Stemming with a depth of two returns the deepest two nodes."),
-
- etap:is(Stemmed2, couch_key_tree:stem(TwoChild, 1),
- "Stemming to a depth of one returns the deepest node."),
-
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/070-couch-db.t
----------------------------------------------------------------------
diff --git a/test/etap/070-couch-db.t b/test/etap/070-couch-db.t
deleted file mode 100755
index 5fa9344..0000000
--- a/test/etap/070-couch-db.t
+++ /dev/null
@@ -1,74 +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(4),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- timer:sleep(1000),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
- test_util:start_couch(),
-
- couch_db:create(<<"etap-test-db">>, []),
- {ok, AllDbs} = couch_server:all_databases(),
- etap:ok(lists:member(<<"etap-test-db">>, AllDbs), "Database was created."),
-
- couch_server:delete(<<"etap-test-db">>, []),
- {ok, AllDbs2} = couch_server:all_databases(),
- etap:ok(not lists:member(<<"etap-test-db">>, AllDbs2),
- "Database was deleted."),
-
- gen_server:call(couch_server, {set_max_dbs_open, 3}),
- MkDbName = fun(Int) -> list_to_binary("lru-" ++ integer_to_list(Int)) end,
-
- lists:foreach(fun(Int) ->
- {ok, TestDbs} = couch_server:all_databases(),
- ok = case lists:member(MkDbName(Int), TestDbs) of
- true -> couch_server:delete(MkDbName(Int), []);
- _ -> ok
- end,
- {ok, Db} = couch_db:create(MkDbName(Int), []),
- ok = couch_db:close(Db)
- end, lists:seq(1, 6)),
-
- {ok, AllDbs3} = couch_server:all_databases(),
- NumCreated = lists:foldl(fun(Int, Acc) ->
- true = lists:member(MkDbName(Int), AllDbs3),
- Acc+1
- end, 0, lists:seq(1, 6)),
- etap:is(6, NumCreated, "Created all databases."),
-
- lists:foreach(fun(Int) ->
- ok = couch_server:delete(MkDbName(Int), [])
- end, lists:seq(1, 6)),
-
- {ok, AllDbs4} = couch_server:all_databases(),
- NumDeleted = lists:foldl(fun(Int, Acc) ->
- false = lists:member(MkDbName(Int), AllDbs4),
- Acc+1
- end, 0, lists:seq(1, 6)),
- etap:is(6, NumDeleted, "Deleted all databases."),
-
- ok = test_util:stop_couch(),
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/071-couchdb-rapid-cycle.t
----------------------------------------------------------------------
diff --git a/test/etap/071-couchdb-rapid-cycle.t b/test/etap/071-couchdb-rapid-cycle.t
deleted file mode 100755
index 2e86483..0000000
--- a/test/etap/071-couchdb-rapid-cycle.t
+++ /dev/null
@@ -1,74 +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(2),
- try
- ok = test()
- catch T:R ->
- Stack = erlang:get_stacktrace(),
- etap:diag("Test died abnormally: ~p~n ~p", [{T, R}, Stack]),
- timer:sleep(250),
- etap:bail(io_lib:format("Error: ~p", [{T, R}]))
- end,
- ok.
-
-dbname() -> <<"etap-test-db">>.
-
-test() ->
- ok = test_util:start_couch(),
- timer:sleep(500),
-
- couch_server:delete(dbname(), []),
- etap:diag("Test starting"),
- timer:sleep(250),
-
- Pid = spawn_link(fun() -> open_loop() end),
-
- Result = lists:foldl(fun(_, N) ->
- {ok, Db} = couch_db:create(dbname(), []),
- ok = couch_db:close(Db),
- ok = couch_server:delete(dbname(), []),
- N + 1
- end, 0, lists:seq(1, 100)),
-
- etap:is(Result, 100, "Cycled the database 1000 times successfully."),
- etap:is(is_process_alive(Pid), true, "The open loop lives"),
-
- Pid ! {self(), close},
- receive
- {Pid, ok} -> ok
- after 1000 ->
- open_loop_didnt_die
- end.
-
-open_loop() ->
- receive
- {Parent, close} ->
- Parent ! {self(), ok}
- after 0 ->
- case couch_db:open_int(dbname(), []) of
- {ok, Db} ->
- ok = couch_db:close(Db);
- {not_found, no_db_file} ->
- ok;
- Other ->
- etap:diag("WHIBBLE? ~p", [Other])
- end,
- open_loop()
- end.
-
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/072-cleanup.t
----------------------------------------------------------------------
diff --git a/test/etap/072-cleanup.t b/test/etap/072-cleanup.t
deleted file mode 100755
index ddd8ca8..0000000
--- a/test/etap/072-cleanup.t
+++ /dev/null
@@ -1,126 +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.
-
--define(TEST_DB, <<"etap-test-db">>).
-
--record(user_ctx, {
- name = null,
- roles = [],
- handler
-}).
-
--define(ADMIN_USER, #user_ctx{roles=[<<"_admin">>]}).
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(7),
- try test() of
- ok ->
- etap:end_tests()
- catch
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- timer:sleep(1000),
- etap:bail(Other)
- end,
- ok.
-
-test() ->
-
- ok = test_util:start_couch(),
- couch_server:delete(?TEST_DB, []),
- timer:sleep(1000),
-
- couch_db:create(?TEST_DB, []),
-
- {ok, AllDbs} = couch_server:all_databases(),
- etap:ok(lists:member(?TEST_DB, AllDbs), "Database was created."),
-
- FooRev = create_design_doc(<<"_design/foo">>, <<"bar">>),
- query_view("foo", "bar"),
-
- BoozRev = create_design_doc(<<"_design/booz">>, <<"baz">>),
- query_view("booz", "baz"),
-
- {ok, _Db} = couch_db:open(?TEST_DB, [{user_ctx, ?ADMIN_USER}]),
- view_cleanup(),
- etap:is(count_index_files(), 2,
- "Two index files before any deletions."),
-
- delete_design_doc(<<"_design/foo">>, FooRev),
- view_cleanup(),
- etap:is(count_index_files(), 1,
- "One index file after first deletion and cleanup."),
-
- delete_design_doc(<<"_design/booz">>, BoozRev),
- view_cleanup(),
- etap:is(count_index_files(), 0,
- "No index files after second deletion and cleanup."),
-
- couch_server:delete(?TEST_DB, []),
- {ok, AllDbs2} = couch_server:all_databases(),
- etap:ok(not lists:member(?TEST_DB, AllDbs2),
- "Database was deleted."),
- ok.
-
-create_design_doc(DDName, ViewName) ->
- {ok, Db} = couch_db:open(?TEST_DB, [{user_ctx, ?ADMIN_USER}]),
- DDoc = couch_doc:from_json_obj({[
- {<<"_id">>, DDName},
- {<<"language">>, <<"javascript">>},
- {<<"views">>, {[
- {ViewName, {[
- {<<"map">>, <<"function(doc) { emit(doc.value, 1); }">>}
- ]}}
- ]}}
- ]}),
- {ok, Rev} = couch_db:update_doc(Db, DDoc, []),
- couch_db:ensure_full_commit(Db),
- couch_db:close(Db),
- Rev.
-
-delete_design_doc(DDName, Rev) ->
- {ok, Db} = couch_db:open(?TEST_DB, [{user_ctx, ?ADMIN_USER}]),
- DDoc = couch_doc:from_json_obj({[
- {<<"_id">>, DDName},
- {<<"_rev">>, couch_doc:rev_to_str(Rev)},
- {<<"_deleted">>, true}
- ]}),
- {ok, _} = couch_db:update_doc(Db, DDoc, [Rev]),
- couch_db:close(Db).
-
-db_url() ->
- Addr = config:get("httpd", "bind_address", "127.0.0.1"),
- Port = integer_to_list(mochiweb_socket_server:get(couch_httpd, port)),
- "http://" ++ Addr ++ ":" ++ Port ++ "/" ++
- binary_to_list(?TEST_DB).
-
-query_view(DDoc, View) ->
- {ok, Code, _Headers, _Body} = test_util:request(
- db_url() ++ "/_design/" ++ DDoc ++ "/_view/" ++ View, [], get),
- etap:is(Code, 200, "Built view index for " ++ DDoc ++ "."),
- ok.
-
-view_cleanup() ->
- {ok, Db} = couch_db:open(?TEST_DB, [{user_ctx, ?ADMIN_USER}]),
- couch_mrview:cleanup(Db),
- couch_db:close(Db).
-
-count_index_files() ->
- % call server to fetch the index files
- RootDir = config:get("couchdb", "view_index_dir"),
- length(filelib:wildcard(RootDir ++ "/." ++
- binary_to_list(?TEST_DB) ++ "_design"++"/mrview/*")).
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/073-changes.t
----------------------------------------------------------------------
diff --git a/test/etap/073-changes.t b/test/etap/073-changes.t
deleted file mode 100755
index bd81964..0000000
--- a/test/etap/073-changes.t
+++ /dev/null
@@ -1,550 +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.
-
-% Verify that compacting databases that are being used as the source or
-% target of a replication doesn't affect the replication and that the
-% replication doesn't hold their reference counters forever.
-
--mode(compile).
-
--record(user_ctx, {
- name = null,
- roles = [],
- handler
-}).
-
--record(changes_args, {
- feed = "normal",
- dir = fwd,
- since = 0,
- limit = 1000000000000000,
- style = main_only,
- heartbeat,
- timeout,
- filter = "",
- filter_fun,
- filter_args = [],
- include_docs = false,
- doc_options = [],
- conflicts = false,
- db_open_options = []
-}).
-
--record(row, {
- id,
- seq,
- deleted = false
-}).
-
-
-test_db_name() -> <<"couch_test_changes">>.
-
-
-main(_) ->
- test_util:run(43, fun() -> test() end).
-
-
-test() ->
- test_util:start_couch(),
-
- test_by_doc_ids(),
- test_by_doc_ids_with_since(),
- test_by_doc_ids_continuous(),
- test_design_docs_only(),
- test_heartbeat(),
-
- ok.
-
-
-test_by_doc_ids() ->
- create_db(test_db_name()),
-
- {ok, _Rev1} = save_doc({[{<<"_id">>, <<"doc1">>}]}),
- {ok, _Rev2} = save_doc({[{<<"_id">>, <<"doc2">>}]}),
- {ok, Rev3} = save_doc({[{<<"_id">>, <<"doc3">>}]}),
- {ok, _Rev4} = save_doc({[{<<"_id">>, <<"doc4">>}]}),
- {ok, _Rev5} = save_doc({[{<<"_id">>, <<"doc5">>}]}),
- {ok, _Rev3_2} = save_doc({[{<<"_id">>, <<"doc3">>}, {<<"_rev">>, Rev3}]}),
- {ok, _Rev6} = save_doc({[{<<"_id">>, <<"doc6">>}]}),
- {ok, _Rev7} = save_doc({[{<<"_id">>, <<"doc7">>}]}),
- {ok, _Rev8} = save_doc({[{<<"_id">>, <<"doc8">>}]}),
-
- etap:diag("Folding changes in ascending order with _doc_ids filter"),
- ChangesArgs = #changes_args{
- filter = "_doc_ids"
- },
- DocIds = [<<"doc3">>, <<"doc4">>, <<"doc9999">>],
- Req = {json_req, {[{<<"doc_ids">>, DocIds}]}},
- Consumer = spawn_consumer(test_db_name(), ChangesArgs, Req),
-
- {Rows, LastSeq} = wait_finished(Consumer),
- {ok, Db2} = couch_db:open_int(test_db_name(), []),
- UpSeq = couch_db:get_update_seq(Db2),
- couch_db:close(Db2),
- etap:is(length(Rows), 2, "Received 2 changes rows"),
- etap:is(LastSeq, UpSeq, "LastSeq is same as database update seq number"),
- [#row{seq = Seq1, id = Id1}, #row{seq = Seq2, id = Id2}] = Rows,
- etap:is(Id1, <<"doc4">>, "First row is for doc doc4"),
- etap:is(Seq1, 4, "First row has seq 4"),
- etap:is(Id2, <<"doc3">>, "Second row is for doc doc3"),
- etap:is(Seq2, 6, "Second row has seq 6"),
-
- stop(Consumer),
- etap:diag("Folding changes in descending order with _doc_ids filter"),
- ChangesArgs2 = #changes_args{
- filter = "_doc_ids",
- dir = rev
- },
- Consumer2 = spawn_consumer(test_db_name(), ChangesArgs2, Req),
-
- {Rows2, LastSeq2} = wait_finished(Consumer2),
- etap:is(length(Rows2), 2, "Received 2 changes rows"),
- etap:is(LastSeq2, 4, "LastSeq is 4"),
- [#row{seq = Seq1_2, id = Id1_2}, #row{seq = Seq2_2, id = Id2_2}] = Rows2,
- etap:is(Id1_2, <<"doc3">>, "First row is for doc doc3"),
- etap:is(Seq1_2, 6, "First row has seq 4"),
- etap:is(Id2_2, <<"doc4">>, "Second row is for doc doc4"),
- etap:is(Seq2_2, 4, "Second row has seq 6"),
-
- stop(Consumer2),
- delete_db().
-
-
-test_by_doc_ids_with_since() ->
- create_db(test_db_name()),
-
- {ok, _Rev1} = save_doc({[{<<"_id">>, <<"doc1">>}]}),
- {ok, _Rev2} = save_doc({[{<<"_id">>, <<"doc2">>}]}),
- {ok, Rev3} = save_doc({[{<<"_id">>, <<"doc3">>}]}),
- {ok, _Rev4} = save_doc({[{<<"_id">>, <<"doc4">>}]}),
- {ok, _Rev5} = save_doc({[{<<"_id">>, <<"doc5">>}]}),
- {ok, Rev3_2} = save_doc({[{<<"_id">>, <<"doc3">>}, {<<"_rev">>, Rev3}]}),
- {ok, _Rev6} = save_doc({[{<<"_id">>, <<"doc6">>}]}),
- {ok, _Rev7} = save_doc({[{<<"_id">>, <<"doc7">>}]}),
- {ok, _Rev8} = save_doc({[{<<"_id">>, <<"doc8">>}]}),
-
- ChangesArgs = #changes_args{
- filter = "_doc_ids",
- since = 5
- },
- DocIds = [<<"doc3">>, <<"doc4">>, <<"doc9999">>],
- Req = {json_req, {[{<<"doc_ids">>, DocIds}]}},
- Consumer = spawn_consumer(test_db_name(), ChangesArgs, Req),
-
- {Rows, LastSeq} = wait_finished(Consumer),
- {ok, Db2} = couch_db:open_int(test_db_name(), []),
- UpSeq = couch_db:get_update_seq(Db2),
- couch_db:close(Db2),
- etap:is(LastSeq, UpSeq, "LastSeq is same as database update seq number"),
- etap:is(length(Rows), 1, "Received 1 changes rows"),
- [#row{seq = Seq1, id = Id1}] = Rows,
- etap:is(Id1, <<"doc3">>, "First row is for doc doc3"),
- etap:is(Seq1, 6, "First row has seq 6"),
-
- stop(Consumer),
-
- ChangesArgs2 = #changes_args{
- filter = "_doc_ids",
- since = 6
- },
- Consumer2 = spawn_consumer(test_db_name(), ChangesArgs2, Req),
-
- {Rows2, LastSeq2} = wait_finished(Consumer2),
- {ok, Db3} = couch_db:open_int(test_db_name(), []),
- UpSeq2 = couch_db:get_update_seq(Db3),
- couch_db:close(Db3),
- etap:is(LastSeq2, UpSeq2, "LastSeq is same as database update seq number"),
- etap:is(length(Rows2), 0, "Received 0 change rows"),
-
- stop(Consumer2),
-
- {ok, _Rev3_3} = save_doc(
- {[{<<"_id">>, <<"doc3">>}, {<<"_deleted">>, true}, {<<"_rev">>, Rev3_2}]}),
-
- ChangesArgs3 = #changes_args{
- filter = "_doc_ids",
- since = 9
- },
- Consumer3 = spawn_consumer(test_db_name(), ChangesArgs3, Req),
-
- {Rows3, LastSeq3} = wait_finished(Consumer3),
- {ok, Db4} = couch_db:open_int(test_db_name(), []),
- UpSeq3 = couch_db:get_update_seq(Db4),
- couch_db:close(Db4),
- etap:is(LastSeq3, UpSeq3, "LastSeq is same as database update seq number"),
- etap:is(length(Rows3), 1, "Received 1 changes rows"),
- etap:is(
- [#row{seq = LastSeq3, id = <<"doc3">>, deleted = true}],
- Rows3,
- "Received row with doc3 deleted"),
-
- stop(Consumer3),
-
- delete_db().
-
-
-test_by_doc_ids_continuous() ->
- create_db(test_db_name()),
-
- {ok, _Rev1} = save_doc({[{<<"_id">>, <<"doc1">>}]}),
- {ok, _Rev2} = save_doc({[{<<"_id">>, <<"doc2">>}]}),
- {ok, Rev3} = save_doc({[{<<"_id">>, <<"doc3">>}]}),
- {ok, Rev4} = save_doc({[{<<"_id">>, <<"doc4">>}]}),
- {ok, _Rev5} = save_doc({[{<<"_id">>, <<"doc5">>}]}),
- {ok, Rev3_2} = save_doc({[{<<"_id">>, <<"doc3">>}, {<<"_rev">>, Rev3}]}),
- {ok, _Rev6} = save_doc({[{<<"_id">>, <<"doc6">>}]}),
- {ok, _Rev7} = save_doc({[{<<"_id">>, <<"doc7">>}]}),
- {ok, _Rev8} = save_doc({[{<<"_id">>, <<"doc8">>}]}),
-
- ChangesArgs = #changes_args{
- filter = "_doc_ids",
- feed = "continuous"
- },
- DocIds = [<<"doc3">>, <<"doc4">>, <<"doc9999">>],
- Req = {json_req, {[{<<"doc_ids">>, DocIds}]}},
- Consumer = spawn_consumer(test_db_name(), ChangesArgs, Req),
-
- pause(Consumer),
- Rows = get_rows(Consumer),
-
- etap:is(length(Rows), 2, "Received 2 changes rows"),
- [#row{seq = Seq1, id = Id1}, #row{seq = Seq2, id = Id2}] = Rows,
- etap:is(Id1, <<"doc4">>, "First row is for doc doc4"),
- etap:is(Seq1, 4, "First row has seq 4"),
- etap:is(Id2, <<"doc3">>, "Second row is for doc doc3"),
- etap:is(Seq2, 6, "Second row has seq 6"),
-
- clear_rows(Consumer),
- {ok, _Rev9} = save_doc({[{<<"_id">>, <<"doc9">>}]}),
- {ok, _Rev10} = save_doc({[{<<"_id">>, <<"doc10">>}]}),
- unpause(Consumer),
- pause(Consumer),
- etap:is(get_rows(Consumer), [], "No new rows"),
-
- {ok, Rev4_2} = save_doc({[{<<"_id">>, <<"doc4">>}, {<<"_rev">>, Rev4}]}),
- {ok, _Rev11} = save_doc({[{<<"_id">>, <<"doc11">>}]}),
- {ok, _Rev4_3} = save_doc({[{<<"_id">>, <<"doc4">>}, {<<"_rev">>, Rev4_2}]}),
- {ok, _Rev12} = save_doc({[{<<"_id">>, <<"doc12">>}]}),
- {ok, Rev3_3} = save_doc({[{<<"_id">>, <<"doc3">>}, {<<"_rev">>, Rev3_2}]}),
- unpause(Consumer),
- pause(Consumer),
-
- NewRows = get_rows(Consumer),
- etap:is(length(NewRows), 2, "Received 2 new rows"),
- [Row14, Row16] = NewRows,
- etap:is(Row14#row.seq, 14, "First row has seq 14"),
- etap:is(Row14#row.id, <<"doc4">>, "First row is for doc doc4"),
- etap:is(Row16#row.seq, 16, "Second row has seq 16"),
- etap:is(Row16#row.id, <<"doc3">>, "Second row is for doc doc3"),
-
- clear_rows(Consumer),
- {ok, _Rev3_4} = save_doc({[{<<"_id">>, <<"doc3">>}, {<<"_rev">>, Rev3_3}]}),
- unpause(Consumer),
- pause(Consumer),
- etap:is(get_rows(Consumer), [#row{seq = 17, id = <<"doc3">>}],
- "Got row for seq 17, doc doc3"),
-
- unpause(Consumer),
- stop(Consumer),
- delete_db().
-
-
-test_design_docs_only() ->
- create_db(test_db_name()),
-
- {ok, _Rev1} = save_doc({[{<<"_id">>, <<"doc1">>}]}),
- {ok, _Rev2} = save_doc({[{<<"_id">>, <<"doc2">>}]}),
- {ok, Rev3} = save_doc({[{<<"_id">>, <<"_design/foo">>}]}),
-
- ChangesArgs = #changes_args{
- filter = "_design"
- },
- Consumer = spawn_consumer(test_db_name(), ChangesArgs, {json_req, null}),
-
- {Rows, LastSeq} = wait_finished(Consumer),
- {ok, Db2} = couch_db:open_int(test_db_name(), []),
- UpSeq = couch_db:get_update_seq(Db2),
- couch_db:close(Db2),
-
- etap:is(LastSeq, UpSeq, "LastSeq is same as database update seq number"),
- etap:is(length(Rows), 1, "Received 1 changes rows"),
- etap:is(Rows, [#row{seq = 3, id = <<"_design/foo">>}], "Received row with ddoc"),
-
- stop(Consumer),
-
- {ok, _Rev3_2} = save_doc(
- {[{<<"_id">>, <<"_design/foo">>}, {<<"_rev">>, Rev3},
- {<<"_deleted">>, true}]}),
-
- Consumer2 = spawn_consumer(test_db_name(), ChangesArgs, {json_req, null}),
-
- {Rows2, LastSeq2} = wait_finished(Consumer2),
- UpSeq2 = UpSeq + 1,
-
- etap:is(LastSeq2, UpSeq2, "LastSeq is same as database update seq number"),
- etap:is(length(Rows2), 1, "Received 1 changes rows"),
- etap:is(
- Rows2,
- [#row{seq = 4, id = <<"_design/foo">>, deleted = true}],
- "Received row with deleted ddoc"),
-
- stop(Consumer2),
- delete_db().
-
-test_heartbeat() ->
- create_db(test_db_name()),
-
- {ok, _} = save_doc({[
- {<<"_id">>, <<"_design/foo">>},
- {<<"language">>, <<"javascript">>},
- {<<"filters">>, {[
- {<<"foo">>, <<"function(doc) { if ((doc._id == 'doc10') ||
- (doc._id == 'doc11') ||
- (doc._id == 'doc12')) {
- return true;
- } else {
- return false;
- }}">>
- }]}}
- ]}),
-
- ChangesArgs = #changes_args{
- filter = "foo/foo",
- feed = "continuous",
- timeout = 10000,
- heartbeat = 1000
- },
- Consumer = spawn_consumer(test_db_name(), ChangesArgs, {json_req, null}),
-
- {ok, _Rev1} = save_doc({[{<<"_id">>, <<"doc1">>}]}),
- timer:sleep(200),
- {ok, _Rev2} = save_doc({[{<<"_id">>, <<"doc2">>}]}),
- timer:sleep(200),
- {ok, _Rev3} = save_doc({[{<<"_id">>, <<"doc3">>}]}),
- timer:sleep(200),
- {ok, _Rev4} = save_doc({[{<<"_id">>, <<"doc4">>}]}),
- timer:sleep(200),
- {ok, _Rev5} = save_doc({[{<<"_id">>, <<"doc5">>}]}),
- timer:sleep(200),
- {ok, _Rev6} = save_doc({[{<<"_id">>, <<"doc6">>}]}),
- timer:sleep(200),
- {ok, _Rev7} = save_doc({[{<<"_id">>, <<"doc7">>}]}),
- timer:sleep(200),
- {ok, _Rev8} = save_doc({[{<<"_id">>, <<"doc8">>}]}),
- timer:sleep(200),
- {ok, _Rev9} = save_doc({[{<<"_id">>, <<"doc9">>}]}),
- Heartbeats = get_heartbeats(Consumer),
- etap:is(Heartbeats, 2, "Received 2 heartbeats now"),
- {ok, _Rev10} = save_doc({[{<<"_id">>, <<"doc10">>}]}),
- timer:sleep(200),
- {ok, _Rev11} = save_doc({[{<<"_id">>, <<"doc11">>}]}),
- timer:sleep(200),
- {ok, _Rev12} = save_doc({[{<<"_id">>, <<"doc12">>}]}),
- Heartbeats2 = get_heartbeats(Consumer),
- etap:is(Heartbeats2, 3, "Received 3 heartbeats now"),
- Rows = get_rows(Consumer),
- etap:is(length(Rows), 3, "Received 3 changes rows"),
-
- {ok, _Rev13} = save_doc({[{<<"_id">>, <<"doc13">>}]}),
- timer:sleep(200),
- {ok, _Rev14} = save_doc({[{<<"_id">>, <<"doc14">>}]}),
- timer:sleep(200),
- Heartbeats3 = get_heartbeats(Consumer),
- etap:is(Heartbeats3, 6, "Received 6 heartbeats now"),
- stop(Consumer),
- delete_db().
-
-
-db() ->
- {ok, Db} = couch_db:reopen(get(current_db)),
- Db.
-
-
-save_doc(Json) ->
- Doc = couch_doc:from_json_obj(Json),
- {ok, Rev} = couch_db:update_doc(db(), Doc, []),
- {ok, couch_doc:rev_to_str(Rev)}.
-
-
-get_rows(Consumer) ->
- Ref = make_ref(),
- Consumer ! {get_rows, Ref},
- receive
- {rows, Ref, Rows} ->
- Rows
- after 3000 ->
- etap:bail("Timeout getting rows from consumer")
- end.
-
-get_heartbeats(Consumer) ->
- Ref = make_ref(),
- Consumer ! {get_heartbeats, Ref},
- receive
- {hearthbeats, Ref, HeartBeats} ->
- HeartBeats
- after 3000 ->
- etap:bail("Timeout getting heartbeats from consumer")
- end.
-
-
-clear_rows(Consumer) ->
- Ref = make_ref(),
- Consumer ! {reset, Ref},
- receive
- {ok, Ref} ->
- ok
- after 3000 ->
- etap:bail("Timeout clearing consumer rows")
- end.
-
-
-stop(Consumer) ->
- Ref = make_ref(),
- Consumer ! {stop, Ref},
- receive
- {ok, Ref} ->
- ok
- after 3000 ->
- etap:bail("Timeout stopping consumer")
- end.
-
-
-pause(Consumer) ->
- Ref = make_ref(),
- Consumer ! {pause, Ref},
- receive
- {paused, Ref} ->
- ok
- after 3000 ->
- etap:bail("Timeout pausing consumer")
- end.
-
-
-unpause(Consumer) ->
- Ref = make_ref(),
- Consumer ! {continue, Ref},
- receive
- {ok, Ref} ->
- ok
- after 3000 ->
- etap:bail("Timeout unpausing consumer")
- end.
-
-
-wait_finished(_Consumer) ->
- receive
- {consumer_finished, Rows, LastSeq} ->
- {Rows, LastSeq}
- after 30000 ->
- etap:bail("Timeout waiting for consumer to finish")
- end.
-
-
-spawn_consumer(DbName, ChangesArgs0, Req) ->
- Parent = self(),
- spawn(fun() ->
- put(heartbeat_count, 0),
- Callback = fun({change, {Change}, _}, _, Acc) ->
- Id = couch_util:get_value(<<"id">>, Change),
- Seq = couch_util:get_value(<<"seq">>, Change),
- Del = couch_util:get_value(<<"deleted">>, Change, false),
- [#row{id = Id, seq = Seq, deleted = Del} | Acc];
- ({stop, LastSeq}, _, Acc) ->
- Parent ! {consumer_finished, lists:reverse(Acc), LastSeq},
- stop_loop(Parent, Acc);
- (timeout, _, Acc) ->
- put(heartbeat_count, get(heartbeat_count) + 1),
- maybe_pause(Parent, Acc);
- (_, _, Acc) ->
- maybe_pause(Parent, Acc)
- end,
- {ok, Db} = couch_db:open_int(DbName, []),
- ChangesArgs = case (ChangesArgs0#changes_args.timeout =:= undefined)
- andalso (ChangesArgs0#changes_args.heartbeat =:= undefined) of
- true ->
- ChangesArgs0#changes_args{timeout = 10, heartbeat = 10};
- false ->
- ChangesArgs0
- end,
- FeedFun = couch_changes:handle_changes(ChangesArgs, Req, Db),
- try
- FeedFun({Callback, []})
- catch throw:{stop, _} ->
- ok
- end,
- catch couch_db:close(Db)
- end).
-
-
-maybe_pause(Parent, Acc) ->
- receive
- {get_rows, Ref} ->
- Parent ! {rows, Ref, lists:reverse(Acc)},
- maybe_pause(Parent, Acc);
- {get_heartbeats, Ref} ->
- Parent ! {hearthbeats, Ref, get(heartbeat_count)},
- maybe_pause(Parent, Acc);
- {reset, Ref} ->
- Parent ! {ok, Ref},
- maybe_pause(Parent, []);
- {pause, Ref} ->
- Parent ! {paused, Ref},
- pause_loop(Parent, Acc);
- {stop, Ref} ->
- Parent ! {ok, Ref},
- throw({stop, Acc})
- after 0 ->
- Acc
- end.
-
-
-pause_loop(Parent, Acc) ->
- receive
- {stop, Ref} ->
- Parent ! {ok, Ref},
- throw({stop, Acc});
- {reset, Ref} ->
- Parent ! {ok, Ref},
- pause_loop(Parent, []);
- {continue, Ref} ->
- Parent ! {ok, Ref},
- Acc;
- {get_rows, Ref} ->
- Parent ! {rows, Ref, lists:reverse(Acc)},
- pause_loop(Parent, Acc)
- end.
-
-
-stop_loop(Parent, Acc) ->
- receive
- {get_rows, Ref} ->
- Parent ! {rows, Ref, lists:reverse(Acc)},
- stop_loop(Parent, Acc);
- {stop, Ref} ->
- Parent ! {ok, Ref},
- Acc
- end.
-
-
-create_db(DbName) ->
- Options = [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}, overwrite],
- {ok, Db} = couch_db:create(DbName, Options),
- put(current_db, Db).
-
-
-delete_db() ->
- Db = db(),
- Options = [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}],
- ok = couch_server:delete(couch_db:name(Db), Options),
- put(current_db, undefined).
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/074-doc-update-conflicts.t
----------------------------------------------------------------------
diff --git a/test/etap/074-doc-update-conflicts.t b/test/etap/074-doc-update-conflicts.t
deleted file mode 100755
index a7468e8..0000000
--- a/test/etap/074-doc-update-conflicts.t
+++ /dev/null
@@ -1,208 +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.
-
--record(user_ctx, {
- name = null,
- roles = [],
- handler
-}).
-
--define(i2l(I), integer_to_list(I)).
-
-test_db_name() -> <<"couch_test_update_conflicts">>.
-
-
-main(_) ->
- test_util:run(25, fun() -> test() end).
-
-
-test() ->
- test_util:start_couch(),
- config:set("couchdb", "delayed_commits", "true", false),
-
- lists:foreach(
- fun(NumClients) -> test_concurrent_doc_update(NumClients) end,
- [100, 500, 1000]),
-
- test_bulk_delete_create(),
-
- ok.
-
-
-% Verify that if multiple clients try to update the same document
-% simultaneously, only one of them will get success response and all
-% the other ones will get a conflict error. Also validate that the
-% client which got the success response got its document version
-% persisted into the database.
-test_concurrent_doc_update(NumClients) ->
- {ok, Db} = create_db(test_db_name()),
- Doc = couch_doc:from_json_obj({[
- {<<"_id">>, <<"foobar">>},
- {<<"value">>, 0}
- ]}),
- {ok, Rev} = couch_db:update_doc(Db, Doc, []),
- ok = couch_db:close(Db),
- RevStr = couch_doc:rev_to_str(Rev),
- etap:diag("Created first revision of test document"),
-
- etap:diag("Spawning " ++ ?i2l(NumClients) ++
- " clients to update the document"),
- Clients = lists:map(
- fun(Value) ->
- ClientDoc = couch_doc:from_json_obj({[
- {<<"_id">>, <<"foobar">>},
- {<<"_rev">>, RevStr},
- {<<"value">>, Value}
- ]}),
- Pid = spawn_client(ClientDoc),
- {Value, Pid, erlang:monitor(process, Pid)}
- end,
- lists:seq(1, NumClients)),
-
- lists:foreach(fun({_, Pid, _}) -> Pid ! go end, Clients),
- etap:diag("Waiting for clients to finish"),
-
- {NumConflicts, SavedValue} = lists:foldl(
- fun({Value, Pid, MonRef}, {AccConflicts, AccValue}) ->
- receive
- {'DOWN', MonRef, process, Pid, {ok, _NewRev}} ->
- {AccConflicts, Value};
- {'DOWN', MonRef, process, Pid, conflict} ->
- {AccConflicts + 1, AccValue};
- {'DOWN', MonRef, process, Pid, Error} ->
- etap:bail("Client " ++ ?i2l(Value) ++
- " got update error: " ++ couch_util:to_list(Error))
- after 60000 ->
- etap:bail("Timeout waiting for client " ++ ?i2l(Value) ++ " to die")
- end
- end,
- {0, nil},
- Clients),
-
- etap:diag("Verifying client results"),
- etap:is(
- NumConflicts,
- NumClients - 1,
- "Got " ++ ?i2l(NumClients - 1) ++ " client conflicts"),
-
- {ok, Db2} = couch_db:open_int(test_db_name(), []),
- {ok, Leaves} = couch_db:open_doc_revs(Db2, <<"foobar">>, all, []),
- ok = couch_db:close(Db2),
- etap:is(length(Leaves), 1, "Only one document revision was persisted"),
- [{ok, Doc2}] = Leaves,
- {JsonDoc} = couch_doc:to_json_obj(Doc2, []),
- etap:is(
- couch_util:get_value(<<"value">>, JsonDoc),
- SavedValue,
- "Persisted doc has the right value"),
-
- ok = timer:sleep(1000),
- etap:diag("Restarting the server"),
- ok = test_util:stop_couch(),
- ok = timer:sleep(1000),
- ok = test_util:start_couch(),
-
- {ok, Db3} = couch_db:open_int(test_db_name(), []),
- {ok, Leaves2} = couch_db:open_doc_revs(Db3, <<"foobar">>, all, []),
- ok = couch_db:close(Db3),
- etap:is(length(Leaves2), 1, "Only one document revision was persisted"),
- [{ok, Doc3}] = Leaves,
- etap:is(Doc3, Doc2, "Got same document after server restart"),
-
- delete_db(Db3).
-
-
-% COUCHDB-188
-test_bulk_delete_create() ->
- {ok, Db} = create_db(test_db_name()),
- Doc = couch_doc:from_json_obj({[
- {<<"_id">>, <<"foobar">>},
- {<<"value">>, 0}
- ]}),
- {ok, Rev} = couch_db:update_doc(Db, Doc, []),
-
- DeletedDoc = couch_doc:from_json_obj({[
- {<<"_id">>, <<"foobar">>},
- {<<"_rev">>, couch_doc:rev_to_str(Rev)},
- {<<"_deleted">>, true}
- ]}),
- NewDoc = couch_doc:from_json_obj({[
- {<<"_id">>, <<"foobar">>},
- {<<"value">>, 666}
- ]}),
-
- {ok, Db2} = couch_db:reopen(Db),
- {ok, Results} = couch_db:update_docs(Db2, [DeletedDoc, NewDoc], []),
- ok = couch_db:close(Db2),
-
- etap:is(length([ok || {ok, _} <- Results]), 2,
- "Deleted and non-deleted versions got an ok reply"),
-
- [{ok, Rev1}, {ok, Rev2}] = Results,
- {ok, Db3} = couch_db:open_int(test_db_name(), []),
-
- {ok, [{ok, Doc1}]} = couch_db:open_doc_revs(
- Db3, <<"foobar">>, [Rev1], [conflicts, deleted_conflicts]),
- {ok, [{ok, Doc2}]} = couch_db:open_doc_revs(
- Db3, <<"foobar">>, [Rev2], [conflicts, deleted_conflicts]),
- ok = couch_db:close(Db3),
-
- {Doc1Props} = couch_doc:to_json_obj(Doc1, []),
- {Doc2Props} = couch_doc:to_json_obj(Doc2, []),
-
- etap:is(couch_util:get_value(<<"_deleted">>, Doc1Props), true,
- "Document was deleted"),
- etap:is(couch_util:get_value(<<"_deleted">>, Doc2Props), undefined,
- "New document not flagged as deleted"),
- etap:is(couch_util:get_value(<<"value">>, Doc2Props), 666,
- "New leaf revision has the right value"),
- etap:is(couch_util:get_value(<<"_conflicts">>, Doc1Props), undefined,
- "Deleted document has no conflicts"),
- etap:is(couch_util:get_value(<<"_deleted_conflicts">>, Doc1Props), undefined,
- "Deleted document has no deleted conflicts"),
- etap:is(couch_util:get_value(<<"_conflicts">>, Doc2Props), undefined,
- "New leaf revision doesn't have conflicts"),
- etap:is(couch_util:get_value(<<"_deleted_conflicts">>, Doc2Props), undefined,
- "New leaf revision doesn't have deleted conflicts"),
-
- etap:is(element(1, Rev1), 2, "Deleted revision has position 2"),
- etap:is(element(1, Rev2), 1, "New leaf revision has position 1"),
-
- delete_db(Db2).
-
-
-spawn_client(Doc) ->
- spawn(fun() ->
- {ok, Db} = couch_db:open_int(test_db_name(), []),
- receive go -> ok end,
- erlang:yield(),
- Result = try
- couch_db:update_doc(Db, Doc, [])
- catch _:Error ->
- Error
- end,
- ok = couch_db:close(Db),
- exit(Result)
- end).
-
-
-create_db(DbName) ->
- couch_db:create(
- DbName,
- [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}, overwrite]).
-
-
-delete_db(Db) ->
- ok = couch_server:delete(
- couch_db:name(Db), [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}]).
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/075-auth-cache.t
----------------------------------------------------------------------
diff --git a/test/etap/075-auth-cache.t b/test/etap/075-auth-cache.t
deleted file mode 100755
index 4d79134..0000000
--- a/test/etap/075-auth-cache.t
+++ /dev/null
@@ -1,274 +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.
-
--record(user_ctx, {
- name = null,
- roles = [],
- handler
-}).
-
--record(db, {
- main_pid = nil,
- compactor_pid = nil,
- instance_start_time, % number of microsecs since jan 1 1970 as a binary string
- fd,
- fd_monitor,
- header,
- committed_update_seq,
- id_tree,
- seq_tree,
- local_tree,
- update_seq,
- name,
- filepath,
- validate_doc_funs = [],
- security = [],
- security_ptr = nil,
- user_ctx = #user_ctx{},
- waiting_delayed_commit = nil,
- revs_limit = 1000,
- fsync_options = [],
- options = [],
- compression,
- before_doc_update = nil, % nil | fun(Doc, Db) -> NewDoc
- after_doc_read = nil % nil | fun(Doc, Db) -> NewDoc
-}).
-
-auth_db_name() -> <<"couch_test_auth_db">>.
-auth_db_2_name() -> <<"couch_test_auth_db_2">>.
-salt() -> <<"SALT">>.
-
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(19),
- 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() ->
- test_util:start_couch(),
- OrigName = config:get("couch_httpd_auth", "authentication_db"),
- config:set(
- "couch_httpd_auth", "authentication_db",
- binary_to_list(auth_db_name()), false),
- delete_db(auth_db_name()),
- delete_db(auth_db_2_name()),
-
- test_auth_db_crash(),
-
- config:set("couch_httpd_auth", "authentication_db", OrigName, false),
- delete_db(auth_db_name()),
- delete_db(auth_db_2_name()),
- couch_server_sup:stop(),
- ok.
-
-
-test_auth_db_crash() ->
- Creds0 = couch_auth_cache:get_user_creds("joe"),
- etap:is(Creds0, nil, "Got nil when getting joe's credentials"),
-
- etap:diag("Adding first version of Joe's user doc"),
- PasswordHash1 = hash_password("pass1"),
- {ok, Rev1} = update_user_doc(auth_db_name(), "joe", "pass1"),
-
- Creds1 = couch_auth_cache:get_user_creds("joe"),
- etap:is(is_list(Creds1), true, "Got joe's credentials from cache"),
- etap:is(couch_util:get_value(<<"password_sha">>, Creds1), PasswordHash1,
- "Cached credentials have the right password"),
-
- etap:diag("Updating Joe's user doc password"),
- PasswordHash2 = hash_password("pass2"),
- {ok, _Rev2} = update_user_doc(auth_db_name(), "joe", "pass2", Rev1),
-
- Creds2 = couch_auth_cache:get_user_creds("joe"),
- etap:is(is_list(Creds2), true, "Got joe's credentials from cache"),
- etap:is(couch_util:get_value(<<"password_sha">>, Creds2), PasswordHash2,
- "Cached credentials have the new password"),
-
- etap:diag("Shutting down the auth database process"),
- shutdown_db(auth_db_name()),
-
- {ok, UpdateRev} = get_doc_rev(auth_db_name(), "joe"),
- PasswordHash3 = hash_password("pass3"),
- {ok, _Rev3} = update_user_doc(auth_db_name(), "joe", "pass3", UpdateRev),
-
- etap:is(get_user_doc_password_sha(auth_db_name(), "joe"),
- PasswordHash3,
- "Latest Joe's doc revision has the new password hash"),
-
- Creds3 = couch_auth_cache:get_user_creds("joe"),
- etap:is(is_list(Creds3), true, "Got joe's credentials from cache"),
- etap:is(couch_util:get_value(<<"password_sha">>, Creds3), PasswordHash3,
- "Cached credentials have the new password"),
-
- etap:diag("Deleting Joe's user doc"),
- delete_user_doc(auth_db_name(), "joe"),
- Creds4 = couch_auth_cache:get_user_creds("joe"),
- etap:is(nil, Creds4,
- "Joe's credentials not found in cache after user doc was deleted"),
-
- etap:diag("Adding new user doc for Joe"),
- PasswordHash5 = hash_password("pass5"),
- {ok, _NewRev1} = update_user_doc(auth_db_name(), "joe", "pass5"),
-
- Creds5 = couch_auth_cache:get_user_creds("joe"),
- etap:is(is_list(Creds5), true, "Got joe's credentials from cache"),
- etap:is(couch_util:get_value(<<"password_sha">>, Creds5), PasswordHash5,
- "Cached credentials have the right password"),
-
- full_commit(auth_db_name()),
-
- etap:diag("Changing the auth database"),
- config:set(
- "couch_httpd_auth", "authentication_db",
- binary_to_list(auth_db_2_name()), false),
- ok = timer:sleep(500),
-
- Creds6 = couch_auth_cache:get_user_creds("joe"),
- etap:is(nil, Creds6,
- "Joe's credentials not found in cache after auth database changed"),
-
- etap:diag("Adding first version of Joe's user doc to new auth database"),
- PasswordHash7 = hash_password("pass7"),
- {ok, _} = update_user_doc(auth_db_2_name(), "joe", "pass7"),
-
- Creds7 = couch_auth_cache:get_user_creds("joe"),
- etap:is(is_list(Creds7), true, "Got joe's credentials from cache"),
- etap:is(couch_util:get_value(<<"password_sha">>, Creds7), PasswordHash7,
- "Cached credentials have the right password"),
-
- etap:diag("Shutting down the auth database process"),
- shutdown_db(auth_db_2_name()),
-
- {ok, UpdateRev2} = get_doc_rev(auth_db_2_name(), "joe"),
- PasswordHash8 = hash_password("pass8"),
- {ok, _Rev8} = update_user_doc(auth_db_2_name(), "joe", "pass8", UpdateRev2),
-
- etap:is(get_user_doc_password_sha(auth_db_2_name(), "joe"),
- PasswordHash8,
- "Latest Joe's doc revision has the new password hash"),
-
- Creds8 = couch_auth_cache:get_user_creds("joe"),
- etap:is(is_list(Creds8), true, "Got joe's credentials from cache"),
- etap:is(couch_util:get_value(<<"password_sha">>, Creds8), PasswordHash8,
- "Cached credentials have the new password"),
-
- etap:diag("Changing the auth database again"),
- config:set(
- "couch_httpd_auth", "authentication_db",
- binary_to_list(auth_db_name()), false),
- ok = timer:sleep(500),
-
- Creds9 = couch_auth_cache:get_user_creds("joe"),
- etap:is(Creds9, Creds5,
- "Got same credentials as before the firt auth database change"),
- etap:is(couch_util:get_value(<<"password_sha">>, Creds9), PasswordHash5,
- "Cached credentials have the right password"),
- ok.
-
-
-update_user_doc(DbName, UserName, Password) ->
- update_user_doc(DbName, UserName, Password, nil).
-
-update_user_doc(DbName, UserName, Password, Rev) ->
- User = iolist_to_binary(UserName),
- Doc = couch_doc:from_json_obj({[
- {<<"_id">>, <<"org.couchdb.user:", User/binary>>},
- {<<"name">>, User},
- {<<"type">>, <<"user">>},
- {<<"salt">>, salt()},
- {<<"password_sha">>, hash_password(Password)},
- {<<"roles">>, []}
- ] ++ case Rev of
- nil -> [];
- _ -> [{<<"_rev">>, Rev}]
- end}),
- {ok, AuthDb} = open_auth_db(DbName),
- {ok, NewRev} = couch_db:update_doc(AuthDb, Doc, []),
- ok = couch_db:close(AuthDb),
- {ok, couch_doc:rev_to_str(NewRev)}.
-
-
-hash_password(Password) ->
- list_to_binary(
- couch_util:to_hex(crypto:sha(iolist_to_binary([Password, salt()])))).
-
-
-shutdown_db(DbName) ->
- {ok, AuthDb} = open_auth_db(DbName),
- ok = couch_db:close(AuthDb),
- couch_util:shutdown_sync(AuthDb#db.main_pid),
- ok = timer:sleep(1000).
-
-
-get_doc_rev(DbName, UserName) ->
- DocId = iolist_to_binary([<<"org.couchdb.user:">>, UserName]),
- {ok, AuthDb} = open_auth_db(DbName),
- UpdateRev =
- case couch_db:open_doc(AuthDb, DocId, []) of
- {ok, Doc} ->
- {Props} = couch_doc:to_json_obj(Doc, []),
- couch_util:get_value(<<"_rev">>, Props);
- {not_found, missing} ->
- nil
- end,
- ok = couch_db:close(AuthDb),
- {ok, UpdateRev}.
-
-
-get_user_doc_password_sha(DbName, UserName) ->
- DocId = iolist_to_binary([<<"org.couchdb.user:">>, UserName]),
- {ok, AuthDb} = open_auth_db(DbName),
- {ok, Doc} = couch_db:open_doc(AuthDb, DocId, []),
- ok = couch_db:close(AuthDb),
- {Props} = couch_doc:to_json_obj(Doc, []),
- couch_util:get_value(<<"password_sha">>, Props).
-
-
-delete_user_doc(DbName, UserName) ->
- DocId = iolist_to_binary([<<"org.couchdb.user:">>, UserName]),
- {ok, AuthDb} = open_auth_db(DbName),
- {ok, Doc} = couch_db:open_doc(AuthDb, DocId, []),
- {Props} = couch_doc:to_json_obj(Doc, []),
- DeletedDoc = couch_doc:from_json_obj({[
- {<<"_id">>, DocId},
- {<<"_rev">>, couch_util:get_value(<<"_rev">>, Props)},
- {<<"_deleted">>, true}
- ]}),
- {ok, _} = couch_db:update_doc(AuthDb, DeletedDoc, []),
- ok = couch_db:close(AuthDb).
-
-
-full_commit(DbName) ->
- {ok, AuthDb} = open_auth_db(DbName),
- {ok, _} = couch_db:ensure_full_commit(AuthDb),
- ok = couch_db:close(AuthDb).
-
-
-open_auth_db(DbName) ->
- couch_db:open_int(
- DbName, [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}]).
-
-
-delete_db(Name) ->
- couch_server:delete(
- Name, [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}]).
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/076-file-compression.t
----------------------------------------------------------------------
diff --git a/test/etap/076-file-compression.t b/test/etap/076-file-compression.t
deleted file mode 100755
index 499aae5..0000000
--- a/test/etap/076-file-compression.t
+++ /dev/null
@@ -1,183 +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.
-
--mode(compile).
-
--record(user_ctx, {
- name = null,
- roles = [],
- handler
-}).
-
-test_db_name() -> <<"couch_test_file_compression">>.
-ddoc_id() -> <<"_design/test">>.
-num_docs() -> 5000.
-
-
-main(_) ->
- test_util:init_code_path(),
-
- etap:plan(10),
- 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() ->
- test_util:start_couch(),
- config:set("couchdb", "file_compression", "none", false),
-
- create_database(),
- compact_db(),
- compact_view(),
- DbDiskSize1 = db_disk_size(),
- ViewDiskSize1 = view_disk_size(),
-
- config:set("couchdb", "file_compression", "snappy", false),
- compact_db(),
- compact_view(),
- DbDiskSize2 = db_disk_size(),
- ViewDiskSize2 = view_disk_size(),
-
- etap:is(DbDiskSize2 < DbDiskSize1, true, "Database disk size decreased"),
- etap:is(ViewDiskSize2 < ViewDiskSize1, true, "Index disk size decreased"),
-
- config:set("couchdb", "file_compression", "deflate_9", false),
- compact_db(),
- compact_view(),
- DbDiskSize3 = db_disk_size(),
- ViewDiskSize3 = view_disk_size(),
-
- etap:is(DbDiskSize3 < DbDiskSize2, true, "Database disk size decreased again"),
- etap:is(ViewDiskSize3 < ViewDiskSize2, true, "Index disk size decreased again"),
-
- config:set("couchdb", "file_compression", "deflate_1", false),
- compact_db(),
- compact_view(),
- DbDiskSize4 = db_disk_size(),
- ViewDiskSize4 = view_disk_size(),
-
- etap:is(DbDiskSize4 > DbDiskSize3, true, "Database disk size increased"),
- etap:is(ViewDiskSize4 > ViewDiskSize3, true, "Index disk size increased"),
-
- config:set("couchdb", "file_compression", "snappy", false),
- compact_db(),
- compact_view(),
- DbDiskSize5 = db_disk_size(),
- ViewDiskSize5 = view_disk_size(),
-
- etap:is(DbDiskSize5 > DbDiskSize4, true, "Database disk size increased again"),
- etap:is(ViewDiskSize5 > ViewDiskSize4, true, "Index disk size increased again"),
-
- config:set("couchdb", "file_compression", "none", false),
- compact_db(),
- compact_view(),
- DbDiskSize6 = db_disk_size(),
- ViewDiskSize6 = view_disk_size(),
-
- etap:is(DbDiskSize6 > DbDiskSize5, true, "Database disk size increased again"),
- etap:is(ViewDiskSize6 > ViewDiskSize5, true, "Index disk size increased again"),
-
- delete_db(),
- couch_server_sup:stop(),
- ok.
-
-
-create_database() ->
- {ok, Db} = couch_db:create(
- test_db_name(),
- [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}, overwrite]),
- ok = populate_db(Db, num_docs()),
- DDoc = couch_doc:from_json_obj({[
- {<<"_id">>, ddoc_id()},
- {<<"language">>, <<"javascript">>},
- {<<"views">>, {[
- {<<"view1">>, {[
- {<<"map">>, <<"function(doc) { emit(doc._id, doc.string); }">>}
- ]}}
- ]}
- }
- ]}),
- {ok, _} = couch_db:update_doc(Db, DDoc, []),
- refresh_index(),
- ok = couch_db:close(Db).
-
-
-populate_db(_Db, NumDocs) when NumDocs =< 0 ->
- ok;
-populate_db(Db, NumDocs) ->
- Docs = lists:map(
- fun(_) ->
- couch_doc:from_json_obj({[
- {<<"_id">>, couch_uuids:random()},
- {<<"string">>, list_to_binary(lists:duplicate(1000, $X))}
- ]})
- end,
- lists:seq(1, 500)),
- {ok, _} = couch_db:update_docs(Db, Docs, []),
- populate_db(Db, NumDocs - 500).
-
-
-refresh_index() ->
- {ok, Db} = couch_db:open_int(test_db_name(), []),
- {ok, DDoc} = couch_db:open_doc(Db, ddoc_id(), [ejson_body]),
- couch_mrview:query_view(Db, DDoc, <<"view1">>, [{stale, false}]),
- ok = couch_db:close(Db).
-
-
-compact_db() ->
- {ok, Db} = couch_db:open_int(test_db_name(), []),
- {ok, CPid} = couch_db:start_compact(Db),
- case couch_db:wait_for_compaction(Db, 120000) of
- timeout -> etap:bail("Timeout waiting for database compaction");
- ok -> ok
- end,
- ok = couch_db:close(Db).
-
-
-compact_view() ->
- {ok, MonRef} = couch_mrview:compact(test_db_name(), ddoc_id(), [monitor]),
- receive
- {'DOWN', MonRef, process, _CompactPid, normal} ->
- ok;
- {'DOWN', MonRef, process, _CompactPid, Reason} ->
- etap:bail("Error compacting view group: " ++ couch_util:to_list(Reason))
- after 120000 ->
- etap:bail("Timeout waiting for view group compaction")
- end.
-
-
-db_disk_size() ->
- {ok, Db} = couch_db:open_int(test_db_name(), []),
- {ok, Info} = couch_db:get_db_info(Db),
- ok = couch_db:close(Db),
- couch_util:get_value(disk_size, Info).
-
-
-view_disk_size() ->
- {ok, Db} = couch_db:open_int(test_db_name(), []),
- {ok, DDoc} = couch_db:open_doc(Db, ddoc_id(), [ejson_body]),
- {ok, Info} = couch_mrview:get_info(Db, DDoc),
- ok = couch_db:close(Db),
- couch_util:get_value(disk_size, Info).
-
-
-delete_db() ->
- ok = couch_server:delete(
- test_db_name(), [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}]).
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/077-couch-db-fast-db-delete-create.t
----------------------------------------------------------------------
diff --git a/test/etap/077-couch-db-fast-db-delete-create.t b/test/etap/077-couch-db-fast-db-delete-create.t
deleted file mode 100644
index 4ba5c56..0000000
--- a/test/etap/077-couch-db-fast-db-delete-create.t
+++ /dev/null
@@ -1,50 +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:run(1, fun() -> test() end).
-
-
-loop(0) ->
- ok;
-loop(N) ->
- ok = cycle(),
- loop(N - 1).
-
-
-cycle() ->
- {ok, Db} = couch_db:create(<<"etap-test-db">>, []),
- % Dirty but only less dirty than importing the #db{} record
- couch_file:close(element(5, Db)),
- ok = couch_server:delete(<<"etap-test-db">>, [sync]),
- ok.
-
-
-test() ->
- test_util:start_couch(),
-
- ok = loop(1),
- ok = loop(10),
- ok = loop(100),
- ok = loop(1000),
-
- % for more thorough testing:
- % ok = loop(10000),
- % ok = loop(100000),
- % ok = loop(1000000),
- % ok = loop(10000000),
-
- etap:is(true, true, "lots of creating and deleting of a database"),
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/080-config-get-set.t
----------------------------------------------------------------------
diff --git a/test/etap/080-config-get-set.t b/test/etap/080-config-get-set.t
deleted file mode 100755
index d727936..0000000
--- a/test/etap/080-config-get-set.t
+++ /dev/null
@@ -1,128 +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.
-
-default_config() ->
- test_util:build_file("etc/couchdb/default_dev.ini").
-
-main(_) ->
- test_util:init_code_path(),
- etap:plan(12),
- 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() ->
- application:set_env(config, ini_files, ["etc/couchdb/default_dev.ini"]),
- application:start(config),
-
-
- % Check that we can get values
-
-
- etap:fun_is(
- fun(List) -> length(List) > 0 end,
- config:all(),
- "Data was loaded from the INI file."
- ),
-
- etap:fun_is(
- fun(List) -> length(List) > 0 end,
- config:get("daemons"),
- "There are settings in the [daemons] section of the INI file."
- ),
-
- etap:is(
- config:get("httpd_design_handlers", "_view"),
- "{couch_mrview_http, handle_view_req}",
- "The {httpd_design_handlers, view} is the expected default."
- ),
-
- etap:is(
- config:get("httpd", "foo", "bar"),
- "bar",
- "Returns the default when key doesn't exist in config."
- ),
-
- etap:is(
- config:get("httpd", "foo"),
- undefined,
- "The default default is the atom 'undefined'."
- ),
-
- etap:is(
- config:get("httpd", "port", "bar"),
- "5984",
- "Only returns the default when the config setting does not exist."
- ),
-
-
- % Check that setting values works.
-
-
- ok = config:set("log", "level", "severe", false),
-
- etap:is(
- config:get("log", "level"),
- "severe",
- "Non persisted changes take effect."
- ),
-
- etap:is(
- config:get("new_section", "bizzle"),
- undefined,
- "Section 'new_section' does not exist."
- ),
-
- ok = config:set("new_section", "bizzle", "bang", false),
-
- etap:is(
- config:get("new_section", "bizzle"),
- "bang",
- "New section 'new_section' was created for a new key/value pair."
- ),
-
-
- % Check that deleting works
-
-
- ok = config:delete("new_section", "bizzle", false),
- etap:is(
- config:get("new_section", "bizzle"),
- undefined,
- "Deleting sets the value to \"\""
- ),
-
-
- % Check ge/set/delete binary strings
-
- ok = config:set(<<"foo">>, <<"bar">>, <<"baz">>, false),
- etap:is(
- config:get(<<"foo">>, <<"bar">>),
- <<"baz">>,
- "Can get and set with binary section and key values."
- ),
- ok = config:delete(<<"foo">>, <<"bar">>, false),
- etap:is(
- config:get(<<"foo">>, <<"bar">>),
- undefined,
- "Deleting with binary section/key pairs sets the value to \"\""
- ),
-
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/081-config-override.1.ini
----------------------------------------------------------------------
diff --git a/test/etap/081-config-override.1.ini b/test/etap/081-config-override.1.ini
deleted file mode 100644
index 55451da..0000000
--- a/test/etap/081-config-override.1.ini
+++ /dev/null
@@ -1,22 +0,0 @@
-; Licensed to the Apache Software Foundation (ASF) under one
-; or more contributor license agreements. See the NOTICE file
-; distributed with this work for additional information
-; regarding copyright ownership. The ASF licenses this file
-; to you 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.
-
-[couchdb]
-max_dbs_open=10
-
-[httpd]
-port=4895
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/081-config-override.2.ini
----------------------------------------------------------------------
diff --git a/test/etap/081-config-override.2.ini b/test/etap/081-config-override.2.ini
deleted file mode 100644
index 5f46357..0000000
--- a/test/etap/081-config-override.2.ini
+++ /dev/null
@@ -1,22 +0,0 @@
-; Licensed to the Apache Software Foundation (ASF) under one
-; or more contributor license agreements. See the NOTICE file
-; distributed with this work for additional information
-; regarding copyright ownership. The ASF licenses this file
-; to you 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.
-
-[httpd]
-port = 80
-
-[fizbang]
-unicode = normalized
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/081-config-override.t
----------------------------------------------------------------------
diff --git a/test/etap/081-config-override.t b/test/etap/081-config-override.t
deleted file mode 100755
index 3a97b66..0000000
--- a/test/etap/081-config-override.t
+++ /dev/null
@@ -1,208 +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.
-
-default_config() ->
- test_util:build_file("etc/couchdb/default_dev.ini").
-
-local_config_1() ->
- test_util:source_file("test/etap/081-config-override.1.ini").
-
-local_config_2() ->
- test_util:source_file("test/etap/081-config-override.2.ini").
-
-local_config_write() ->
- test_util:build_file("test/etap/temp.081").
-
-% Run tests and wait for the config gen_server to shutdown.
-run_tests(IniFiles, Tests) ->
- application:set_env(config, ini_files, IniFiles),
- ok = application:start(config),
- Tests(),
- timer:sleep(1000),
- ok = application:stop(config),
- ok.
-
-main(_) ->
- test_util:init_code_path(),
- etap:plan(17),
-
- 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() ->
-
- CheckStartStop = fun() -> ok end,
- run_tests([default_config()], CheckStartStop),
-
- CheckDefaults = fun() ->
- etap:is(
- config:get("couchdb", "max_dbs_open"),
- "100",
- "{couchdb, max_dbs_open} is 100 by defualt."
- ),
-
- etap:is(
- config:get("httpd","port"),
- "5984",
- "{httpd, port} is 5984 by default"
- ),
-
- etap:is(
- config:get("fizbang", "unicode"),
- undefined,
- "{fizbang, unicode} is undefined by default"
- )
- end,
-
- run_tests([default_config()], CheckDefaults),
-
-
- % Check that subsequent files override values appropriately
-
- CheckOverride = fun() ->
- etap:is(
- config:get("couchdb", "max_dbs_open"),
- "10",
- "{couchdb, max_dbs_open} was overriden with the value 10"
- ),
-
- etap:is(
- config:get("httpd", "port"),
- "4895",
- "{httpd, port} was overriden with the value 4895"
- )
- end,
-
- run_tests([default_config(), local_config_1()], CheckOverride),
-
-
- % Check that overrides can create new sections
-
- CheckOverride2 = fun() ->
- etap:is(
- config:get("httpd", "port"),
- "80",
- "{httpd, port} is overriden with the value 80"
- ),
-
- etap:is(
- config:get("fizbang", "unicode"),
- "normalized",
- "{fizbang, unicode} was created by override INI file"
- )
- end,
-
- run_tests([default_config(), local_config_2()], CheckOverride2),
-
-
- % Check that values can be overriden multiple times
-
- CheckOverride3 = fun() ->
- etap:is(
- config:get("httpd", "port"),
- "80",
- "{httpd, port} value was taken from the last specified INI file."
- )
- end,
-
- run_tests(
- [default_config(), local_config_1(), local_config_2()],
- CheckOverride3
- ),
-
- % Check persistence to last file.
-
- % Empty the file in case it exists.
- {ok, Fd} = file:open(local_config_write(), write),
- ok = file:truncate(Fd),
- ok = file:close(Fd),
-
- % Open and write a value
- CheckCanWrite = fun() ->
- etap:is(
- config:get("httpd", "port"),
- "5984",
- "{httpd, port} is still 5984 by default"
- ),
-
- etap:is(
- config:set("httpd", "port", "8080"),
- ok,
- "Writing {httpd, port} is kosher."
- ),
-
- etap:is(
- config:get("httpd", "port"),
- "8080",
- "{httpd, port} was updated to 8080 successfully."
- ),
-
- etap:is(
- config:delete("httpd", "bind_address"),
- ok,
- "Deleting {httpd, bind_address} succeeds"
- ),
-
- etap:is(
- config:get("httpd", "bind_address"),
- undefined,
- "{httpd, bind_address} was actually deleted."
- )
- end,
-
- run_tests([default_config(), local_config_write()], CheckCanWrite),
-
- % Open and check where we don't expect persistence.
-
- CheckDidntWrite = fun() ->
- etap:is(
- config:get("httpd", "port"),
- "5984",
- "{httpd, port} was not persisted to the primary INI file."
- ),
-
- etap:is(
- config:get("httpd", "bind_address"),
- "127.0.0.1",
- "{httpd, bind_address} was not deleted form the primary INI file."
- )
- end,
-
- run_tests([default_config()], CheckDidntWrite),
-
- % Open and check we have only the persistence we expect.
- CheckDidWrite = fun() ->
- etap:is(
- config:get("httpd", "port"),
- "8080",
- "{httpd, port} is still 8080 after reopening the config."
- ),
-
- etap:is(
- config:get("httpd", "bind_address"),
- undefined,
- "{httpd, bind_address} is still \"\" after reopening."
- )
- end,
-
- run_tests([local_config_write()], CheckDidWrite),
-
- ok.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0b7b43c9/test/etap/082-config-register.t
----------------------------------------------------------------------
diff --git a/test/etap/082-config-register.t b/test/etap/082-config-register.t
deleted file mode 100755
index bd09ea7..0000000
--- a/test/etap/082-config-register.t
+++ /dev/null
@@ -1,79 +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.
-
--mode(compile).
--export([handle_config_change/5]).
-
-default_config() ->
- test_util:build_file("etc/couchdb/default_dev.ini").
-
-main(_) ->
- test_util:init_code_path(),
- etap:plan(5),
- 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() ->
- application:set_env(config, ini_files, ["etc/couchdb/default_dev.ini"]),
- ok = application:start(config),
-
- etap:is(
- config:get("httpd", "port"),
- "5984",
- "{httpd, port} is 5984 by default."
- ),
-
- ok = config:set("httpd", "port", "4895", false),
-
- etap:is(
- config:get("httpd", "port"),
- "4895",
- "{httpd, port} changed to 4895"
- ),
-
- config:listen_for_changes(?MODULE, self()),
-
- ok = config:set("httpd", "port", "8080", false),
-
- receive
- {"httpd", "port", Value, false} ->
- etap:is(Value, "8080", "Registered function got notification.")
- after
- 1000 ->
- etap:fail("notification failed")
- end,
-
- % Implicitly checking that we *don't* call the function
- etap:is(
- config:get("httpd", "bind_address"),
- "127.0.0.1",
- "{httpd, bind_address} is not '0.0.0.0'"
- ),
-
- Msg = receive M -> M after 500 -> nil end,
- etap:is(Msg, nil, "yay, no notification for get"),
-
- ok.
-
-handle_config_change(Sec, Key, Val, Persist, Pid) ->
- Pid ! {Sec, Key, Val, Persist},
- {ok, Pid}.
-