anchor.diff:                }
         end,
         fun(_) ->
  +              {"fold_buckets test",
  +               fun() ->
  +                       B1 = <<"b1">>, B2 = <<"b2">>,
  +                       K1 = <<"k1">>, K2 = <<"k2">>,
  +                       V1 = <<"v1">>, V2 = <<"v2">>,
  +
  +                       riak_core_bucket:set_bucket(B1, [{backend, first_backend}]),
  +                       riak_core_bucket:set_bucket(B2, [{backend, second_backend}]),
  +
  +                       %% Start the backend...
  +                       {ok, State} = start(42, sample_config()),
  +
  +                       %% Create some placeholder values in the buckets so that they show
  +                       %% up when we run the fold operation...
  +                       put(B1, K1, [], V1, State),
  +                       put(B2, K2, [], V2, State),
  +
  +                       %% First do a basic fold with no options to make sure we iterate
  +                       %% correctly over all buckets:
  +                       FoldFun = fun(Bucket, Acc) -> [Bucket | Acc] end,
  +                       {ok, FoldRes} = fold_buckets(FoldFun, [], [], State),
  +                       [B1, B2] = lists:sort(FoldRes),
  +
  +                       %% Then filter on a specific backend, and we should only see
  +                       %% the bucket using that backend:
  +                       {ok, [B2]} = fold_buckets(FoldFun, [], [{backend, [second_backend]}], State)
  +               end
  +              }
  +      end,
  +      fun(_) ->
                 {"start error with invalid backend test",
                  fun() ->
                          %% Attempt to start the backend with a
  
positive.code: -define(CAPABILITIES, [async_fold, index_reformat]).
  -define(ANY_CAPABILITIES, [indexes, iterator_refresh]).
  
  -record (state, {backends :: [{atom(), atom(), term()}],
                   default_backend :: atom()}).
  
  -type state() :: #state{}.
  
negative.code:             true
      end.
  
  %% @doc If a {backend, [BACKEND_LIST]} option is specified,
  %% don't fold over any backends that aren't in the list.
  filter_on_backend_opts(Opts, Name) ->
      case lists:keyfind(backend, 1, Opts) of
          false ->
              true; % If no {backend, [...]} option is set, don't filter anything here
          {backend, BackendList} ->
              lists:member(Name, BackendList)
      end.
  
  %% @doc Skips folding on backends that do not support indexes.
  indexes_filter(_Opts, _Name, _Module, _SubState, ModCaps) ->
      lists:member(indexes, ModCaps).
  
  %% @private
  backend_fold_fun(ModFun, FoldFun, Opts, AsyncFold, BackendFilter) ->
      fun({Name, Module, SubState}, {Acc, WorkList}) ->
              %% Get the backend capabilities to determine
              %% if it supports asynchronous folding.
              {ok, ModCaps} = Module:capabilities(SubState),
              DoAsync = AsyncFold andalso lists:member(async_fold, ModCaps),
              case BackendFilter(Opts, Name, Module, SubState, ModCaps) of
                  false ->
                      {Acc, WorkList};
                  true ->
  