Anonymous avatar Anonymous committed 69795b7 Merge

merge

Comments (0)

Files changed (2)

scripts/run_tests.escript

     {ok, [{application, riak, App}]} =
         file:consult(filename:join([Ebin, "riak.app"])),
     {ok, NonTestRe} = re:compile("_tests$"),
-    crypto:start(),
-    setup_mock_ring(),
     Modules = lists:filter(
                 fun(M) ->
                         nomatch == re:run(atom_to_list(M), NonTestRe)
                 end,
                 proplists:get_value(modules, App)),
 
+    crypto:start(),
+    setup_mock_ring(),
+
     start_cover(Modules),
     eunit:test(Modules, [verbose]),
     analyze_cover(Modules);

src/jiak_object.erl

 %% @doc Convert a vclock to a binary appropriate for storing in
 %%      a Jiak object.
 vclock_to_headers(VClock) ->
-    base64:encode(zlib:zip(make_vclock_headers(lists:sort(VClock), []))).
-
-%% @private
-make_vclock_headers([], Acc) ->
-    list_to_binary(string:join(lists:reverse(Acc), ","));
-make_vclock_headers([{Node, {Counter, Timestamp}}|T], Acc) ->
-    Hdr = format_vclock_header(Node, Counter, Timestamp),
-    make_vclock_headers(T, [Hdr|Acc]).    
-
-%% @private
-format_vclock_header(Node, Counter, Timestamp) when is_list(Node); is_binary(Node) ->
-    io_lib:format("~s/~B/~B", [Node, 
-                               Counter, 
-                               Timestamp]);
-format_vclock_header(Node, Counter, Timestamp) ->
-    format_vclock_header(atom_to_list(Node), Counter, Timestamp).
+    base64:encode(zlib:zip(term_to_binary(VClock))).
 
 %% @spec headers_to_vclock(binary()) -> riak:vclock()
 %% @doc Convert a Jiak object vclock (a binary created by
 %%      vclock_to_headers/1) into a vclock appropriate for storing
 %%      in a riak_object.
-headers_to_vclock(Header) when is_binary(Header) ->
-    headers_to_vclock(binary_to_list(zlib:unzip(base64:decode(Header))));
 headers_to_vclock(Header) ->
-    [{list_to_binary(N), 
-      {list_to_integer(C), list_to_integer(T)}} || 
-	{N, C, T} <- 
-	    [list_to_tuple(string:tokens(H, "/")) 
-	     || H <- [string:strip(S) || S <- string:tokens(Header, ",")]]].
+    binary_to_term(zlib:unzip(base64:decode(Header))).
 
 %%
 %% Diffing Objects
 roundtrip_vclock_test() ->
     Vclock = vclock:increment(riak_util:mkclientid(node()),
                               vclock:fresh()),
-    ?assertEqual(Vclock, headers_to_vclock(vclock_to_headers(Vclock))).
+    ?assertEqual(Vclock, headers_to_vclock(vclock_to_headers(Vclock))),
+    Vclock2 = vclock:increment(node(), vclock:fresh()),
+    ?assertEqual(Vclock2, headers_to_vclock(vclock_to_headers(Vclock2))).
 
 roundtrip_riak_object_test_() ->
     [fun test_to_riak_object/0,
     L0 = [other_fake_bucket,<<"other_fake_key">>,<<"fake_tag">>],
     B = add_link(A, L0),
     ?assertEqual([L0], links(B)),
+    ?assertEqual([L0], links(B, '_', '_')),
     ?assertEqual([L0], links(B, other_fake_bucket)),
     ?assertEqual([],   links(B, wrong_fake_bucket)),
     ?assertEqual([L0], links(B, '_', <<"fake_tag">>)),
     ?assertEqual([],   links(B, wrong_fake_bucket, <<"fake_tag">>)),
     
     ?assertEqual(B, add_link(B, L0)), %%don't double-add links
+
+    %% add_link/4 should do same as add_link/2
+    ?assertEqual(add_link(A, L0),
+                 add_link(A, hd(L0), hd(tl(L0)), hd(tl(tl(L0))))),
     
     ?assertEqual([], links(remove_link(B, L0))),
+
+    %% remove_link/4 should do same as remove_link/2
+    ?assertEqual(remove_link(B, L0),
+                 remove_link(B, hd(L0), hd(tl(L0)), hd(tl(tl(L0))))),
     
     L1 = [other_fake_bucket,<<"second_fake_key">>,<<"new_fake_tag">>],
     L2 = [new_fake_bucket,<<"third_fake_key">>,<<"fake_tag">>],
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.