anchor.diff:      UpNodes1 = ordsets:from_list(UpNodes),
       Primaries = riak_core_ring:all_owners(Ring),
       {Up, _Pangs} = check_up(Primaries, UpNodes1, [], []),
  -    lists:reverse(Up).
  +    Up.
   
   %% Get the active preflist taking account of which nodes are up
   -spec get_apl(binary(), n_val(), atom()) -> preflist().
  
positive.code:                  get_apl(last_in_ring(), 3, Ring, [nodeb, nodec, noded])),
      %% With two nodes down
      ?assertEqual([{365375409332725729550921208179070754913983135744,nodec},
                    {0,nodec},
                    {182687704666362864775460604089535377456991567872,noded}],
                   get_apl(last_in_ring(), 3, Ring,  [nodec, noded])),
      %% With the other two nodes down
      ?assertEqual([{0,nodea},
  
negative.code: 
  last_in_ring() ->
      <<1461501637330902918203684832716283019655932542975:160/unsigned>>.
  
  six_node_test() ->
      %% its non-trivial to create a real 6 node ring, so here's one we made
      %% earlier
      {ok, [Ring]} = file:consult("../test/my_ring"),
      %DocIdx = riak_core_util:chash_key({<<"foo">>, <<"bar">>}),
      DocIdx = <<73,212,27,234,104,13,150,207,0,82,86,183,125,225,172,
        154,135,46,6,112>>,
  
      Nodes = ['dev1@127.0.0.1', 'dev2@127.0.0.1', 'dev3@127.0.0.1',
          'dev4@127.0.0.1', 'dev5@127.0.0.1', 'dev6@127.0.0.1'],
  
      %% Fallbacks should be selected by finding the next-highest partition after
      %% the DocIdx of the key, in this case the 433883 partition. The N
      %% partitions at that point are the primary partitions. If any of the primaries
      %% are down, the next up node found by walking the preflist is used as the
      %% fallback for that partition.
  
      ?assertEqual([{433883298582611803841718934712646521460354973696, 'dev2@127.0.0.1'},
                    {456719261665907161938651510223838443642478919680, 'dev3@127.0.0.1'},
                    {479555224749202520035584085735030365824602865664, 'dev4@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes)),
  
      ?assertEqual([{456719261665907161938651510223838443642478919680, 'dev3@127.0.0.1'},
                    {479555224749202520035584085735030365824602865664, 'dev4@127.0.0.1'},
                    {433883298582611803841718934712646521460354973696, 'dev5@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes -- ['dev2@127.0.0.1'])),
  
      ?assertEqual([{479555224749202520035584085735030365824602865664, 'dev4@127.0.0.1'},
                    {433883298582611803841718934712646521460354973696, 'dev5@127.0.0.1'},
                    {456719261665907161938651510223838443642478919680, 'dev6@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes -- ['dev2@127.0.0.1', 'dev3@127.0.0.1'])),
  
      ?assertEqual([{433883298582611803841718934712646521460354973696, 'dev5@127.0.0.1'},
                    {456719261665907161938651510223838443642478919680, 'dev6@127.0.0.1'},
                    {479555224749202520035584085735030365824602865664, 'dev1@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes -- ['dev2@127.0.0.1', 'dev3@127.0.0.1',
                        'dev4@127.0.0.1'])),
  
      ?assertEqual([{433883298582611803841718934712646521460354973696, 'dev5@127.0.0.1'},
                    {456719261665907161938651510223838443642478919680, 'dev6@127.0.0.1'},
                    {479555224749202520035584085735030365824602865664, 'dev5@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes -- ['dev2@127.0.0.1', 'dev3@127.0.0.1',
                        'dev4@127.0.0.1', 'dev1@127.0.0.1'])),
  
      ?assertEqual([{433883298582611803841718934712646521460354973696, 'dev2@127.0.0.1'},
                    {456719261665907161938651510223838443642478919680, 'dev3@127.0.0.1'},
                    {479555224749202520035584085735030365824602865664, 'dev5@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes -- ['dev4@127.0.0.1'])),
  
      ?assertEqual([{433883298582611803841718934712646521460354973696, 'dev2@127.0.0.1'},
                    {456719261665907161938651510223838443642478919680, 'dev5@127.0.0.1'},
                    {479555224749202520035584085735030365824602865664, 'dev6@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes -- ['dev4@127.0.0.1', 'dev3@127.0.0.1'])),
  
      ?assertEqual([{433883298582611803841718934712646521460354973696, 'dev2@127.0.0.1'},
                    {456719261665907161938651510223838443642478919680, 'dev5@127.0.0.1'},
                    {479555224749202520035584085735030365824602865664, 'dev1@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes -- ['dev4@127.0.0.1', 'dev3@127.0.0.1',
                        'dev6@127.0.0.1'])),
  
      ?assertEqual([{433883298582611803841718934712646521460354973696, 'dev2@127.0.0.1'},
                    {456719261665907161938651510223838443642478919680, 'dev5@127.0.0.1'},
                    {479555224749202520035584085735030365824602865664, 'dev2@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes -- ['dev4@127.0.0.1', 'dev3@127.0.0.1',
                        'dev6@127.0.0.1', 'dev1@127.0.0.1'])),
  
      ?assertEqual([{433883298582611803841718934712646521460354973696, 'dev2@127.0.0.1'},
                    {456719261665907161938651510223838443642478919680, 'dev2@127.0.0.1'},
                    {479555224749202520035584085735030365824602865664, 'dev2@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes -- ['dev4@127.0.0.1', 'dev3@127.0.0.1',
                        'dev6@127.0.0.1', 'dev1@127.0.0.1', 'dev5@127.0.0.1'])),
  
      ?assertEqual([{433883298582611803841718934712646521460354973696, 'dev2@127.0.0.1'},
                    {479555224749202520035584085735030365824602865664, 'dev4@127.0.0.1'},
                    {456719261665907161938651510223838443642478919680, 'dev5@127.0.0.1'}],
                get_apl(DocIdx, 3, Ring, Nodes -- ['dev3@127.0.0.1'])),
  
      ok.
  
  -endif.
  