Hi Basho,

I had written some simple tests using riakc client library.

The tests are attached to this mail.

In particular I made this call in the tests at the start of
of each test in order to get a clean DB.

    riakc_pb_socket:delete(Pid, Bucket, Key),

In 0.14 that worked just fine. But ... in 1.0 it did not work.
The tests failed and complained about siblings.

But ... after some time of experimenting I found that if I
added a sleep of 5 seconds after the delete ... then the tests
were OK again.

Is this correct? Does delete take 5 seconds?

NOTE that the attached file assumes inits is started.

/Roland
%%%-------------------------------------------------------------------
%%% @author <[email protected]>
%%% @doc
%%% @end
%%%-------------------------------------------------------------------
-module(node).

-export([test_nvc/0,
         test_vc/0,
         test_vc_siblings/0,
         connect/0,
         create_bucket_nvc/0,
         create_bucket_vc/0,
         set_bucket_nvc/0,
         set_bucket_vc/0,
         write_first/0,
         write_second_nvc/0,
         write_second_vc/0,
         delete/0,
         read/0,
         buckets/0,
         keys/0,
         bucket_props/0]).

test_nvc() ->
    create_bucket_nvc(),
    write_first(),
    write_second_nvc(),
    read().

test_vc() ->
    create_bucket_vc(),
    write_first(),
    write_second_vc(),
    read().

test_vc_siblings() ->
    create_bucket_vc(),
    write_first(),
    write_vc_siblings(),
    read().

connect() ->
    {ok, Pid} = riakc_pb_socket:start_link("localhost", 8087),
    Pid.

create_bucket_nvc() ->
    delete(),
    set_bucket_nvc().

set_bucket_nvc() ->
    %% riakc_pb_socket:set_bucket/3 cannot be used. It only supports
    %% two settings: n_val and allow_mult.
    httpc:request(put,
                  {"http://localhost:8098/riak/persons";,
                   [],
                   "application/json",
                   "{\"props\":{\"last_write_wins\":true,\"allow_mult\":false}}"},
                  [],
                  []).

create_bucket_vc() ->
    delete(),
    set_bucket_vc().

set_bucket_vc() ->
    %% riakc_pb_socket:set_bucket/3 cannot be used. It only supports
    %% two settings: n_val and allow_mult.
    httpc:request(put,
                  {"http://localhost:8098/riak/persons";,
                   [],
                   "application/json",
                   "{\"props\":{\"last_write_wins\":false,\"allow_mult\":true}}"},
                  [],
                  []).

write_first() ->
    Pid = connect(),
    Bucket = <<"persons">>,
    Key = <<"roland">>,
    Obj = riakc_obj:new(Bucket, Key, <<"1953">>),
    ok = riakc_pb_socket:put(Pid, Obj),
    riakc_pb_socket:stop(Pid).

delete() ->
    Pid = connect(),
    Bucket = <<"persons">>,
    Key = <<"roland">>,
    riakc_pb_socket:delete(Pid, Bucket, Key),
    %% In riak 1.0 you have to do some seconds sleep after a
    %% delete. Is this meant to be so?
    timer:sleep(5000),
    riakc_pb_socket:stop(Pid).

read() ->
    Pid = connect(),
    Bucket = <<"persons">>,
    Key = <<"roland">>,
    {ok, Obj} = riakc_pb_socket:get(Pid, Bucket, Key),
    riakc_pb_socket:stop(Pid),
    Obj.

write_second_nvc() ->
    Pid = connect(),
    Bucket = <<"persons">>,
    Key = <<"roland">>,
    Obj = riakc_obj:new(Bucket, Key, <<"1954">>),
    ok = riakc_pb_socket:put(Pid, Obj),
    riakc_pb_socket:stop(Pid).

write_second_vc() ->
    Pid = connect(),
    Bucket = <<"persons">>,
    Key = <<"roland">>,
    {ok, Obj1} = riakc_pb_socket:get(Pid, Bucket, Key),
    Obj2 = riakc_obj:update_value(Obj1, <<"1954">>),
    ok = riakc_pb_socket:put(Pid, Obj2),
    riakc_pb_socket:stop(Pid).

write_vc_siblings() ->
    Pid = connect(),
    Bucket = <<"persons">>,
    Key = <<"roland">>,
    {ok, Obj1} = riakc_pb_socket:get(Pid, Bucket, Key),
    Obj2 = riakc_obj:update_value(Obj1, <<"1954">>),
    ok = riakc_pb_socket:put(Pid, Obj2),
    Obj3 = riakc_obj:update_value(Obj1, <<"1955">>),
    ok = riakc_pb_socket:put(Pid, Obj3),
    riakc_pb_socket:stop(Pid).

buckets() ->
    Pid = connect(),
    {ok, Buckets} = riakc_pb_socket:list_buckets(Pid),
    riakc_pb_socket:stop(Pid),
    Buckets.

keys() ->
    Pid = connect(),
    Bucket = <<"persons">>,
    {ok, Keys} = riakc_pb_socket:list_keys(Pid, Bucket),
    riakc_pb_socket:stop(Pid),
    Keys.

bucket_props() ->
    Pid = connect(),
    Bucket = <<"persons">>,
    %% NOTE: only returns allow_mult and n_val.
    {ok, Props} = riakc_pb_socket:get_bucket(Pid, Bucket),
    riakc_pb_socket:stop(Pid),
    Props.
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to