2015-06-19 08:12:20 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2007-2015 Basho Technologies, Inc. All Rights Reserved.
|
|
|
|
%%
|
|
|
|
%% This file is provided 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.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
2015-06-22 08:49:07 +00:00
|
|
|
-module(machi_pb_high_client_test).
|
2015-06-19 08:12:20 +00:00
|
|
|
-compile(export_all).
|
|
|
|
|
|
|
|
-ifdef(TEST).
|
|
|
|
-ifndef(PULSE).
|
|
|
|
|
|
|
|
-include("machi_pb.hrl").
|
|
|
|
-include("machi_projection.hrl").
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
|
2015-06-22 08:49:07 +00:00
|
|
|
-define(C, machi_pb_high_client).
|
2015-06-19 08:12:20 +00:00
|
|
|
|
|
|
|
smoke_test_() ->
|
|
|
|
{timeout, 5*60, fun() -> smoke_test2() end}.
|
|
|
|
|
|
|
|
smoke_test2() ->
|
2015-12-07 06:26:39 +00:00
|
|
|
PortBase = 5720,
|
2015-10-23 09:19:25 +00:00
|
|
|
ok = application:set_env(machi, max_file_size, 1024*1024),
|
2015-06-19 08:12:20 +00:00
|
|
|
try
|
2015-12-07 06:26:39 +00:00
|
|
|
{Ps, MgrNames, Dirs} = machi_test_util:start_flu_packages(
|
|
|
|
1, PortBase, "./data.", []),
|
|
|
|
D = orddict:from_list([{P#p_srvr.name, P} || P <- Ps]),
|
|
|
|
M0 = hd(MgrNames),
|
|
|
|
ok = machi_chain_manager1:set_chain_members(M0, D),
|
|
|
|
[machi_chain_manager1:trigger_react_to_env(M0) || _ <-lists:seq(1,5)],
|
2015-06-19 08:12:20 +00:00
|
|
|
|
2015-06-22 08:49:07 +00:00
|
|
|
{ok, Clnt} = ?C:start_link(Ps),
|
2015-06-19 08:12:20 +00:00
|
|
|
try
|
2015-06-22 08:49:07 +00:00
|
|
|
true = ?C:connected_p(Clnt),
|
2015-06-29 07:10:43 +00:00
|
|
|
String = "yo, dawgggggggggggggggggggggggggggggggggg",
|
2015-06-22 08:49:07 +00:00
|
|
|
String = ?C:echo(Clnt, String),
|
2015-06-23 05:08:10 +00:00
|
|
|
|
2015-06-22 09:16:15 +00:00
|
|
|
%% TODO: auth() is not implemented. Auth requires SSL.
|
|
|
|
%% Probably ought to put client stuff that relies on SSL into
|
|
|
|
%% a separate test module? Or separate test func?
|
|
|
|
{error, _} = ?C:auth(Clnt, "foo", "bar"),
|
2015-06-19 08:12:20 +00:00
|
|
|
|
2015-10-19 12:08:38 +00:00
|
|
|
CoC_n = "", % CoC_namespace (not implemented)
|
2015-10-19 08:58:50 +00:00
|
|
|
CoC_l = 0, % CoC_locator (not implemented)
|
2015-06-23 05:08:10 +00:00
|
|
|
Prefix = <<"prefix">>,
|
|
|
|
Chunk1 = <<"Hello, chunk!">>,
|
2015-06-23 05:45:24 +00:00
|
|
|
{ok, {Off1, Size1, File1}} =
|
2015-10-19 08:58:50 +00:00
|
|
|
?C:append_chunk(Clnt, CoC_n, CoC_l, Prefix, Chunk1, none, 0),
|
2015-06-30 06:48:35 +00:00
|
|
|
true = is_binary(File1),
|
2015-06-23 05:45:24 +00:00
|
|
|
Chunk2 = "It's another chunk",
|
|
|
|
CSum2 = {client_sha, machi_util:checksum_chunk(Chunk2)},
|
|
|
|
{ok, {Off2, Size2, File2}} =
|
2015-10-19 08:58:50 +00:00
|
|
|
?C:append_chunk(Clnt, CoC_n, CoC_l, Prefix, Chunk2, CSum2, 1024),
|
2015-06-23 06:13:13 +00:00
|
|
|
Chunk3 = ["This is a ", <<"test,">>, 32, [["Hello, world!"]]],
|
2015-06-23 07:53:06 +00:00
|
|
|
File3 = File2,
|
2015-06-23 06:34:48 +00:00
|
|
|
Off3 = Off2 + iolist_size(Chunk2),
|
|
|
|
Size3 = iolist_size(Chunk3),
|
|
|
|
ok = ?C:write_chunk(Clnt, File2, Off3, Chunk3, none),
|
|
|
|
|
2015-06-23 07:24:08 +00:00
|
|
|
Reads = [{iolist_to_binary(Chunk1), File1, Off1, Size1},
|
|
|
|
{iolist_to_binary(Chunk2), File2, Off2, Size2},
|
2015-06-23 07:53:06 +00:00
|
|
|
{iolist_to_binary(Chunk3), File3, Off3, Size3}],
|
2015-06-29 07:10:43 +00:00
|
|
|
[begin
|
2015-10-19 03:09:39 +00:00
|
|
|
File = binary_to_list(Fl),
|
2015-10-21 06:35:32 +00:00
|
|
|
?assertMatch({ok, {[{File, Off, Ch, _}], []}},
|
|
|
|
?C:read_chunk(Clnt, Fl, Off, Sz, []))
|
2015-06-29 07:10:43 +00:00
|
|
|
end || {Ch, Fl, Off, Sz} <- Reads],
|
2015-06-23 05:08:10 +00:00
|
|
|
|
2015-06-30 07:03:45 +00:00
|
|
|
{ok, KludgeBin} = ?C:checksum_list(Clnt, File1),
|
|
|
|
true = is_binary(KludgeBin),
|
2015-06-23 08:08:15 +00:00
|
|
|
{ok, [{File1Size,File1}]} = ?C:list_files(Clnt),
|
|
|
|
true = is_integer(File1Size),
|
2015-06-23 07:53:06 +00:00
|
|
|
|
2015-10-23 09:19:25 +00:00
|
|
|
File1Bin = binary_to_list(File1),
|
2015-10-13 08:12:33 +00:00
|
|
|
[begin
|
2015-12-07 06:26:39 +00:00
|
|
|
#p_srvr{name=Name, props=Props} = P,
|
|
|
|
Dir = proplists:get_value(data_dir, Props),
|
2015-10-23 09:19:25 +00:00
|
|
|
?assertEqual({ok, [File1Bin]},
|
2015-12-14 07:34:57 +00:00
|
|
|
file:list_dir(filename:join([Dir, "data"])))
|
2015-10-23 09:19:25 +00:00
|
|
|
end || P <- Ps],
|
|
|
|
|
|
|
|
[begin
|
|
|
|
ok = ?C:trim_chunk(Clnt, Fl, Off, Sz)
|
|
|
|
end || {_Ch, Fl, Off, Sz} <- Reads],
|
|
|
|
[begin
|
|
|
|
{ok, {[], Trimmed}} =
|
|
|
|
?C:read_chunk(Clnt, Fl, Off, Sz, [{needs_trimmed, true}]),
|
|
|
|
Filename = binary_to_list(Fl),
|
|
|
|
?assertEqual([{Filename, Off, Sz}], Trimmed)
|
|
|
|
end || {_Ch, Fl, Off, Sz} <- Reads],
|
2015-10-13 08:12:33 +00:00
|
|
|
|
2015-10-23 09:19:25 +00:00
|
|
|
LargeBytes = binary:copy(<<"x">>, 1024*1024),
|
|
|
|
LBCsum = {client_sha, machi_util:checksum_chunk(LargeBytes)},
|
|
|
|
{ok, {Offx, Sizex, Filex}} =
|
2015-10-19 08:58:50 +00:00
|
|
|
?C:append_chunk(Clnt, CoC_n, CoC_l,
|
|
|
|
Prefix, LargeBytes, LBCsum, 0),
|
2015-10-23 09:19:25 +00:00
|
|
|
ok = ?C:trim_chunk(Clnt, Filex, Offx, Sizex),
|
|
|
|
|
|
|
|
%% Make sure everything was trimmed
|
|
|
|
File = binary_to_list(Filex),
|
|
|
|
[begin
|
2015-12-07 06:26:39 +00:00
|
|
|
#p_srvr{name=Name, props=Props} = P,
|
2015-12-14 07:34:57 +00:00
|
|
|
DataDir = filename:join([proplists:get_value(data_dir, Props), "data"]),
|
|
|
|
?assertEqual({ok, []}, file:list_dir(DataDir)),
|
|
|
|
{ok, CsumT} = machi_flu_filename_mgr:get_csum_table(Name),
|
|
|
|
Plist = machi_csum_table:all_files(CsumT),
|
|
|
|
?assertEqual([{File, ts}], Plist)
|
2015-10-23 09:19:25 +00:00
|
|
|
end || P <- Ps],
|
|
|
|
|
|
|
|
[begin
|
|
|
|
{error, trimmed} =
|
|
|
|
?C:read_chunk(Clnt, Fl, Off, Sz, [])
|
|
|
|
end || {_Ch, Fl, Off, Sz} <- Reads],
|
2015-06-19 08:12:20 +00:00
|
|
|
ok
|
|
|
|
after
|
2015-06-22 08:49:07 +00:00
|
|
|
(catch ?C:quit(Clnt))
|
2015-06-19 08:12:20 +00:00
|
|
|
end
|
|
|
|
after
|
2015-12-07 06:26:39 +00:00
|
|
|
machi_test_util:stop_flu_packages()
|
2015-06-19 08:12:20 +00:00
|
|
|
end.
|
|
|
|
|
|
|
|
-endif. % !PULSE
|
|
|
|
-endif. % TEST
|