From f3e688373082574d6f469acc282b873658a2321a Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Thu, 15 Apr 2010 16:34:25 +0000 Subject: refactor att compression to allow more encodings. thanks fdmanana. COUCHDB-710 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@934475 13f79535-47bb-0310-9956-ffa450edef68 --- test/etap/030-doc-from-json.t | 2 +- test/etap/031-doc-to-json.t | 2 +- test/etap/113-replication-attachment-comp.t | 31 ++++++--- test/etap/140-attachment-comp.t | 102 +++++++++++++++++++--------- 4 files changed, 91 insertions(+), 46 deletions(-) (limited to 'test') diff --git a/test/etap/030-doc-from-json.t b/test/etap/030-doc-from-json.t index 359a75f9..22b23bd4 100755 --- a/test/etap/030-doc-from-json.t +++ b/test/etap/030-doc-from-json.t @@ -18,7 +18,7 @@ -record(doc, {id= <<"">>, revs={0, []}, body={[]}, atts=[], deleted=false, meta=[]}). -record(att, {name, type, att_len, disk_len, md5= <<>>, revpos=0, data, - comp=false}). + encoding=identity}). default_config() -> test_util:build_file("etc/couchdb/default_dev.ini"). diff --git a/test/etap/031-doc-to-json.t b/test/etap/031-doc-to-json.t index 89cf4bc9..05425d38 100755 --- a/test/etap/031-doc-to-json.t +++ b/test/etap/031-doc-to-json.t @@ -18,7 +18,7 @@ -record(doc, {id= <<"">>, revs={0, []}, body={[]}, atts=[], deleted=false, meta=[]}). -record(att, {name, type, att_len, disk_len, md5= <<>>, revpos=0, data, - comp=false}). + encoding=identity}). default_config() -> test_util:build_file("etc/couchdb/default_dev.ini"). diff --git a/test/etap/113-replication-attachment-comp.t b/test/etap/113-replication-attachment-comp.t index d9039694..30f602ef 100644 --- a/test/etap/113-replication-attachment-comp.t +++ b/test/etap/113-replication-attachment-comp.t @@ -30,7 +30,7 @@ test_db_b_name() -> main(_) -> test_util:init_code_path(), - etap:plan(28), + etap:plan(30), case (catch test()) of ok -> etap:end_tests(); @@ -191,7 +191,7 @@ check_server_can_decompress_att(DbName) -> check_att_stubs(SourceDbName, TargetDbName) -> {ok, {{_, Code1, _}, _Headers1, Body1}} = http:request( get, - {db_url(SourceDbName) ++ "/testdoc1?att_gzip_length=true", []}, + {db_url(SourceDbName) ++ "/testdoc1?att_encoding_info=true", []}, [], [{sync, true}]), etap:is( @@ -206,7 +206,7 @@ check_att_stubs(SourceDbName, TargetDbName) -> ), {ok, {{_, Code2, _}, _Headers2, Body2}} = http:request( get, - {db_url(TargetDbName) ++ "/testdoc1?att_gzip_length=true", []}, + {db_url(TargetDbName) ++ "/testdoc1?att_encoding_info=true", []}, [], [{sync, true}]), etap:is( @@ -225,21 +225,30 @@ check_att_stubs(SourceDbName, TargetDbName) -> TargetAttStub, [<<"length">>] ), - TargetAttStubGzipLength = couch_util:get_nested_json_value( + TargetAttStubEnc = couch_util:get_nested_json_value( TargetAttStub, - [<<"gzip_length">>] + [<<"encoding">>] ), - GzipLengthDefined = is_integer(TargetAttStubGzipLength), etap:is( - GzipLengthDefined, + TargetAttStubEnc, + <<"gzip">>, + "Attachment stub has encoding property set to gzip" + ), + TargetAttStubEncLength = couch_util:get_nested_json_value( + TargetAttStub, + [<<"encoded_length">>] + ), + EncLengthDefined = is_integer(TargetAttStubEncLength), + etap:is( + EncLengthDefined, true, - "Stubs have the gzip_length field properly defined" + "Stubs have the encoded_length field properly defined" ), - GzipLengthSmaller = (TargetAttStubGzipLength < TargetAttStubLength), + EncLengthSmaller = (TargetAttStubEncLength < TargetAttStubLength), etap:is( - GzipLengthSmaller, + EncLengthSmaller, true, - "Stubs have the gzip_length field smaller than their length field" + "Stubs have the encoded_length field smaller than their length field" ), ok. diff --git a/test/etap/140-attachment-comp.t b/test/etap/140-attachment-comp.t index cb3039e6..b6c09d53 100755 --- a/test/etap/140-attachment-comp.t +++ b/test/etap/140-attachment-comp.t @@ -22,7 +22,7 @@ test_db_name() -> main(_) -> test_util:init_code_path(), - etap:plan(57), + etap:plan(65), case (catch test()) of ok -> etap:end_tests(); @@ -127,26 +127,26 @@ tests_for_1st_text_att() -> test_get_1st_text_att_with_accept_encoding_deflate(), test_get_1st_text_att_with_accept_encoding_deflate_only(), test_get_doc_with_1st_text_att(), - test_length_1st_text_att_stub(). + test_1st_text_att_stub(). tests_for_1st_png_att() -> test_get_1st_png_att_without_accept_encoding_header(), test_get_1st_png_att_with_accept_encoding_gzip(), test_get_1st_png_att_with_accept_encoding_deflate(), test_get_doc_with_1st_png_att(), - test_length_1st_png_att_stub(). + test_1st_png_att_stub(). tests_for_2nd_text_att() -> test_get_2nd_text_att_with_accept_encoding_gzip(), test_get_2nd_text_att_without_accept_encoding_header(), test_get_doc_with_2nd_text_att(), - test_length_2nd_text_att_stub(). + test_2nd_text_att_stub(). tests_for_2nd_png_att() -> test_get_2nd_png_att_without_accept_encoding_header(), test_get_2nd_png_att_with_accept_encoding_gzip(), test_get_doc_with_2nd_png_att(), - test_length_2nd_png_att_stub(). + test_2nd_png_att_stub(). test_get_1st_text_att_with_accept_encoding_gzip() -> {ok, {{_, Code, _}, Headers, Body}} = http:request( @@ -297,27 +297,36 @@ test_get_doc_with_1st_text_att() -> ), ok. -test_length_1st_text_att_stub() -> +test_1st_text_att_stub() -> {ok, {{_, Code, _}, _Headers, Body}} = http:request( get, - {db_url() ++ "/testdoc1", []}, + {db_url() ++ "/testdoc1?att_encoding_info=true", []}, [], [{sync, true}]), etap:is(Code, 200, "HTTP response code is 200"), Json = couch_util:json_decode(Body), - TextAttJson = couch_util:get_nested_json_value( + {TextAttJson} = couch_util:get_nested_json_value( Json, [<<"_attachments">>, <<"readme.txt">>] ), - TextAttLength = couch_util:get_nested_json_value( - TextAttJson, - [<<"length">>] - ), + TextAttLength = proplists:get_value(<<"length">>, TextAttJson), etap:is( TextAttLength, length(test_text_data()), "1st text attachment stub length matches the uncompressed length" ), + TextAttEncoding = proplists:get_value(<<"encoding">>, TextAttJson), + etap:is( + TextAttEncoding, + <<"gzip">>, + "1st text attachment stub has the encoding field set to gzip" + ), + TextAttEncLength = proplists:get_value(<<"encoded_length">>, TextAttJson), + etap:is( + TextAttEncLength, + iolist_size(zlib:gzip(test_text_data())), + "1st text attachment stub encoded_length matches the compressed length" + ), ok. test_get_doc_with_1st_png_att() -> @@ -348,27 +357,36 @@ test_get_doc_with_1st_png_att() -> ), ok. -test_length_1st_png_att_stub() -> +test_1st_png_att_stub() -> {ok, {{_, Code, _}, _Headers, Body}} = http:request( get, - {db_url() ++ "/testdoc2", []}, + {db_url() ++ "/testdoc2?att_encoding_info=true", []}, [], [{sync, true}]), etap:is(Code, 200, "HTTP response code is 200"), Json = couch_util:json_decode(Body), - PngAttJson = couch_util:get_nested_json_value( + {PngAttJson} = couch_util:get_nested_json_value( Json, [<<"_attachments">>, <<"icon.png">>] ), - PngAttLength = couch_util:get_nested_json_value( - PngAttJson, - [<<"length">>] - ), + PngAttLength = proplists:get_value(<<"length">>, PngAttJson), etap:is( PngAttLength, length(test_png_data()), "1st png attachment stub length matches the uncompressed length" ), + PngEncoding = proplists:get_value(<<"encoding">>, PngAttJson), + etap:is( + PngEncoding, + undefined, + "1st png attachment stub doesn't have an encoding field" + ), + PngEncLength = proplists:get_value(<<"encoded_length">>, PngAttJson), + etap:is( + PngEncLength, + undefined, + "1st png attachment stub doesn't have an encoded_length field" + ), ok. test_get_2nd_text_att_with_accept_encoding_gzip() -> @@ -466,27 +484,36 @@ test_get_doc_with_2nd_text_att() -> ), ok. -test_length_2nd_text_att_stub() -> +test_2nd_text_att_stub() -> {ok, {{_, Code, _}, _Headers, Body}} = http:request( get, - {db_url() ++ "/testdoc3", []}, + {db_url() ++ "/testdoc3?att_encoding_info=true", []}, [], [{sync, true}]), etap:is(Code, 200, "HTTP response code is 200"), Json = couch_util:json_decode(Body), - TextAttJson = couch_util:get_nested_json_value( + {TextAttJson} = couch_util:get_nested_json_value( Json, [<<"_attachments">>, <<"readme.txt">>] ), - TextAttLength = couch_util:get_nested_json_value( - TextAttJson, - [<<"length">>] - ), + TextAttLength = proplists:get_value(<<"length">>, TextAttJson), etap:is( TextAttLength, length(test_text_data()), "2nd text attachment stub length matches the uncompressed length" ), + TextAttEncoding = proplists:get_value(<<"encoding">>, TextAttJson), + etap:is( + TextAttEncoding, + <<"gzip">>, + "2nd text attachment stub has the encoding field set to gzip" + ), + TextAttEncLength = proplists:get_value(<<"encoded_length">>, TextAttJson), + etap:is( + TextAttEncLength, + iolist_size(zlib:gzip(test_text_data())), + "2nd text attachment stub encoded_length matches the compressed length" + ), ok. test_get_doc_with_2nd_png_att() -> @@ -517,27 +544,36 @@ test_get_doc_with_2nd_png_att() -> ), ok. -test_length_2nd_png_att_stub() -> +test_2nd_png_att_stub() -> {ok, {{_, Code, _}, _Headers, Body}} = http:request( get, - {db_url() ++ "/testdoc4", []}, + {db_url() ++ "/testdoc4?att_encoding_info=true", []}, [], [{sync, true}]), etap:is(Code, 200, "HTTP response code is 200"), Json = couch_util:json_decode(Body), - PngAttJson = couch_util:get_nested_json_value( + {PngAttJson} = couch_util:get_nested_json_value( Json, [<<"_attachments">>, <<"icon.png">>] ), - PngAttLength = couch_util:get_nested_json_value( - PngAttJson, - [<<"length">>] - ), + PngAttLength = proplists:get_value(<<"length">>, PngAttJson), etap:is( PngAttLength, length(test_png_data()), "2nd png attachment stub length matches the uncompressed length" ), + PngEncoding = proplists:get_value(<<"encoding">>, PngAttJson), + etap:is( + PngEncoding, + undefined, + "2nd png attachment stub doesn't have an encoding field" + ), + PngEncLength = proplists:get_value(<<"encoded_length">>, PngAttJson), + etap:is( + PngEncLength, + undefined, + "2nd png attachment stub doesn't have an encoded_length field" + ), ok. test_png_data() -> -- cgit v1.2.3