Permalink
Browse files

Fix repl enum and add bucket properties codec quickcheck

  • Loading branch information...
1 parent 02eb409 commit 029b02b2fd88efbc97fa5763f7f756cdc0ee72c9 @seancribbs seancribbs committed Feb 15, 2013
Showing with 121 additions and 28 deletions.
  1. +3 −0 .gitignore
  2. +2 −0 rebar.config
  3. +4 −4 src/riak.proto
  4. +112 −0 test/bucket_props_codec_eqc.erl
  5. +0 −24 test/encoding_test.erl
View
@@ -7,6 +7,9 @@ ebin/*.beam
ebin/riak_pb.app
include/*_pb.hrl
doc/*
+.qc
+.eqc-info
+current_counterexample.eqc
# Python
riak_pb.egg-info
View
@@ -4,5 +4,7 @@
{protobuffs, "0.8.*", {git, "git://github.com/basho/erlang_protobuffs.git", "master"}}
]}.
+{eunit_opts, [verbose]}.
+
%% Fixes attempted removal of riak_pb directory by rebar_escripter
{escript_name, "doesnothavescript"}.
View
@@ -115,10 +115,10 @@ message RpbBucketProps {
// Used by riak_repl bucket fixup
enum RpbReplMode {
- OFF = 0;
- REALTIME = 1;
- FULLSYNC = 2;
- BOTH = 3;
+ off = 0;
+ realtime = 1;
+ fullsync = 2;
+ both = 3;
}
optional RpbReplMode repl = 22;
}
@@ -0,0 +1,112 @@
+%% -------------------------------------------------------------------
+%%
+%% Copyright (c) 2013 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.
+%%
+%% -------------------------------------------------------------------
+-module(bucket_props_codec_eqc).
+
+-include_lib("eqc/include/eqc.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+-compile(export_all).
+
+-define(QC_OUT(P), eqc:on_output(fun(F,TL) ->
+ io:format(user, F, TL)
+ end, P)).
+
+bucket_codec_test_() ->
+ [{"bucket properties encode decode",
+ ?_test(begin
+ quickcheck(?QC_OUT(numtests(1000, prop_codec())))
+ end)}].
+
+prop_codec() ->
+ ?FORALL(Props, sortuniq(list(bucket_prop())),
+ ?WHENFAIL(begin
+ io:format("Props: ~p~n~n", [Props])
+ end,
+ begin
+ Props2 = riak_pb_codec:decode_bucket_props(
+ riak_pb:decode_rpbbucketprops(
+ iolist_to_binary(riak_pb:encode_rpbbucketprops(
+ riak_pb_codec:encode_bucket_props(Props))))),
+ Props =:= lists:sort(Props2)
+ end)).
+
+bucket_prop() ->
+ oneof([num(n_val),
+ flag(allow_mult),
+ flag(last_write_wins),
+ commit(precommit),
+ commit(postcommit),
+ chash(),
+ linkfun(),
+ num(old_vclock),
+ num(young_vclock),
+ num(big_vclock),
+ num(small_vclock),
+ quorum(pr),
+ quorum(r),
+ quorum(w),
+ quorum(pw),
+ quorum(dw),
+ quorum(rw),
+ flag(basic_quorum),
+ flag(notfound_ok),
+ backend(),
+ flag(search),
+ repl()]).
+
+sortuniq(Gen) ->
+ ?LET(L, Gen, lists:ukeysort(1,L)).
+
+flag(Prop) ->
+ ?LET(B, bool(), {Prop, B}).
+
+num(Prop) ->
+ ?LET(N, nat(), {Prop, N}).
+
+quorum(Prop) ->
+ ?LET(V, oneof([one, quorum, all, default, nat()]), {Prop, V}).
+
+backend() ->
+ ?LET(B, non_empty(binary()), {backend, B}).
+
+repl() ->
+ ?LET(R, oneof([off, realtime, fullsync, both]), {repl, R}).
+
+commit(Prop) ->
+ ?LET(C, non_empty(list(commit_hook())), {Prop, C}).
+
+commit_hook() ->
+ ?LET(H, oneof([modfun_hook(), name_hook()]), {struct, H}).
+
+modfun_hook() ->
+ ?LET({M,F}, {non_empty(binary()), non_empty(binary())},
+ [{<<"mod">>, M}, {<<"fun">>, F}]).
+
+name_hook() ->
+ ?LET(N, non_empty(binary()), [{<<"name">>, N}]).
+
+chash() ->
+ ?LET({M,F}, {atom(), atom()}, {chash_keyfun,{M,F}}).
+
+atom() ->
+ ?LET(B, non_empty(binary()), binary_to_atom(B, latin1)).
+
+linkfun() ->
+ ?LET({M,F}, {atom(), atom()}, {linkfun, {modfun, M, F}}).
@@ -86,30 +86,6 @@ pb_test_() ->
{"msg code encode decode",
?_test(begin
msg_code_encode_decode(0)
- end)},
- {"bucket props encode decode",
- ?_test(begin
- Props = [{n_val, 99},
- {allow_mult, true}],
- Props2 = riak_pb_codec:decode_bucket_props(
- riak_pb:decode_rpbbucketprops(
- iolist_to_binary(riak_pb:encode_rpbbucketprops(
- riak_pb_codec:encode_bucket_props(Props))))),
- MdSame = (lists:sort(Props) =:=
- lists:sort(Props2)),
- ?assertEqual(true, MdSame)
- end)},
- {"bucket props encode decode 2",
- ?_test(begin
- Props = [{n_val, 33},
- {allow_mult, false}],
- Props2 = riak_pb_codec:decode_bucket_props(
- riak_pb:decode_rpbbucketprops(
- iolist_to_binary(riak_pb:encode_rpbbucketprops(
- riak_pb_codec:encode_bucket_props(Props))))),
- MdSame = (lists:sort(Props) =:=
- lists:sort(Props2)),
- ?assertEqual(true, MdSame)
end)}
].

0 comments on commit 029b02b

Please sign in to comment.