couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [13/31] couchdb commit: updated refs/heads/1963-eunit to 16528f8
Date Tue, 03 Jun 2014 04:50:32 GMT
Port 050-stream.t etap test suite to eunit


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

Branch: refs/heads/1963-eunit
Commit: 787ac492b86ef79811c442558b97862840032f48
Parents: c08960c
Author: Alexander Shorin <kxepal@gmail.com>
Authored: Sun May 18 14:45:05 2014 +0400
Committer: Alexander Shorin <kxepal@gmail.com>
Committed: Tue Jun 3 03:04:17 2014 +0400

----------------------------------------------------------------------
 test/couchdb/Makefile.am            |  1 +
 test/couchdb/couch_stream_tests.erl | 99 ++++++++++++++++++++++++++++++++
 test/etap/050-stream.t              | 87 ----------------------------
 test/etap/Makefile.am               |  1 -
 4 files changed, 100 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/787ac492/test/couchdb/Makefile.am
----------------------------------------------------------------------
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am
index 58a6840..948ba7c 100644
--- a/test/couchdb/Makefile.am
+++ b/test/couchdb/Makefile.am
@@ -24,6 +24,7 @@ eunit_files = \
     couch_doc_json_tests.erl \
     couch_uuids_tests.erl \
     couch_work_queue_tests.erl \
+    couch_stream_tests.erl \
     couchdb_tests.hrl
 
 EXTRA_DIST = \

http://git-wip-us.apache.org/repos/asf/couchdb/blob/787ac492/test/couchdb/couch_stream_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couch_stream_tests.erl b/test/couchdb/couch_stream_tests.erl
new file mode 100644
index 0000000..580477f
--- /dev/null
+++ b/test/couchdb/couch_stream_tests.erl
@@ -0,0 +1,99 @@
+% 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.
+
+-module(couch_stream_tests).
+
+-include_lib("couchdb_tests.hrl").
+
+setup() ->
+    {ok, Fd} = couch_file:open(?tempfile(), [create, overwrite]),
+    {ok, Stream} = couch_stream:open(Fd),
+    {Fd, Stream}.
+
+teardown({Fd, _}) ->
+    ok = couch_file:close(Fd).
+
+
+stream_test_() ->
+    {
+        "CouchDB stream test",
+        {
+            foreach,
+            fun setup/0, fun teardown/1,
+            [
+                fun should_write/1,
+                fun should_write_consecutive/1,
+                fun should_write_empty_binary/1,
+                fun should_return_file_pointers_on_close/1,
+                fun should_return_stream_size_on_close/1,
+                fun should_return_valid_pointers/1,
+                fun should_recall_last_pointer_position/1,
+                fun should_stream_more_with_4K_chunk_size/1
+            ]
+        }
+    }.
+
+
+should_write({_, Stream}) ->
+    ?_assertMatch(ok, couch_stream:write(Stream, <<"food">>)).
+
+should_write_consecutive({_, Stream}) ->
+    couch_stream:write(Stream, <<"food">>),
+    ?_assertMatch(ok, couch_stream:write(Stream, <<"foob">>)).
+
+should_write_empty_binary({_, Stream}) ->
+    ?_assertMatch(ok, couch_stream:write(Stream, <<>>)).
+
+should_return_file_pointers_on_close({_, Stream}) ->
+    couch_stream:write(Stream, <<"foodfoob">>),
+    {Ptrs, _, _, _, _} = couch_stream:close(Stream),
+    ?_assertMatch([{0, 8}], Ptrs).
+
+should_return_stream_size_on_close({_, Stream}) ->
+    couch_stream:write(Stream, <<"foodfoob">>),
+    {_, Length, _, _, _} = couch_stream:close(Stream),
+    ?_assertEqual(8, Length).
+
+should_return_valid_pointers({Fd, Stream}) ->
+    couch_stream:write(Stream, <<"foodfoob">>),
+    {Ptrs, _, _, _, _} = couch_stream:close(Stream),
+    ?_assertMatch(<<"foodfoob">>, read_all(Fd, Ptrs)).
+
+should_recall_last_pointer_position({Fd, Stream}) ->
+    couch_stream:write(Stream, <<"foodfoob">>),
+    {_, _, _, _, _} = couch_stream:close(Stream),
+    {ok, ExpPtr} = couch_file:bytes(Fd),
+    {ok, Stream2} = couch_stream:open(Fd),
+    ZeroBits = <<0:(8 * 10)>>,
+    OneBits = <<1:(8 * 10)>>,
+    ok = couch_stream:write(Stream2, OneBits),
+    ok = couch_stream:write(Stream2, ZeroBits),
+    {Ptrs, 20, _, _, _} = couch_stream:close(Stream2),
+    [{ExpPtr, 20}] = Ptrs,
+    AllBits = iolist_to_binary([OneBits, ZeroBits]),
+    ?_assertMatch(AllBits, read_all(Fd, Ptrs)).
+
+should_stream_more_with_4K_chunk_size({Fd, _}) ->
+    {ok, Stream} = couch_stream:open(Fd, [{buffer_size, 4096}]),
+    lists:foldl(
+        fun(_, Acc) ->
+            Data = <<"a1b2c">>,
+            couch_stream:write(Stream, Data),
+            [Data | Acc]
+        end, [], lists:seq(1, 1024)),
+    ?_assertMatch({[{0, 4100}, {4106, 1020}], 5120, _, _, _},
+                  couch_stream:close(Stream)).
+
+
+read_all(Fd, PosList) ->
+    Data = couch_stream:foldl(Fd, PosList, fun(Bin, Acc) -> [Bin, Acc] end, []),
+    iolist_to_binary(Data).

http://git-wip-us.apache.org/repos/asf/couchdb/blob/787ac492/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/787ac492/test/etap/Makefile.am
----------------------------------------------------------------------
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index 4eef1a0..b6ec287 100644
--- a/test/etap/Makefile.am
+++ b/test/etap/Makefile.am
@@ -36,7 +36,6 @@ fixture_files = \
     fixtures/test.couch
 
 tap_files = \
-    050-stream.t \
     060-kt-merging.t \
     061-kt-missing-leaves.t \
     062-kt-remove-leaves.t \


Mime
View raw message