mirror of
https://github.com/valitydev/riak_test.git
synced 2024-11-06 08:35:22 +00:00
f8389ba071
The original test author had forgotten that tests are run against multiple backends, and his intercept strategy, being at the backend, required duplication of the intercept mod:fun for each backend of interest
59 lines
1.8 KiB
Erlang
59 lines
1.8 KiB
Erlang
%% -------------------------------------------------------------------
|
|
%%
|
|
%% Copyright (c) 2015 Basho Technologies, Inc.
|
|
%%
|
|
%% 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(riak_kv_leveled_backend_intercepts).
|
|
-compile(export_all).
|
|
-include("intercept.hrl").
|
|
|
|
-define(M, riak_kv_leveled_backend_orig).
|
|
|
|
corrupting_put(Bucket, Key, IndexSpecs, Val0, ModState) ->
|
|
Val =
|
|
case random:uniform(20) of
|
|
10 ->
|
|
corrupt_binary(Val0);
|
|
_ -> Val0
|
|
end,
|
|
?M:put_orig(Bucket, Key, IndexSpecs, Val, ModState).
|
|
|
|
corrupting_get(Bucket, Key, ModState) ->
|
|
case ?M:get_orig(Bucket, Key, ModState) of
|
|
{ok, BinVal0, UpdModState} ->
|
|
BinVal =
|
|
case random:uniform(20) of
|
|
10 ->
|
|
corrupt_binary(BinVal0);
|
|
_ -> BinVal0
|
|
end,
|
|
{ok, BinVal, UpdModState};
|
|
Else -> Else
|
|
end.
|
|
|
|
corrupt_binary(O) ->
|
|
crypto:rand_bytes(byte_size(O)).
|
|
|
|
always_corrupt_get(Bucket, Key, ModState) ->
|
|
case ?M:get_orig(Bucket, Key, ModState) of
|
|
{ok, BinVal0, UpdModState} ->
|
|
BinVal = corrupt_binary(BinVal0),
|
|
{ok, BinVal, UpdModState};
|
|
Else -> Else
|
|
end.
|